Lab · Building blocks

Service discovery: a registry, heartbeats and old lists

A registry keeps the list of a service's live copies. Three copies of a payments service tell it they are alive, and a caller, the orders service, keeps its own copy of that list. Stop a payments copy, or the registry, and see how long the caller keeps sending to something that is gone.

Try it

Lab time 3.0 s
The caller, the orders serviceThe callerthe orders servicelist of 3, 0.8 s oldRegistry, lists 3 copiesRegistrylists 3 copiesdrops after 2 missedPayments 1, 10.0.0.1:8080Payments 110.0.0.1:8080on the listPayments 2, 10.0.0.2:8080Payments 210.0.0.2:8080on the listPayments 3, 10.0.0.3:8080Payments 310.0.0.3:8080on the list
  • The caller — the orders service — healthy — list of 3, 0.8 s old
  • Registry — lists 3 copies — healthy — drops after 2 missed
  • Payments 1 — 10.0.0.1:8080 — healthy — on the list
  • Payments 2 — 10.0.0.2:8080 — healthy — on the list
  • Payments 3 — 10.0.0.3:8080 — healthy — on the list
  • Request
  • Response
  • Error / rejected
  • Event / message
  • Health check
  • Write
Failing now
0%
of requests, over the last 2 s
Requests failed
0/ 26
since the run began
Sent to a copy that cannot answer
0
0 of them tried again on another copy
Registry dropped it after
–
no copy is stopped or broken now
Caller sent to it for
–
no copy is stopped or broken now
Copies on the registry's list
3/ 3
a copy is dropped after 2 s of silence
Copies on the caller's list
3/ 3
fetched 0.8 s ago

Numbers add up:26 arrived = 22 answered + 0 failed at a stopped or broken copy + 0 failed with no copy known + 4 in progressThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

The registry
How the registry learns that a copy is alive

Each copy tells the registry "I am alive". A copy that runs but cannot answer still sends them.

1 s
2

With these two settings, a copy is dropped after 2 s with no good word from it.

Registry

Heartbeats: each copy reports in by itself. Health checks: the registry asks each copy to do a small piece of real work.

The callers
2 s

After one failed call, a caller stops using that copy until its next fresh list, and tries the request once more on another copy.

A cart service with its own copy of the list. It fetches half a gap after the orders service.

6/s
Copies of payments
Payments 1
Payments 2
Payments 3

A copy that stops says nothing to anyone. A broken copy still runs, and still sends heartbeats when those are in use, but every request to it fails.

Failed requests (%)
02550751001s2s3s
Show data table
TimeFailed requests
1s0
1s0
2s0
2s0
3s0
3s0
Copies on each list
The registry's listThe first caller's list
00.81.52.331s2s3s
Show data table
TimeThe registry's listThe first caller's list
1s33
1s33
2s33
2s33
3s33
3s33

What just happened

Nothing yet. Start traffic or run an experiment.

What this model simplifies
  • The times are short so you can watch them: a heartbeat every second and a fresh list every 2 seconds. Real systems often wait 10 to 30 seconds for each.
  • There are at most two callers, and they share the same requests a second between them. A real system has many, and each holds a list of a different age.
  • Choosing health checks turns heartbeats off. Real systems often use both. The registry also keeps asking a copy it has dropped, and lists it again when it answers well.
  • The registry is one box. A real one runs as several copies that agree with each other, so that one of them can stop.
  • A request to a stopped copy fails after 80 ms. A real dead machine often gives no answer at all, and the caller must wait for its own time limit.
  • A broken copy fails every request and every health check. A real one may fail only some of them, and a health check is only as good as the work it asks for.
  • When the registry comes back, it starts its count again for every copy on its list. Real registries have their own, more careful, rules for this.
  • With "Skip a copy that fails" on, a caller tries a failed request once more, and forgets what it skipped at its next fresh list.
  • The callers pick a copy themselves. A load balancer in front of the copies, which is the other common design, is left out.