Logical Clocks(II) — Clock Series
Pratik Pandey
Senior Software Engineer at Booking.com | AWS Serverless Community Builder | pratikpandey.substack.com
In my last article, we learned about Lamport Clocks and we saw how Lamport clocks could help us define ordering between our operations. However, given Lamport times( L(A) < L(B) ), we cannot tell whether A happened before B or A and B happened concurrently. It only tells us that B did not happen before A.
If we need to determine whether A happened before B, or the events were concurrent, we need to use Vector Clocks.
Vector Clocks
To explain in simple terms, Vector clocks are an extension of Lamport clocks, where each node knows about the logical time of all the other nodes. (Remember that in?Lamport Clock?system, each node managed its clock independently and only knew about the logical time of the node it's receiving the message from).
Following are the steps followed by the algorithm -
Using the above image, we can derive the following -
领英推荐
If you notice the vector clocks associated with any events, they represent the logical clocks associated with the event, as well as include the state of any event before it, i.e the causal events. Eg — <2,2,0> represents the state when 2 events are received on node 1 and node 2, and none on node 3.
This brings us to the end of this article. We learned that Vector Clocks can help in establishing the ordering of operations, including identifying whether operations happened concurrently or were causally related. We’ll cover two more topics are part of this series, the next one on?Versioned Vectors, which are very close to vector clocks!
Thank you for reading! I’ll be posting weekly content on distributed systems & patterns, so please like, share and subscribe to this?newsletter?for notifications of new posts.
Please comment on the post with your feedback, will help me improve! :)
Until next time, Keep asking questions & Keep learning!
Senior Software Engineer at Booking.com | AWS Serverless Community Builder | pratikpandey.substack.com
2 年Please subscribe to my newsletter -?https://www.dhirubhai.net/newsletters/system-design-patterns-6937319059256397824/ Also, you can connect with me/book mock interviews with me on Topmate -?https://topmate.io/pratik_pandey You can follow me on Medium -?https://distributedsystemsmadeeasy.medium.com/subscribe