System designLoading progress…

Health and readiness

Route requests across instances and calculate capacity with headroom, startup time and instance failures.

Health and readiness

Two different questions. Liveness: is the process stuck, so that it needs a restart? Readiness: should it receive traffic right now? A process still loading its model is alive but not ready. Health checks have their own failure modes: they can be stale, and a readiness check that requires a shared dependency turns that dependency's outage into a total outage, because every instance reports unready at once.

instancealive (liveness)model loadedreadygets traffic
#1yesyesyesyes
#2yesyesyesyes
#3yesnonono
#4NO → restartnonono
instances receiving traffic: 2 needing a restart: 1

Liveness asks whether the process needs recovery (restart it). Readiness asks whether it should receive traffic (not while loading). Checks can be stale, and overly strict ones can take the whole fleet out when a shared dependency fails.

Take the database down and make readiness strict.

Predict first. Should a process still loading its required model always receive normal traffic?

Chapter context

Load balancing distributes work among eligible backends. Scaling changes available capacity. Both require the application to manage state and dependencies so adding a process actually adds useful throughput.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

With demand R, per-instance capacity c and intended usable fraction u, require ncu≥Rncu\ge R. To keep that same target after one failure, require (n−1)cu≥R(n-1)cu\ge R. These are rate constraints, not a complete queueing or availability model.

Worked example

Demand is 900 requests/s. Each instance sustains 400 requests/s, but the target usable fraction is 75%, or 300 requests/s. Three instances meet normal demand. Four are required to maintain the same target capacity after losing one: (4−1)×300=900.

Reference code

The following example uses the Python standard library and does not call a remote service.

from math import ceil
demand,capacity,usable=900,400,.75
normal=ceil(demand/(capacity*usable))
resilient=normal+1
assert normal == 3 and resilient == 4
assert (resilient-1)*capacity*usable == demand

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

Horizontal scaling can move the bottleneck to a database. Healthy and ready are not identical. A load balancer does not repair session or transaction state lost with a backend.