LightYear
/Docs
DocsNetworkingConfigure a Load Balancer

Configure a Load Balancer

Set up a LightYear managed load balancer to distribute traffic across multiple backend servers.

intermediate
10 min read
LightYear Docs Team
Updated April 24, 2026
load-balancernetworkinghigh-availabilityscaling
Ready to get started?

Networking Topology Diagram

A load balancer distributes incoming traffic across multiple backend servers, improving availability and scalability. LightYear's managed load balancer handles health checks, SSL termination, and session persistence automatically.

Prerequisites

  • At least two running servers in the same region
  • A LightYear account with load balancer access

Step 1 — Create a Load Balancer

  1. Navigate to Networking → Load Balancers.
  2. Click Create Load Balancer.
  3. Select the region (must match your backend servers).
  4. Choose a protocol: HTTP, HTTPS, or TCP.

Step 2 — Configure the Forwarding Rules

Frontend PortProtocolBackend Port
80HTTP80
443HTTPS80

For HTTPS termination, upload your SSL certificate under SSL Certificates before creating the forwarding rule.

Step 3 — Add Backend Instances

  1. Under Attached Instances, click Add Instance.
  2. Select your backend servers from the dropdown.
  3. Repeat for all backend servers.

Step 4 — Configure Health Checks

Health checks determine whether a backend is healthy and should receive traffic.

SettingRecommended Value
ProtocolHTTP
Path/health
Interval15 seconds
Timeout5 seconds
Unhealthy threshold3
Healthy threshold2

Create a health check endpoint on your backend servers:

>_BASH
$cat > /var/www/html/health << 'EOF'
$OK
$EOF

Or in your Node.js application:

JS
app.get('/health', (req, res) => {
  res.status(200).json({ status: 'ok', timestamp: Date.now() });
});

Step 5 — Configure Session Persistence (Optional)

If your application requires users to always hit the same backend server, enable sticky sessions:

  1. Under Sticky Sessions, select Cookie.
  2. Set the cookie name (e.g., LB_SESSION).
  3. Set the expiry in seconds (e.g., 3600 for 1 hour).

Step 6 — Verify the Load Balancer

After creation, the load balancer is assigned a public IP. Test it:

>_BASH
$curl -I http://LOAD_BALANCER_IP
OUTPUT
HTTP/1.1 200 OK
Server: nginx/1.24.0
Content-Type: text/html; charset=utf-8

Configure via API

>_BASH
$curl -X POST https://api.lightyear.host/v1/load-balancers \
$ -H "Authorization: Bearer YOUR_API_KEY" \
$ -H "Content-Type: application/json" \
$ -d '{
$ "region": "sgp-01",
$ "label": "web-lb-01",
$ "forwarding_rules": [
$ {"frontend_protocol": "HTTP", "frontend_port": 80, "backend_protocol": "HTTP", "backend_port": 80}
$ ],
$ "health_check": {
$ "protocol": "HTTP",
$ "port": 80,
$ "path": "/health",
$ "check_interval": 15,
$ "response_timeout": 5,
$ "unhealthy_threshold": 3,
$ "healthy_threshold": 2
$ }
$ }'

[!TIP] Point your domain's DNS A record to the load balancer IP, not to individual server IPs. This allows you to add or remove backend servers without changing DNS.

Was this article helpful?

Your cookie choices for this website

This site uses cookies and related technologies, as described in our privacy policy, for purposes that may include site operation, analytics, and enhanced user experience. You may choose to consent to our use of these technologies, or manage your own preferences. Cookie policy