QA
Senior LevelSystem Design & Architecture

How do State-Based and Operation-Based CRDTs achieve Strong Eventual Consistency?

❓ Interview Prompt: Explain CRDTs (Conflict-Free Replicated Data Types), State-based (CvRDT) vs Operation-based (CmRDT), join-semilattices, and LWW-Element-Set.

Conflict-Free Replicated Data Types (CRDTs) achieve Strong Eventual Consistency (SEC) across distributed replicas without central locks or consensus rounds:

Mathematical Guarantees:

1
State-Based CRDTs (CvRDT): Replicas send full states. Merges use a Join-Semilattice operator that is Commutative ($A \lor B = B \lor A$), Associative, and Idempotent ($A \lor A = A$).
2
Operation-Based CRDTs (CmRDT): Replicas stream concurrent edit operations. Requires causal delivery guarantees.

Code Implementation Example

typescript
// State-based LWW (Last-Write-Wins) Element Set CRDT
class LWWRegister<T> {
  constructor(public value: T, public timestamp: number) {}
  
  // Merge operator: Commutative, Associative, Idempotent
  merge(other: LWWRegister<T>): LWWRegister<T> {
    return other.timestamp > this.timestamp ? other : this;
  }
}
πŸ’‘Implementing a Last-Write-Wins (LWW) Register CRDT.
🎯 Interview Key Takeaway

Use CRDTs with commutative merge operators to achieve strong eventual consistency across distributed replicas.

#System Design#CRDT#Eventual Consistency#Mathematics#Senior
Back to all System Design & Architecture Questions→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?