25-byte heartbeat propagation with epidemic routing, adaptive TTL, and O(log N) convergence for network-wide liveness detection.
The heartbeat system is how nodes detect each other's liveness across the entire network. Each node periodically broadcasts a compact heartbeat message that propagates epidemically through the mesh, reaching all nodes in O(log N) rounds.
Each heartbeat is exactly 25 bytes on the wire:
| Offset | Size | Field |
|---|---|---|
| 0 | 16 bytes | nodeId -- originator's unique identifier |
| 16 | 4 bytes | timestamp -- uint32 Unix epoch seconds |
| 20 | 1 byte | ttl -- remaining hop budget |
| 21 | 1 byte | hopCount -- hops from originator so far |
| 22 | 3 bytes | avgRtt -- originator's average RTT to neighbors (uint24, microseconds) |
The message type is 0x10 (HEARTBEAT_PROPAGATE).
Each node originates a heartbeat every 30 seconds. The heartbeat contains the node's own nodeId, the current timestamp, and the node's average measured RTT to its K=6 neighbors.
The initial TTL is calculated adaptively based on network size:
TTL = max(4, ceil(ln(N)))Where N is the number of nodes in the routing table. This ensures:
The logarithmic scaling means heartbeats reach the entire network without flooding it.
Heartbeats propagate using epidemic (gossip) routing:
Each round takes approximately one network hop (the RTT between neighbors). A heartbeat from any node reaches every other node in the network within a few hundred milliseconds for typical network sizes.
To prevent heartbeat storms, each node maintains a deduplication map keyed by {originatorId}:{timestamp}:
At 30-second intervals with typical network sizes, the map stays well within capacity.
Rather than writing every heartbeat to the database individually, nodes batch updates:
The heartbeat table directly drives the shard ring:
This creates a self-healing property: if a node goes offline, its shard responsibilities are automatically redistributed within 5 minutes without any manual intervention.