Vector Clock is an algorithm that generates partial ordering of events and detects causality violations in a distributed system. These clocks expand on Scalar time to facilitate a casually consistent view of the distributed system, they detect whether a contributed event has caused another event in the distributed system. It essentially captures all the casual relationships. This algorithm helps us label every process with a vector(a list of integers) with an integer for each local clock of every process within the system. So for N given processes, there will be vector/ array of size N.
How does the vector clock algorithm work :
- Initially, all the clocks are set to zero.
- Every time, an Internal event occurs in a process, the value of the processes’s logical clock in the vector is incremented by 1
- Also, every time a process sends a message, the value of the processes’s logical clock in the vector is incremented by 1.
Every time, a process receives a message, the value of the processes’s logical clock in the vector is incremented by 1, and moreover, each element is updated by taking the maximum of the value in its own vector clock and the value in the vector in the received message (for every element).
Example-1:
Consider a process (P) with a vector size N for each process: the above set of rules mentioned are to be executed by the vector clock:

The above example depicts the vector clocks mechanism in which the vector clocks are updated after execution of internal events, the arrows indicate how the values of vectors are sent in between the processes (P1, P2, P3).
Example-2:
To sum up, Vector clocks algorithms are used in distributed systems to provide a casually consistent ordering of events but the entire Vector is sent to each process for every message sent, in order to keep the vector clocks in sync.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
Recommended Posts:
- Hashing in Distributed Systems
- Deadlock detection in Distributed systems
- Deadlock Detection in Distributed Systems
- Comparison - Centralized, Decentralized and Distributed Systems
- Interprocess Communication in Distributed Systems
- Synchronization in Distributed Systems
- Date's Twelve Rules for Distributed Database Systems
- Distributed File Systems
- Operating Systems | Input Output Systems | Question 5
- Advantages of Distributed database
- Mutual exclusion in distributed system
- Maekawa’s Algorithm for Mutual Exclusion in Distributed System
- Ricart–Agrawala Algorithm in Mutual Exclusion in Distributed System
- Lamport's Algorithm for Mutual Exclusion in Distributed System
- Suzuki–Kasami Algorithm for Mutual Exclusion in Distributed System
- Hierarchical Deadlock Detection in Distributed System
- Algorithm for implementing Distributed Shared Memory
- Difference between Network OS and Distributed OS
- Chandy-Misra-Haas's Distributed Deadlock Detection Algorithm
- Implementation of Access Matrix in Distributed OS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

