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
- 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
Follow a request
Pause to pick a request that is on screen.
Show data table
| Time | Failed requests |
|---|---|
| 1s | 0 |
| 1s | 0 |
| 2s | 0 |
| 2s | 0 |
| 3s | 0 |
| 3s | 0 |
The registry's listThe first caller's list
Show data table
| Time | The registry's list | The first caller's list |
|---|---|---|
| 1s | 3 | 3 |
| 1s | 3 | 3 |
| 2s | 3 | 3 |
| 2s | 3 | 3 |
| 3s | 3 | 3 |
| 3s | 3 | 3 |
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.