QA
Senior LevelSoftware Engineering Principles

How do Lamport Timestamps and Vector Clocks determine causal ordering in distributed systems?

❓ Interview Prompt: Explain Logical Clocks, Lamport Timestamps, Vector Clocks, detecting concurrent conflicts, causality tracking, and DynamoDB conflict resolution.

Physical system clocks cannot be synchronized perfectly across distributed servers due to clock drift. Logical clocks order distributed events without physical time:

1. Lamport Timestamps:

Assigns a monotonically increasing counter to events. Provides partial causal ordering ($A \rightarrow B \implies L(A) < L(B)$).

2. Vector Clocks:

Each node maintains a vector array of counters for all nodes ($V[1..N]$):

•
Detects causal independence / concurrent write conflicts ($V_A \parallel V_B$) when neither vector dominates the other, allowing systems (Riak/Dynamo) to trigger sibling conflict resolution!

Code Implementation Example

typescript
type VectorClock = Record<string, number>;

// Check if Clock A causally precedes Clock B
export function isCausallyPreceding(a: VectorClock, b: VectorClock): boolean {
  let strictlySmaller = false;
  for (const node in a) {
    if ((a[node] || 0) > (b[node] || 0)) return false;
    if ((a[node] || 0) < (b[node] || 0)) strictlySmaller = true;
  }
  return strictlySmaller;
}
💡Comparing Vector Clocks to evaluate causal event ordering.
🎯 Interview Key Takeaway

Use Vector Clocks to track causal event dependencies and detect concurrent write conflicts in distributed storage systems.

#Vector Clocks#Lamport Timestamps#Causality#Senior
Back to all Software Engineering Principles Questions→

More Software Engineering Principles Interview Questions

Beginner LevelSoftware Engineering Principles

Explain the 5 SOLID Principles of Object-Oriented Software Design with practical refactoring examples.

Beginner LevelSoftware Engineering Principles

What are DRY (Don't Repeat Yourself), KISS (Keep It Simple, Stupid), and YAGNI (You Aren't Gonna Need It)?

Beginner LevelSoftware Engineering Principles

Why is Composition Over Inheritance a fundamental object-oriented design principle?