Sharding medium
In a sharded system, why is 'Denormalization' (purposefully duplicating data) considered a standard performance optimization?
- A To ensure that every database request is satisfied by a single physical shard, thereby avoiding the massive latency penalty of cross-shard network communication.
- B To take advantage of the fact that storage space is inexpensive compared to the cost of high-speed CPU cycles.
- C To provide an additional layer of security by storing fragments of the same information in multiple locations.
- D To increase the total number of secondary indexes that can be maintained by each shard.
Answer: A. To ensure that every database request is satisfied by a single physical shard, thereby avoiding the massive latency penalty of cross-shard network communication.
The ultimate goal in sharding is 'Data Locality'. If you need to show an order history that includes the customer's name, and those two pieces of data live on different shards, you are forced to wait for two slow network requests. By duplicating the user's name directly into the 'Orders' table (denormalization), the query can be resolved entirely on the local shard. While this makes data updates (like changing a username) more complex—as you may need to update thousands of records across many shards—the gain in read performance is usually worth the trade-off for high-traffic apps.
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)?