Unique IDs with Causality

Learn how to use the time to generate a unique ID and also maintain the causality of events.

Causality

In the previous lesson, we generated unique IDs to differentiate various events. Apart from the identification of events, we are also interested in finding the sequence of these events. Let’s consider an example where Peter and John are two Twitter users. John tweets on a Twitter post (event A), and Peter replies to John’s comment (event B). Event B is dependent on event A and cannot happen before it. The events are not concurrent here.

We can also have concurrent events, i.e., two events independent of each other. For example, if Peter and John comment on two different Twitter posts, there is no happened-before relationship (causality) between them. It is essential to identify the dependence of one event over the other but not in the case of concurrent events.

The above scenario can also be handled by assigning a unique ID and encoding the dependence of events using a social graph. We might also use a separate time data structure and a simple, unique ID. However, we want a unique ID to do the double duty—unique identification and also helping with the causality of events.

The following slides provide a visualization of concurrent and non-concurrent events.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy