Core Concepts

Heartbeat and Health Checks

Use silence to decide when to investigate, reroute traffic, or release a worker's claim.

Free~14 min

A heartbeat is a signal a component sends at regular intervals. If a worker stops reporting for longer than a configured timeout, the scheduler can mark it unavailable and start reassigning its work. The worker may still be running.

Tell a missing signal from a stopped worker

A crawler gives worker W1 a URL to fetch and expects to hear from it every 30 seconds. The worker sends a short message on that schedule, and the crawler records when the message arrives. A probe goes the other way. An observer contacts the component and checks the answer, such as whether an application can handle an HTTP request.

If the next heartbeat is late, W1 might have crashed. It might also be paused or unable to reach the receiver. The same silence can follow any of these events. A failure detector uses observations like this to suspect a failure under its timing assumptions. The rest of the system still decides how to act on that suspicion. Chandra and Toueg on unreliable failure detectors

A heartbeat from a process can arrive while the part of it doing a job is stuck. Pick a signal that fits the decision. A worker slot may need evidence that the job is making progress. A router may only need to know that the application can take another request. Build the action around what the receiver can actually observe.

Bound how long a worker may keep a job

A lease is permission that expires at a deadline. In the Distributed Web Crawler walkthrough, a worker gets a two-minute URL lease and sends a heartbeat every 30 seconds to extend live leases. A watchdog is a process that checks those deadlines. It scans every 10 seconds and returns an expired URL to pending so another worker can fetch it.

Use those intervals in a small example. W1 holds lease L1 on URL U42. The Frontier, the service that hands out URLs, accepts a renewal for L1 at 30 seconds. Its new lease deadline is 150 seconds. No more renewals arrive. The watchdog's first successful scan after expiry runs at 158 seconds. It makes URL U42 available, then W2 claims it with a new lease ID, L2.

W1 could come back after a pause and send a late renewal for L1. Check the lease ID and deadline in the same operation that changes the URL's state. A check of the worker name alone would miss a restarted worker or a new attempt from the same worker. L1 cannot extend L2 or mark W2's job done. A store that accepts effects outside the Frontier needs to enforce its own ownership rule or make repeats safe.

Choose a timeout the system can afford

A shorter lease frees jobs sooner after a real crash. It also expires more often when a live worker is slow, so another worker may do the same work. Measure normal heartbeat delays including time spent waiting for the receiver to process a renewal. Choose a lease long enough to tolerate expected gaps and test how long it takes a healthy watchdog to reclaim work. An unhealthy watchdog can add more delay than its scan period suggests.

The crawler can retry a URL and deduplicate stored content. That makes a repeat fetch cheaper than letting a URL remain stuck indefinitely. In the ChatGPT walkthrough, losing a worker's publishing permission has another consequence. The worker can still be running a model call. Recovery rejects its stale writes and holds the worker slot until it confirms that execution has stopped. The deadline ended the permission. The hardware can still be busy.

Check readiness separately from liveness

Suppose redirect API B has finished starting. Its process still answers a local check, but it temporarily loses access to a dependency needed for its route. A readiness check asks whether the instance is eligible for new work now. A liveness check asks whether the process is stuck in a condition a restart should fix. For B, the process can stay running while the router sends new traffic to API A.

Kubernetes makes these consequences concrete. A failed readiness probe makes the container unready. Kubernetes updates the Pod's readiness so a Service can direct regular traffic elsewhere as the endpoint change takes effect. Repeated liveness failures can restart the container. A configured startup probe gives slow initialization a separate period before readiness and liveness probes run. Kubernetes startup, readiness, and liveness probes

Keep probes quick and tied to what they control. If the service can serve a useful route without a shared dependency, a readiness test that requires that dependency for every instance could remove all targets during the outage. A liveness check of the same dependency can cause a fleet of healthy processes to restart together. Check request error rates and observed progress as well, because a passing probe is evidence for the check you built.

See also

  • Availability explains failure domains and how redundancy keeps work moving.
  • Idempotency explains how to make a reclaim safe if the first worker still acts.
  • Load Balancing covers readiness and draining for live traffic.
  • Failover covers deciding who can take over after a suspected failure.

Used in

  • Web Crawler (Distributed) renews URL leases with heartbeats and uses a watchdog to return expired jobs to pending.
  • ChatGPT distinguishes a worker's publishing permission from whether a model execution has actually stopped.
  • Online Chess uses game-owner heartbeats to refresh the Redis owner record used for routing.

Done reading? Mark it so it sticks in your dashboard.

Discussion