Unique IDs with Causality
Design a distributed sequencer capable of generating unique IDs while preserving event causality. Compare physical clock solutions like Twitter Snowflake and Google TrueTime with logical clocks. Evaluate the trade-offs between consistency, scalability, and complexity in System Design.
Causality
In the previous lesson, we generated unique IDs. Beyond uniqueness, systems often need to reason about event ordering and causality. Consider two users on a social media platform. One user posts a comment (Event A), and another user replies (Event B). Event B depends on Event A and must occur after it. These two events are causally related.
Conversely, concurrent events occur independently. If Peter and John comment on two different Tweets simultaneously, there is no causal relationship between them. We need to identify dependencies where they exist.
Note: Causality can be modeled by encoding dependencies in a graph structure or by maintaining a separate logical time mechanism. In many designs, it is preferable to use an identifier that both guarantees uniqueness and preserves event ordering.
The following slides visualize concurrent and non-concurrent events.