Heartbeat
A periodic "I'm alive" message that lets a system notice when a node has failed. Simple to build, subtle to tune, because a slow node and a dead one look the same.
A heartbeat is the simplest failure detector there is: every node periodically sends a small “I’m still here” message to a monitor or to its peers. If the heartbeats stop for long enough, the node is presumed dead and the system reacts: it elects a new leader, reroutes traffic or restarts something.
The tuning problem
Two numbers decide how a heartbeat behaves: the interval and the timeout (how many missed beats before you declare death).
- Too aggressive: a garbage-collection pause or a congested network makes a healthy node look dead. You fail over needlessly, and in the worst case end up with two nodes both believing they’re the leader.
- Too relaxed: a genuinely dead node keeps receiving traffic for ages.
There’s no perfect setting, because from the outside a slow node and a crashed node are indistinguishable. That’s a practical face of FLP Impossibility. More sophisticated detectors (such as the phi-accrual detector used in Cassandra and Akka) output a suspicion level based on the history of arrival times, rather than a binary alive/dead.
Where heartbeats show up
- Consensus: in Raft, the leader’s heartbeats stop followers starting an election. Silence triggers one.
- Orchestrators: container platforms run liveness probes (restart if it fails) and readiness probes (stop sending traffic until it passes). Mixing them up is a classic way to cause a restart loop.
- Long-lived connections: WebSockets use ping/pong frames, and Server-Sent Events (SSEs) streams send comment lines, both to detect dead peers and to stop proxies culling an idle connection.
A small example
A real-time UI pings its socket every 15 seconds and expects a pong within 5. Two missed pongs and it closes the socket, shows a subtle “reconnecting” indicator, and reconnects with backoff and jitter. Without the heartbeat, a half-open connection can sit there looking fine while delivering nothing, which on a price screen is the worst possible failure: stale data that looks live.
In practice
Every time I’ve debugged “the data just stopped updating”, the root cause was a connection that had died silently and nothing noticed. A heartbeat plus a visible connection state is cheap, and it turns a silent failure into a handled one. The wider taxonomy is in Types of Failure.
- #distributed-systems
- #failure-detection
- #health-checks
- #websockets
↩ Linked from (6)
- FLP ImpossibilityGrowing
…ersion of a feeling every on-call engineer knows: is it down, or just slow? You can't know for sure, so every timeout is a guess, and the design question is what a wrong guess costs. Systems that are safe when the guess…
- RaftGrowing
The leader sends regular heartbeats. While they keep coming, followers stay followers. If a follower hears nothing for its election timeout, it becomes a candidate, increments the term and asks for votes. A candidate wit…
- Server-Sent Events (SSEs)Growing
…es can hold the stream back. Disable response buffering, and send a comment line (: ping) every so often as a Heartbeat so idle timeouts don't kill it.
- The Consensus ProblemGrowing
…including halfway through telling others what they decided. Messages can arrive late or out of order. And as failure detectors show, a node can't reliably tell a crashed peer from a slow one. Naive approaches, such as "…
- Types of FailureGrowing
Crash failures can be handled by replication and a way to notice the crash, usually a Heartbeat. Omission needs retries, which means duplicates, which means idempotency (Message Delivery Semantics). Timing failures are t…
- WebSocketsEvergreen
…balancers need WebSocket support and generous idle timeouts. Dead peers look alive. Use ping/pong frames as a Heartbeat to detect them and to keep proxies from culling the connection. Reconnection is your job. Exponentia…
↪ Links to (5)
Related by topic
- Growingmetaphor
Balance Is a Control Loop
Calisthenics Lab - Growing
Message Passing
Distributed systems - Seedmetaphor
Regress, Don't Grind: Graceful Degradation
Calisthenics Lab - Growing
AJAX Polling
Real-time UIs