Load Balancing Algorithms and Strategies: Active-Passive vs Active-Active Explained
Active-passive configurations use one primary server to handle traffic while a standby node remains idle until failover occurs, whereas active-active architectures distribute requests across all available nodes simultaneously to maximize resource utilization and eliminate downtime during failures.
The system-design-primer repository provides foundational guidance on implementing resilient distributed systems, with specific emphasis on load balancing algorithms and strategies that ensure high availability. Understanding when to deploy active-passive versus active-active configurations is critical for architects designing fault-tolerant infrastructures that align with specific latency, consistency, and resource utilization requirements.
Core Load Balancing Patterns
The README.md file in the system-design-primer repository defines two fundamental high-availability patterns for load balancing: active-passive and active-active. Each pattern addresses different trade-offs between resource efficiency, failover speed, and operational complexity.
Active-Passive Failover
In an active-passive setup, one server (the active node) handles all incoming traffic while a second server (the passive node) remains on standby. The passive node continuously monitors the active node via heartbeat messages. If the active node fails and heartbeats stop, the passive node assumes the active IP address (VIP) and begins serving traffic.
According to the system-design-primer documentation, this pattern is ideal for critical services that must avoid state-synchronization complexity, such as databases or stateful APIs. The primary advantage is operational simplicity—there is no need for request-level synchronization between nodes. However, the trade-off includes failover time that depends on whether the standby is hot (ready) or cold (requires startup), and the passive node remains idle most of the time, resulting in wasted resources.
Active-Active Distribution
In an active-active configuration, all nodes simultaneously accept traffic and share the load. DNS or application logic must know the IP addresses of every instance, and each node typically maintains its own copy of data or uses a shared store.
The system-design-primer identifies this pattern as optimal for high-throughput front-ends, stateless services, or systems that already replicate data (such as web servers or caches). The advantages include full resource utilization, zero-downtime failover, and better scaling characteristics. The trade-offs involve increased complexity: data replication or conflict-resolution logic is required, and operational management is more demanding due to the need to handle split-brain scenarios and synchronization issues.
Architectural Implementation Details
Implementing these load balancing algorithms and strategies requires careful consideration of health-checking mechanisms, traffic distribution algorithms, and the network layer at which balancing occurs.
Health Checks and Virtual IP Failover
The failover mechanism in active-passive setups relies on continuous health monitoring. The passive node receives heartbeat signals from the active node at regular intervals. When these signals cease—indicating a failure—the passive node initiates a takeover sequence that includes assuming the virtual IP (VIP) address previously held by the failed node.
As documented in the system-design-primer, this pattern is often deployed with multiple load balancers for redundancy. The repository notes that "to protect against failures, it's common to set up multiple load balancers, either in active-passive or active-active mode," providing resilience at the load balancer tier itself.
Load Distribution Algorithms
When operating in active-active mode, load balancers employ various algorithms to distribute incoming requests. According to the system-design-primer's README.md, common routing metrics include:
- Random: Distributes requests arbitrarily across the pool
- Least loaded: Directs traffic to the server with the lowest current load
- Session/cookies: Routes based on user session data to maintain state consistency
- Round robin or weighted round robin: Cycles through servers sequentially, optionally assigning different weights to servers with varying capacities
These algorithms enable fine-grained control over traffic distribution in active-active architectures.
Layer 4 vs Layer 7 Load Balancing
The system-design-primer distinguishes between two operational layers for load balancers. Layer 4 balancers operate at the transport layer, making routing decisions based on IP addresses and port numbers while performing Network Address Translation (NAT). Layer 7 balancers operate at the application layer, inspecting HTTP headers, cookies, or request paths to enable content-based routing.
This distinction is critical when implementing load balancing algorithms and strategies, as Layer 7 balancing provides greater flexibility for session-aware routing in active-active clusters, while Layer 4 offers higher performance and simpler configuration for stateless traffic distribution.
Choosing Between Active-Passive and Active-Active
Selecting the appropriate pattern depends on specific architectural requirements regarding state management, latency tolerance, and resource efficiency.
| Criteria | Favor Active-Passive | Favor Active-Active |
|---|---|---|
| Statefulness | Strongly stateful services that cannot easily replicate state | Stateless or easily replicable state |
| Latency Sensitivity | Acceptable short fail-over pause | Zero-downtime required |
| Resource Utilisation | Lower cost for low-traffic workloads | High utilisation for large traffic |
| Complexity | Simpler operational model | Higher operational complexity (data sync, split-brain handling) |
Stateful services such as databases typically benefit from active-passive configurations to avoid complex distributed state synchronization. Conversely, stateless web servers and caching layers are ideal candidates for active-active deployment, maximizing throughput and eliminating single points of failure.
Configuration Examples
Practical implementation of these load balancing algorithms and strategies requires specific configuration patterns in popular software load balancers.
HAProxy: Active-Passive with Backup Nodes
The following configuration demonstrates active-passive failover using HAProxy's backup directive. In this setup, the server marked with backup only receives traffic when the primary server fails health checks.
# haproxy.cfg (run on both nodes)
global
maxconn 2000
log 127.0.0.1 local0
defaults
mode http
timeout connect 5s
timeout client 30s
timeout server 30s
frontend http_in
bind *:80
default_backend servers
backend servers
balance roundrobin
server app1 10.0.0.1:8080 check
server app2 10.0.0.2:8080 check backup # backup = passive node
The backup flag marks app2 as a passive instance; traffic is sent only when app1 fails. The surrounding infrastructure (e.g., keepalived) would move the virtual IP to the backup host.
NGINX: Active-Active Round-Robin
For active-active configurations, NGINX distributes traffic across all upstream servers simultaneously using load balancing algorithms such as round-robin.
# nginx.conf (identical on every load-balancer)
http {
upstream app_pool {
server 10.0.0.1:8080;
server 10.0.0.2:8080;
}
server {
listen 80;
location / {
proxy_pass http://app_pool;
proxy_set_header Host $host;
}
}
}
All servers receive traffic simultaneously; DNS points to multiple NGINX instances, each using the same upstream pool.
AWS Route 53: DNS-Based Active-Active
DNS-based active-active load balancing distributes traffic at the resolution layer, allowing geographic distribution and weighted routing without dedicated hardware.
{
"Comment": "Weighted routing for two web servers",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "app.example.com.",
"Type": "A",
"SetIdentifier": "us-east-1a",
"Weight": 50,
"TTL": 60,
"ResourceRecords": [{ "Value": "52.12.34.56" }]
}
},
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "app.example.com.",
"Type": "A",
"SetIdentifier": "us-east-1b",
"Weight": 50,
"TTL": 60,
"ResourceRecords": [{ "Value": "52.12.34.57" }]
}
}
]
}
Two IPs receive equal traffic; if one endpoint becomes unhealthy, Route 53 automatically routes all queries to the healthy one, achieving active-active with DNS-level health checks.
Summary
- Active-passive configurations utilize a single primary node with a standby replica, minimizing complexity for stateful services but leaving resources idle during normal operations.
- Active-active architectures distribute traffic across all available nodes, maximizing throughput and eliminating failover downtime, though they require robust data synchronization mechanisms.
- The system-design-primer repository documents both patterns in
README.md, emphasizing that multiple load balancers should be deployed in either configuration to prevent single points of failure at the load balancing tier itself. - Selection between patterns depends on statefulness requirements, latency sensitivity, and operational complexity tolerance, with databases typically favoring active-passive and stateless web services favoring active-active.
Frequently Asked Questions
What is the primary difference between active-passive and active-active load balancing?
Active-passive load balancing operates with one node handling all traffic while a secondary node remains on standby, ready to assume control via virtual IP takeover when heartbeat signals fail. Active-active load balancing distributes incoming requests across all available nodes simultaneously, requiring each node to handle production traffic and maintain synchronized state or shared data stores.
When should I choose active-passive over active-active for my database tier?
Choose active-passive configurations for strongly stateful services that cannot easily replicate state without complex conflict resolution, such as traditional relational databases or stateful APIs. This pattern avoids the synchronization complexity and potential split-brain scenarios inherent in active-active database clusters, accepting the trade-off of idle standby resources and brief failover latency.
How does the system-design-primer recommend handling load balancer redundancy?
According to the repository's README.md, you should protect against load balancer failures by deploying multiple load balancers in either active-passive or active-active mode. This prevents the load balancer itself from becoming a single point of failure, with active-passive configurations using heartbeat monitoring and virtual IP failover between balancer nodes, while active-active configurations distribute DNS resolution across multiple balancer IPs.
What load distribution algorithms work best with active-active configurations?
Active-active architectures benefit from algorithms that evenly distribute traffic while accounting for server capacity and session persistence, including round-robin, weighted round-robin, least-loaded, and session-based routing using cookies. The system-design-primer specifically documents these routing options in README.md, noting that Layer 7 load balancers can inspect HTTP headers and cookies for content-based routing, while Layer 4 balancers use IP and port information for faster packet-level distribution.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →