# Vector clock

## Algorithm for partial ordering of events and detecting causality in distributed systems / From Wikipedia, the free encyclopedia

#### Dear Wikiwand AI, let's keep it short by simply answering these key questions:

Can you list the top facts and stats about Vector clock?

Summarize this article for a 10 year old

SHOW ALL QUESTIONS

Not to be confused with Version vector.

A **vector clock** is a data structure used for determining the partial ordering of events in a distributed system and detecting causality violations. Just as in Lamport timestamps, inter-process messages contain the state of the sending process's logical clock. A vector clock of a system of *N* processes is an array/vector of *N* logical clocks, one clock per process; a local "largest possible values" copy of the global clock-array is kept in each process.

Denote $VC_{i}$ as the vector clock maintained by process $i$, the clock updates proceed as follows:^{[1]}

- Initially all clocks are zero.
- Each time a process experiences an internal event, it increments its own logical clock in the vector by one. For instance, upon an event at process $i$, it updates $VC_{i}[i]\leftarrow VC_{i}[i]+1$.
- Each time a process sends a message, it increments its own logical clock in the vector by one (as in the bullet above, but not twice for the same event) then it pairs the message with a copy of its own vector and finally sends the pair.
- Each time a process receives a message-vector clock pair, it increments its own logical clock in the vector by one and updates each element in its vector by taking the maximum of the value in its own vector clock and the value in the vector in the received pair (for every element). For example, if process $P_{i}$ receives a message $(m,VC_{j})$ from $P_{j}$, it first increments its own logical clock in the vector by one $VC_{i}[i]\leftarrow VC_{i}[i]+1$ and then updates its entire vector by setting $VC_{i}[k]\leftarrow \max(VC_{i}[k],VC_{j}[k]),\forall k$.