Vector Clock in Distributed System clock design vector.

Vector Clock in Distributed System clock design vector.



play-rounded-fill play-rounded-outline play-sharp-fill play-sharp-outline
pause-sharp-outline pause-sharp-fill pause-rounded-outline pause-rounded-fill
00:00

🔹 Vector Clock in Distributed Systems – Clock Design & Concept


✅ What is a Vector Clock?

A Vector Clock is a logical clock mechanism used in distributed systems to capture causal relationships between events — especially to determine whether one event happened before another (→ “happened-before” relation).

Unlike Lamport clocks (which can only show if events are ordered or concurrent), vector clocks can precisely track causality.


🧭 Why is it Needed?

In distributed systems, due to the absence of a global clock:

  • It’s hard to know the actual order of events.
  • Vector clocks help track causal dependencies among processes.

📐 Vector Clock Design (Structure)

Each process in a distributed system maintains a vector of integers — one entry for every process in the system.

Example:

For a system with 3 processes P1, P2, P3, each process maintains a vector clock like:

VC(P1) = [v1, v2, v3]

Where:

  • v1: P1’s own clock
  • v2: P1’s knowledge of P2’s clock
  • v3: P1’s knowledge of P3’s clock

🔧 How Vector Clocks Work (Rules):

  1. Initialization:
    • Every process starts with vector [0, 0, ..., 0]
  2. Local Event:
    • A process increments its own clock.
    • VC[i] = VC[i] + 1
  3. Send Message:
    • Increment local clock.
    • Send the entire vector along with the message.
  4. Receive Message:
    • Increment own clock.
    • Take the element-wise maximum of the received vector and own vector.
    VC[i] = max(VC[i], received VC[i]) for all i
    

📊 Example:

Let’s assume:

  • P1 sends a message to P2
  • VC(P1) before sending: [2,0,0]
  • P1 sends message → [3,0,0] to P2

P2 receives message when its clock was [1,2,0]
Now it computes:

VC(P2) = max([1,2,0], [3,0,0]) → [3,2,0]
Then increments its own component → [3,3,0]

🧠 Interpretation of Vector Clocks:

For two events with vector clocks VC1 and VC2:

  • VC1 < VC2 → VC1 happened before VC2
  • VC1 || VC2 → Events are concurrent (no causal relationship)

📝 Benefits of Vector Clocks:

  • Captures causality precisely.
  • Helps in version control, conflict resolution, and event ordering.
  • Used in distributed databases, Git, blockchains, etc.

⚖️ Limitations:

  • Requires O(n) space and communication overhead (where n = number of processes).
  • Not scalable for large systems.

Would you like a diagram, visual animation, or real-world application (like in DynamoDB or Git)? I can also provide this in Hindi if you prefer.

Vector Clock in Distributed System clock design vector.

LOGICAL AND VECTOR CLOCKS USED IN …

A Practical Tour of Vector Clock Systems.

Clocks in Distributed System

Chapter 3: Logical Time



Leave a Reply

Your email address will not be published. Required fields are marked *

error: