Two primitives that pair well
Coordination services give clients two powerful tools. An ephemeral node exists only while its creator stays connected. A watch is a one time subscription that fires when a specific node changes or disappears.
Detecting liveness
Because an ephemeral node disappears when its client session ends, its mere presence proves the client is alive. A service can register itself by creating an ephemeral node at a known path. Other clients set a watch on that path and learn instantly when the service goes away.
- The owner creates an ephemeral node tied to its session.
- Observers watch the node for deletion.
- When the session ends, the node is removed and watchers are notified.
The catch with watches
A watch fires once and then must be re registered. Between the fire and the re registration, more changes can happen. Good clients always re read the current state after a watch fires rather than trusting the notification to carry the data.
Key idea
Ephemeral nodes prove liveness and watches deliver fast change notifications, but because a watch fires only once, clients must re read state and re register the watch each time.