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
- Navigate to Networking → Load Balancers.
- Click Create Load Balancer.
- Select the region (must match your backend servers).
- Choose a protocol: HTTP, HTTPS, or TCP.
Step 2 — Configure the Forwarding Rules
| Frontend Port | Protocol | Backend Port |
|---|---|---|
| 80 | HTTP | 80 |
| 443 | HTTPS | 80 |
For HTTPS termination, upload your SSL certificate under SSL Certificates before creating the forwarding rule.
Step 3 — Add Backend Instances
- Under Attached Instances, click Add Instance.
- Select your backend servers from the dropdown.
- Repeat for all backend servers.
Step 4 — Configure Health Checks
Health checks determine whether a backend is healthy and should receive traffic.
| Setting | Recommended Value |
|---|---|
| Protocol | HTTP |
| Path | /health |
| Interval | 15 seconds |
| Timeout | 5 seconds |
| Unhealthy threshold | 3 |
| Healthy threshold | 2 |
Create a health check endpoint on your backend servers:
$cat > /var/www/html/health << 'EOF'$OK$EOFOr in your Node.js application:
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:
- Under Sticky Sessions, select Cookie.
- Set the cookie name (e.g.,
LB_SESSION). - Set the expiry in seconds (e.g.,
3600for 1 hour).
Step 6 — Verify the Load Balancer
After creation, the load balancer is assigned a public IP. Test it:
$curl -I http://LOAD_BALANCER_IPHTTP/1.1 200 OK
Server: nginx/1.24.0
Content-Type: text/html; charset=utf-8Configure via API
$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.
