The Generation Clock (also known as Term, Epoch, or Generation Number) is a critical logical clock pattern in distributed systems. It provides a mechanism to identify which node in a cluster is the current legitimate authority, preventing data corruption caused by "Zombie Leaders" (stale leaders that haven't yet realized they've been replaced).
In a distributed system, leadership is often managed via Leases. If a leader node experiences a long Stop-the-World GC Pause or a Network Partition, its lease may expire while it is "asleep."
The Generation Clock solves this by attaching a Fencing Token to every request.
Term: 5). The leader must include this number in every message it sends to followers or shared resources.Term: 5 and the resource is at 4, it accepts the write and updates its state to 5.Term: 4, the resource rejects the request because 4 < 5.While the pattern is identical, different systems use unique names for the Generation Clock:
| System | Name | Usage |
|---|---|---|
| Raft | Term | Incremented for every election cycle. Used to ignore stale RPCs. |
| ZooKeeper | Epoch | Incremented whenever a new leader starts a session. |
| Kafka | Controller Epoch | Ensures only one controller node manages the cluster. |
| Cassandra | Generation | Stored in the Gossip state to detect node restarts. |
It is called a Logical Clock because it measures Causality, not seconds. In distributed environments where physical clocks are unreliable (due to drift and skew), the Generation Clock provides a "Happens-Before" relationship: a message with a higher generation number is mathematically guaranteed to be more recent than one with a lower number.