Sharding hard
In a multi-master sharded system using 'Vector Clocks', what is the result if two clients update the same record on different servers at the exact same time (a 'Concurrent Write Conflict')?
- A The database preserves both versions as 'Siblings' and returns both to the next reader, forcing the application code to perform a 'Conflict Resolution' (e.g., merging the two results).
- B Both servers will instantly enter a 'Split Brain' state and shut down to prevent data corruption.
- C The server uses 'Last Write Wins' (LWW) based on its local wall-clock time, simply deleting the older version.
- D The database uses a randomized coin-flip to decide which of the two versions should be the permanent record.
Answer: A. The database preserves both versions as 'Siblings' and returns both to the next reader, forcing the application code to perform a 'Conflict Resolution' (e.g., merging the two results).
Vector clocks don't 'solve' conflicts; they 'detect' them. Unlike simple timestamps (which can be wrong if clocks drift), Vector Clocks can prove that two events happened concurrently. By keeping both versions (Siblings), the database ensures no information is ever accidentally overwritten. This 'Causality Tracking' is the technical foundation of Amazon's Dynamo database. While it provides ultimate data safety, it is famously difficult for developers, who must now write code to handle the case where a database read returns two different values for the same key.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- In an E-Commerce platform, why might you choose to shard the `Orders` table by `user_id` rather than the more obvious `order_id`?
- In the context of database scaling, what is the fundamental difference between 'Vertical Partitioning' and 'Horizontal Partitioning' (Sharding)?
- If Shard A fails in a large cluster, and its incoming traffic is automatically re-routed to Shard B, what is the risk of a 'Cascading Failure'?
- In a standard 'Modulo Sharding' setup (`key % N`), what is the primary consequence of adding a new server to the cluster (increasing N from 10 to 11)?
- From an engineering perspective, when should you choose 'Vertical Scaling' (a bigger server) over 'Horizontal Scaling' (Sharding)?
- Which sharding strategy is mathematically optimized for efficient 'Range Scans' (e.g., retrieving all records created between January and March)?