Database DesignKey-Value Stores (Redis, DynamoDB)Medium⏱️ ~3 min

Consistency Models and Conflict Resolution Strategies

The Consistency Trade-off

Key-value stores span from strong consistency to eventual consistency. Strong consistency guarantees reads return the latest write, but adds 10-50ms latency for synchronous replication and may refuse writes during network partitions. Eventual consistency serves reads in under 5ms but risks stale reads.

Read and Write Quorums

Tunable consistency uses quorums: R nodes must agree on reads, W nodes must acknowledge writes. With replication factor N, if R + W > N, reads and writes overlap, guaranteeing reads see latest writes. Common configuration: N=3, R=2, W=2 balances consistency and availability. Lower quorums (R=1) return faster but may be stale.

Conflict Resolution: Last Writer Wins

When concurrent writes occur to the same key, the system must choose a winner. Last-writer-wins (LWW) uses timestamps: highest timestamp wins. Simple but can lose data if clocks skew or writes happen within clock resolution. NTP (Network Time Protocol, which synchronizes clocks across networked computers) keeps clocks within milliseconds, but edge cases remain. Applications must tolerate occasional lost updates.

Conflict Resolution: Vector Clocks

Vector clocks track causal relationships between writes by maintaining a counter per node. When two writes have incomparable vectors (neither happened-before the other), the system surfaces them as conflicts for application resolution rather than silently picking a winner. More complex but preserves all data.

CRDTs: Conflict-Free Data Types

CRDTs (Conflict-free Replicated Data Types) are data structures designed to merge automatically without conflicts. Counters, sets, and registers have CRDT variants that converge to consistent state regardless of update order. They eliminate conflict resolution complexity but constrain what data structures you can use.

💡 Key Takeaways
Strong consistency adds 10-50ms latency; eventual consistency serves reads in under 5ms
Quorum formula: R + W > N guarantees reads see latest writes
Last-writer-wins is simple but risks data loss from clock skew between nodes
Vector clocks surface conflicts for application resolution instead of silent data loss
CRDTs automatically merge without conflicts but limit available data structures
📌 Interview Tips
1When discussing consistency, ask what happens if two users update the same key simultaneously to show you understand conflict scenarios
2Mention the quorum formula R + W > N and give a concrete example like N=3, R=2, W=2
3Discuss trade-offs between LWW simplicity versus vector clock complexity for conflict handling
← Back to Key-Value Stores (Redis, DynamoDB) Overview
Consistency Models and Conflict Resolution Strategies | Key-Value Stores (Redis, DynamoDB) - System Overflow