Small regular 'I am alive' signals that let others notice when a machine stops.
A heartbeat is a tiny message that a machine sends again and again to say "I am alive". If the messages stop, the others know something is wrong.
When two machines talk over a network, silence is confusing. If a server does not answer, was it crashed, overloaded, or is the network just slow? From the outside these look the same. So systems use a simple habit: every machine regularly sends a small message, and everyone else watches the clock.
A heartbeat usually carries very little: the sender's name, a counter or timestamp, and sometimes a bit of health information such as load. It is sent at a fixed interval (for example every 1 second). The monitor decides a machine is dead after it has missed several beats in a row, called the timeout.
The worker decides when. Silence means trouble.
The monitor asks. A missing reply means trouble.
| Pattern | How it works | Good and bad |
|---|---|---|
| Central monitor | Everyone sends beats to one monitor or leader | Simple. The monitor is a single point of failure and may be overloaded. |
| Leader to followers | The leader sends beats, followers watch the leader (Raft) | Fast failover. Followers only watch one machine. |
| All to all | Every node pings every other node | No single point. Traffic grows with the square of the number of nodes. |
| Ring or random peers | Each node watches a few neighbours, or random ones (gossip) | Scales to thousands of nodes. Detection is slower and more complex. |
| Check | What it proves | What it misses |
|---|---|---|
| Process is running | The program has not crashed | It may be stuck or deadlocked |
| Network ping answers | The machine and network work | The app itself may be broken |
| Application health endpoint | The app can answer a request | A deeper dependency (database) may be down |
| Deep check (touches the database) | The whole path works | Heavy, and one shared dependency failing marks every server dead at once |
A simplified model with a fixed delay pattern (no random numbers). The monitor gives up when no heartbeat has arrived for the whole timeout. Real detectors (for example phi accrual) use the history of arrival times instead of one fixed number.
| Term | Meaning in easy words |
|---|---|
| Heartbeat | A small, regular message that says the sender is alive |
| Interval | How often a heartbeat is sent |
| Timeout | How long the monitor waits without a beat before it suspects failure |
| Failure detector | The part of a system that decides which nodes are alive or suspected dead |
| False positive | A healthy node wrongly declared dead |
| False negative | A dead node not noticed yet (it is still believed alive) |
| Liveness probe | A check that asks if a process is running and should be restarted if not (Kubernetes) |
| Readiness probe | A check that asks if a process is ready to receive traffic |
| Phi accrual detector | A detector that outputs a suspicion level learned from past beat timing |
| Lease | A permission that lasts for a set time and must be renewed, like a heartbeat with authority |
| Fencing token | An increasing number that lets storage reject writes from an old, wrongly trusted leader |
| Choice | We gain | We lose |
|---|---|---|
| Short interval | Faster detection | More traffic and CPU, and more chances for jitter to look like failure |
| Long interval | Cheap and quiet | Slow to notice a crash |
| Few misses allowed | Quick failover | More false alarms during hiccups |
| Many misses allowed | Stable, few false alarms | Users wait longer during a real failure |
| Fixed timeout | Simple to explain and debug | One number must fit every network condition |
| Adaptive detector | Fits each link, fewer mistakes | More complex to build and tune |