Load Balancing
Distribute requests across healthy service instances.
system design, load balancing, availabilityWhy share the work?
Imagine one school office receiving every timetable question. When many students arrive together, several helpers can share the queue. A load balancer is a traffic director: it selects a service instance, meaning one running copy of a service, for an incoming request. It can spread work and avoid sending new traffic to a copy known to be unhealthy.
School portal: read requests
- Two healthy portal instances can answer timetable requests using shared data.
- The balancer sends one request to A and a later request to B.
- A health check reports B unhealthy, so new requests go to A. Existing requests to B might still fail; A must have enough capacity.
See the reasoning
Route around an unhealthy instance
Follow new portal requests as health changes. This is a prepared demonstration, not live code execution.
First request
- Instance AHealthy; receives request 1Current focus
- Instance BHealthy
The balancer selects A.
Photo uploads: a different shape of work
For a hypothetical photo app, the balancer routes uploads to healthy upload instances. Large uploads occupy connections longer than small reads, so simple round-robin counts may distribute work unevenly. An interrupted upload may need a resumable protocol and shared durable storage; switching instances alone does not resume it.
Costs and failure
Health checks can be late or wrong. A balancer and its network path also need capacity and resilience, and a shared database can still be a bottleneck. Session affinity may keep a client on one instance, but makes failover and distribution harder; shared or stateless session handling is another option.
Reflect on the concept
Four fixed questions to reinforce the reasoning. Answers are not saved or scored.
