Sharding medium
Your database is sharded by `user_id`, but you frequently need to look up users by their unique `email`. What is the primary technical trade-off of maintaining a 'Global Secondary Index' to support these queries?
- A It has no significant downside because modern databases keep all index data in the central router's RAM.
- B It significantly reduces the total storage capacity needed because the index replaces the need for full row replication.
- C It increases 'Write Amplification' and latency, as every new user registration now requires an atomic write to both the User Shard and the Index Shard across the network.
- D It makes read operations significantly slower than performing a full Scatter-Gather scan across all shards.
Answer: C. It increases 'Write Amplification' and latency, as every new user registration now requires an atomic write to both the User Shard and the Index Shard across the network.
A 'Local Index' (indexing a field on the same server) is fast. A 'Global Index' (an index table on a *different* server) requires a distributed transaction to keep the two in sync. When a user changes their email, the database must coordinate an update across two physical machines, often using a 'Two-Phase Commit' (2PC). This 'Write-path' complexity is why many developers choose to accept slightly slower reads or use a 'Lookup Service' (like Redis) rather than creating dozens of global indexes that will inevitably slow down every write to the database.
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)?