Setting up a load balancer on Data Mammoth distributes incoming traffic across multiple servers, improving your application's performance, reliability, and availability. This guide walks you through the entire setup process, from creating the load balancer to adding backend servers and verifying that everything works.
Prerequisites
Before setting up a load balancer, you need:
- At least two running servers (VPS or dedicated) hosting the same application. The load balancer distributes traffic across these servers.
- Your application deployed and working identically on each server. All backend servers should serve the same content and handle the same requests.
- If using HTTPS, an SSL/TLS certificate for your domain.
Step 1 — Create a Load Balancer
Configure Basic Settings
- Name — Enter a descriptive name (e.g., "Production Web LB" or "API Load Balancer").
- Region — Select the data center region. Choose the same region where your backend servers are located for the lowest latency.
- Type — Select the load balancer type if options are available (Layer 4 or Layer 7).
Step 2 — Configure Forwarding Rules
Forwarding rules define how the load balancer handles incoming traffic and routes it to backend servers.
HTTP Forwarding Rule
| Setting | Value |
|---|---|
| Frontend Protocol | HTTP |
| Frontend Port | 80 |
| Backend Protocol | HTTP |
| Backend Port | 80 |
HTTPS Forwarding Rule
| Setting | Value |
|---|---|
| Frontend Protocol | HTTPS |
| Frontend Port | 443 |
| Backend Protocol | HTTP |
| Backend Port | 80 |
| SSL Certificate | Your SSL certificate |
Custom Port Forwarding
For applications running on non-standard ports:
| Setting | Value |
|---|---|
| Frontend Protocol | TCP |
| Frontend Port | 8080 |
| Backend Protocol | TCP |
| Backend Port | 8080 |
Step 3 — Select the Load Balancing Algorithm
Choose how the load balancer distributes traffic across backend servers:
- Round Robin — Sends requests to each server in rotation. Best for servers with equal capacity.
- Least Connections — Sends requests to the server with the fewest active connections. Best for variable-length requests.
- IP Hash — Routes requests from the same client IP to the same backend server. Useful for session persistence.
The default (Round Robin) works well for most web applications. Change the algorithm in the load balancer's settings if needed.
Step 4 — Add Backend Servers
Backend servers (also called "targets" or "nodes") are the servers that receive and process traffic from the load balancer.
Example Backend Configuration
| Server | IP Address | Port | Weight |
|---|---|---|---|
| web-server-01 | 203.0.113.10 | 80 | 1 |
| web-server-02 | 203.0.113.11 | 80 | 1 |
| web-server-03 | 203.0.113.12 | 80 | 1 |
Step 5 — Configure Health Checks
Health checks monitor your backend servers and automatically remove unhealthy servers from the pool. This is essential for maintaining availability.
| Setting | Recommended Value | Description |
|---|---|---|
| Protocol | HTTP or TCP | How to check the server |
| Port | 80 | Which port to check |
| Path | / or /health | URL path for HTTP health checks |
| Check Interval | 10 seconds | How often to check |
| Timeout | 5 seconds | Max time to wait for a response |
| Healthy Threshold | 3 | Consecutive successes to mark healthy |
| Unhealthy Threshold | 3 | Consecutive failures to mark unhealthy |
For detailed health check configuration, see Configuring Health Checks.
Step 6 — Configure Session Persistence (Optional)
If your application requires users to stay connected to the same backend server (e.g., for session-based authentication), enable session persistence (sticky sessions):
Note: Sticky sessions can reduce the effectiveness of load balancing because traffic is not evenly distributed. Use them only when your application architecture requires it. Stateless applications do not need sticky sessions.
Step 7 — Update DNS
Point your domain to the load balancer instead of an individual server:
After DNS propagation, all traffic to your domain flows through the load balancer.
Step 8 — Verify the Setup
Test Traffic Distribution
Test Failover
Monitor
Use your Data Mammoth dashboard to monitor:
- Load balancer traffic volume.
- Backend server health status.
- Request distribution across servers.
- Response times and error rates.
What to Do Next
- Load Balancing Algorithms Explained — Choose the optimal algorithm for your workload.
- Configuring SSL with Your Load Balancer — Set up HTTPS.
- Configuring Health Checks — Fine-tune health monitoring.
- What Is a Load Balancer? — Review the fundamentals.