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 a vector (equivalently, a 1-dimensional array) of n logical clocks, one clock per process. Besides maintaining its own clock, every process also keeps track of the largest value of each of the other processes' clocks that it has so far been informed of. The clock updates proceed as follows, where V C i {\displaystyle VC_{i}} denotes the value of the vector clock maintained by process i {\displaystyle i} :
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 {\displaystyle i} , it updates V C i [ i ] ← V C i [ i ] + 1 {\displaystyle 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 {\displaystyle P_{i}} receives a message ( m , V C j ) {\displaystyle (m,VC_{j})} from P j {\displaystyle P_{j}} , it first increments its own logical clock in the vector by one V C i [ i ] ← V C i [ i ] + 1 {\displaystyle VC_{i}[i]\leftarrow VC_{i}[i]+1} and then updates its entire vector by setting V C i [ k ] ← max ( V C i [ k ] , V C j [ k ] ) , ∀ k {\displaystyle VC_{i}[k]\leftarrow \max(VC_{i}[k],VC_{j}[k]),\forall k} .
History Lamport originated the idea of logical Lamport clocks in 1978. However, the logical clocks in that paper were scalars, not vectors. The generalization to vector time was developed several times, apparently independently, by different authors in the early 1980s. At least 6 papers contain the concept. The papers canonically cited in reference to vector clocks are Colin Fidge’s and Friedemann Mattern’s 1988 works, as they (independently) established the name "vector clock" and the mathematical properties of vector clocks.
Partial ordering property Vector clocks allow for the partial causal ordering of events. Defining the following:
V C ( x ) {\displaystyle VC(x)} denotes the vector clock of event x {\displaystyle x} , and V C ( x ) z {\displaystyle VC(x)_{z}} denotes the component of that clock for process z {\displaystyle z} .
V C ( x ) < V C ( y ) ⟺ ∀ z [ V C ( x ) z ≤ V C ( y ) z ] ∧ ∃ z ′ [ V C ( x ) z ′ < V C ( y ) z ′ ] {\displaystyle VC(x)<VC(y)\iff \forall z[VC(x)_{z}\leq VC(y)_{z}]\land \exists z'[VC(x)_{z'}<VC(y)_{z'}]}
… excerpt ends here. Continue reading the full article.


