Health checks and failover
Detect failure quickly and correctly, then move traffic without making things worse.
15 min readLiveness versus readiness
A liveness check asks whether the process should be restarted: is it deadlocked or wedged? A readiness check asks whether it should receive traffic right now: has it warmed its cache, connected to the database, finished starting up? Mixing them causes trouble. If liveness depends on the database, a database blip restarts every instance at once, turning a short dependency outage into a full cold start of your fleet.
Shallow and deep checks
A shallow check (return 200 if the process is up) misses gray failures. A deep check that calls every dependency is accurate but dangerous: if a shared dependency fails, every instance reports unhealthy and the load balancer removes them all, even though they could still serve cached or degraded responses. A good compromise checks local resources deeply (disk, thread pool, memory) and reports dependency health as a signal for degradation rather than for removal. Many load balancers fail open when every target is unhealthy, sending traffic anyway, precisely to avoid this trap.
Detection time is a trade-off
Detection time is roughly interval x failure threshold. Checking every 10 seconds with 3 failures required means up to 30 seconds of errors before an instance is removed. Faster checks and lower thresholds detect sooner but cause flapping: an instance under brief GC pressure is removed, its load moves to the others, they slow down and are removed too. Use a lower threshold for removal than for re-adding, and combine active checks with passive signals such as the error rate of real traffic (outlier detection).
Failover for stateful components
Stateless instances simply drop out of rotation. Stateful ones need a failover: promote a database replica, move a leader, repoint clients. Each step takes time, typically 10 to 60 seconds for a managed database, plus DNS or connection-pool refresh. During failover, writes fail, so callers need retries. In SystCode, the Feedback panel's failure tests kill one component at a time; a design passes only if traffic finds a healthy path within the scenario's recovery target.
Key takeaways
- Separate liveness (restart me) from readiness (send me traffic)
- Deep health checks on shared dependencies can remove every instance at once
- Detection time equals check interval times failure threshold; tune it against flapping
- Stateful failover takes tens of seconds, so callers must retry through it
Sign in to track lessons and earn badges.