Patterns
35 items
35 items
Handling concurrent updates in distributed systems
Conflict resolution handles the situation when multiple writers update the same data concurrently in distributed systems. Without coordination, concurrent writes can cause data loss or inconsistency. Strategies include: Last-Write-Wins (simple but lossy), application-level merge (custom logic), CRDTs (mathematically guaranteed convergence), and operational transforms (used by Google Docs). The right strategy depends on your data semantics - counters can use CRDTs, documents need operational transforms, and shopping carts can merge sets. This pattern is essential for any system with multiple writers, including multi-region databases, offline-capable apps, and collaborative editing.
In distributed systems, writes can happen simultaneously on different nodes. Network partitions mean nodes can't always coordinate. You must handle conflicting writes - the question is how.
Using timestamps to pick 'latest' write is simple but discards data. If user A adds item and user B changes quantity simultaneously, one change is lost. Acceptable for some data, dangerous for others.
Conflict-free Replicated Data Types are data structures that mathematically guarantee all replicas converge to same state. No coordination needed. Used by Redis, Riak, and collaborative apps.
Scenario: Multi-region database
Without conflict resolution: - Arbitrary winner based on arrival order - Or database rejects one write (unavailable) - Or data becomes inconsistent across regions