Load Balancing
Distributed Systems & Scalability
Chapter 2 · Load Balancing
Chapter 1 showed horizontal scaling only helps once work can genuinely be split across machines. Load balancing is the part that actually does the splitting — and how it splits requests turns out to matter as much as whether it splits them at all.
Round Robin vs. Least Connections, With Unequal Servers
Three servers — two fast (capacity 5 requests/tick), one genuinely slow (capacity 2/tick) — under 12 new requests every tick for 20 ticks:
Health Checks: Routing Around a Server That's Actually Down
B going down partway through 30 requests: a plain Round Robin balancer with no health checking kept routing roughly a third of all remaining requests to the dead server, producing 7 failed requests out of 30. The identical scenario, routed through a balancer that filters to only currently-healthy servers before choosing one, produced 0 failed requests — every request was automatically redirected to A or C instead.
healthy boolean, checked with a plain if. Design Patterns Chapter 8 modeled a genuinely richer set of behaviors — an order's status — as full state objects, each owning its own transition rules. If a real health-check system needed more than "route or don't" (say, a "draining" state that finishes existing connections but accepts no new ones), the boolean would stop being enough, and reaching for that same State pattern would be the natural next step — not a different idea, just a heavier tool for a genuinely more complex version of the same problem.
Sticky Sessions: Solving Statelessness's Problem, Creating a New One
Software Architecture Fundamentals Chapter 8 verified a stateful design losing data on a server restart, and a stateless one surviving it. Sticky sessions are the load-balancer-level alternative: pin a client to the same server for their whole session, so that server can hold state in memory safely. What does pinning cost?
0.
Where This Connects
| This chapter's finding | What it connects to |
|---|---|
| An unbounded queue under Round Robin with unequal server speeds | Chapter 1's own horizontal-scaling findings — unequal processing capacity is exactly the condition that makes a "fair share of requests" different from "fair share of work" |
| Zero failures with health checking vs. 7 without | Chapter 9's own Fault Tolerance & Resilience Patterns — health checking is the first, simplest resilience pattern this course covers |
| Sticky sessions' verified 40-request spread from pure hash luck | Software Architecture Fundamentals Chapter 8's own statelessness finding — the two chapters verify opposite sides of the identical tradeoff |
Hands-On Exercises
Re-run this chapter's own Round Robin vs. Least Connections simulation with two slow servers (capacity 2/tick) and only one fast server (capacity 5/tick). Verify whether Least Connections still keeps queues bounded, and report the new queue depths for both balancers.
📄 View solutionUsing this chapter's own health-checking simulation, make two of the three servers go down at different points (B at request 10, C at request 20). Verify the health-checking balancer still produces zero failures, and report how many requests land on the one server left standing.
📄 View solutionUsing this chapter's own two verified findings (unequal-speed Round Robin, and sticky sessions), explain what specifically these two scenarios have in common: why does "give every option an equal share" produce a worse outcome than "route based on current state" in both cases?
📄 View solutionChapter 2 Quick Reference
- Round Robin: equal share of requests — verified: let a slow server's queue grow to
40and keep climbing, when server speeds genuinely differ - Least Connections: routes to whichever server has the least outstanding work — verified: kept the same slow server's queue capped at
3 - Health checks, verified:
7failed requests without them,0with them, for the identical mid-run server failure - Sticky sessions, verified: a
40-request spread from pure hash luck across 3 identical servers, versus0spread for the same traffic under Least Connections — the direct tradeoff against Software Architecture Fundamentals Chapter 8's own statelessness finding - Next chapter: Caching Strategies — cache-aside, write-through, write-behind, and why invalidation is the genuinely hard part