Caching hard
In an Active-Active Geo-Replicated Redis (CRDB), two regions increment the same counter concurrently. How do CRDTs ensure consistency?
- A They implement a 'Last Write Wins' (LWW) conflict resolution policy based on highly synchronized NTP timestamps across all regional clusters.
- B They utilize a synchronous Paxos consensus protocol for every individual write operation to ensure all replicas agree on the final counter state.
- C They use PN-Counters (Positive-Negative) that merge by summing total operations from all replicas rather than overwriting a single value.
- D They enforce a global distributed lock on the specific counter key, effectively turning the active-active cluster into a single-writer system.
Answer: C. They use PN-Counters (Positive-Negative) that merge by summing total operations from all replicas rather than overwriting a single value.
**CRDTs (Conflict-free Replicated Data Types)** allow concurrent updates from multiple replicas to merge mathematically without conflict. A **PN-Counter** tracks increments (P) and decrements (N) separately across all nodes. The final value is simply `Sum(P) - Sum(N)`. This guarantees strong eventual consistency without requiring global locks or consensus (Paxos/Raft) for every write.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- In the Cache-Aside pattern, what happens when the application requests data that is missing from the cache (a 'Cache Miss')?
- Why use a centralized Distributed Cache (like a Redis Cluster) over local in-memory caches on each web server?
- Setting a short TTL (e.g., 60 seconds) on a cached object helps to:
- What is the primary architectural goal of introducing a cache into a system?
- Most caching systems rely on the principle of 'Temporal Locality', which states:
- Your cache uses an LRU (Least Recently Used) eviction policy. When the cache is full, which item is removed?