Stateless HA Patterns: Load Balancing
You'll learn how load balancers distribute traffic across stateless instances to achieve high availability.
The Core Pattern
Since stateless services don't maintain session data locally (you learned this in lesson 2463), you can run multiple identical copies behind a load balancer. The load balancer acts as a traffic dispatcher, spreading incoming requests across healthy instances.
Think of a load balancer like a restaurant host who seats customers across multiple tables. If one table (instance) becomes unavailable, the host simply directs new customers to other tables. Because the service is stateless, it doesn't matter which table serves you—each provides the same experience.
How It Works
The load balancer performs health checks (lesson 2458) to detect failed instances. When an instance fails, the load balancer automatically stops routing traffic there and redistributes requests among remaining healthy instances. This happens transparently to users.
Load distribution (lesson 2457) spreads traffic evenly, preventing any single instance from becoming overwhelmed. Common algorithms include:
- Round-robin: Cycles through instances sequentially
- Least connections: Routes to the instance with fewest active connections
- Weighted: Assigns more traffic to higher-capacity instances
The High Availability Benefit
This pattern eliminates single points of failure (lesson 2450) at the application tier. Losing one instance doesn't cause downtime—the load balancer simply routes traffic to survivors. Combined with horizontal scaling (lesson 2462), you can add or remove instances based on demand.
Key Takeaway: Load balancers enable high availability for stateless services by distributing traffic across multiple instances, automatically routing around failures, and supporting elastic scaling without disrupting users.