Sub topic 11
Removing the load balancer as a single point of failure
Earlier chapters used a load balancer to remove single points of failure from the backend tier. The load balancer is now the single point of failure. If it stops, every backend becomes unreachable, however healthy they are. This chapter assumes you know how Layer 4 and Layer 7 balancing work, what health checks do, and the basics of IP addressing and ARP.
The problem
Clients connect to one IP address. If the machine that owns that address fails, nothing answers. The fix is to run two or more load balancers and let the address move or be shared between them. The goal is that clients keep using the same address and never notice a failure.
Active-passive pairs with a virtual IP
The most common design uses two load balancers and a virtual IP (VIP). A VIP is an address that is not tied to one machine. Whichever node is currently the primary holds it. The standby watches the primary with a heartbeat. When the heartbeat stops, the standby takes over the VIP and announces it on the local network with a gratuitous ARP. This is a message that tells switches and neighbors that the address now belongs to a different MAC address.
VRRP (Virtual Router Redundancy Protocol) is the standard protocol for this. Keepalived is the usual Linux implementation, and it is often paired with HAProxy or NGINX.
A minimal Keepalived configuration for the primary:
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass s3cret
}
virtual_ipaddress {
192.0.2.10/24
}
}On the standby, use state BACKUP and a lower priority, for example 90. The node with the higher priority holds the VIP. With advert_int 1, failover usually takes a few seconds.
Active-passive is simple, but the standby sits idle, so you pay for capacity you do not use. Connections that were open on the primary are usually dropped at failover unless you also synchronize connection state.
Active-active
In an active-active design, all load balancers carry traffic. There are two common ways to do it:
- Several VIPs. Each node owns one VIP, and DNS returns all of them. If a node fails, a peer takes over its VIP.
- ECMP with anycast routing. Every load balancer announces the same IP to upstream routers using BGP. The routers spread flows across the nodes with equal-cost multipath (ECMP). If a node stops announcing, routers stop sending it traffic.
Active-active uses all your hardware and scales out, but it is harder to run. With ECMP, a change in the set of nodes can re-map flows to different load balancers mid-connection. This is one place where consistent hashing, covered in the previous chapter, helps.
Common errors
- Split brain. If the heartbeat link fails but both nodes are alive, both claim the VIP. Duplicate ARP answers cause intermittent failures. Reduce the risk by sending heartbeats over more than one network path.
- Configuration drift. The standby has a different config than the primary, so failover works but behavior changes. Deploy the same configuration to both nodes from one source.
- Untested failover. A standby that has never taken over may have a wrong interface name, a firewall rule that blocks VRRP (IP protocol 112), or a missing certificate. Test by stopping the primary regularly.
- Session state lost. Sticky-session tables stored in memory on the primary are gone after failover. Prefer cookie-based persistence, which is stored in the client.
- Cloud networks. Many cloud networks do not allow gratuitous ARP to move an address. There you use the provider's managed load balancer, which is already redundant across zones, or an API call to reassign the address.
Choosing a design
| Design | Failover | Capacity use | Complexity |
|---|---|---|---|
| Active-passive with VIP | Seconds | Half idle | Low |
| Active-active with several VIPs | Seconds, plus DNS behavior | Full | Medium |
| Active-active with ECMP and BGP | Sub-second to seconds | Full | High |
| Managed cloud load balancer | Handled by provider | Provider-managed | Low |
Start with an active-passive pair unless you need more throughput than one node provides.
Exercise
Two load balancers in an active-passive pair both lose the network link between them, but both still reach the clients. What happens, and how can you reduce the chance of it?
Show answer
Each node stops receiving heartbeats and assumes the other has failed, so both take the VIP. This is split brain, and it causes intermittent failures from duplicate ARP replies. Reduce the risk by sending heartbeats over more than one independent network path, such as a dedicated cable plus the main network.
Exercise
Why does an in-memory sticky-session table on the primary load balancer weaken a VIP failover design, and what is an alternative?
Show answer
After failover, the standby has no copy of the table, so clients lose their mapping to a backend and may be sent to a different one. Use cookie-based persistence, where the mapping is stored in the client, or synchronize the table between nodes.