mediumSystem Design

How do distributed systems detect node failures?

979 views
01

Understand the problem

Explain heartbeats.

heartbeatfailure-detection
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

Heartbeat + timeout monitor
Run Playground
TIMEOUT = 3.0   # seconds without a heartbeat -> suspected dead
last_seen = {"n1": 0.0, "n2": 0.0, "n3": 0.0}

def heartbeat(node, now):
    last_seen[node] = now

def check(now):
    return {n: ("alive" if now - t <= TIMEOUT else "DEAD")
            for n, t in last_seen.items()}

now = 5.0
heartbeat("n1", now)
heartbeat("n3", now)        # n2 stopped sending heartbeats
print(check(now))           # n2 -> DEAD (silent past the timeout)
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.