Sharding medium
Your social network is sharded by `user_id`. One specific 'Celebrity' user generates 10,000x more write traffic than the average user, creating a hotspot on Shard 1. How can you effectively bridge this write bottleneck?
- A Implement 'Sub-Sharding' for the celebrity's data by appending a random suffix to the shard key for their specific interactions (e.g., `celebrity_id_1`, `celebrity_id_2`).
- B Assign the celebrity a significantly larger integer ID to ensure it is prioritized by the database storage engine.
- C Add more 'Read Replicas' to Shard 1 to handle the increased load.
- D Relocate the celebrity to a shard with a faster NVMe SSD.
Answer: A. Implement 'Sub-Sharding' for the celebrity's data by appending a random suffix to the shard key for their specific interactions (e.g., `celebrity_id_1`, `celebrity_id_2`).
The 'Celebrity Problem' occurs because sharding is rigid. Adding read replicas doesn't solve a *write* bottleneck. To fix this, you must distribute the celebrity's writes across multiple shards. By adding a random salt or suffix to the shard key for that specific user, you break their 'Data Locality' to gain 'Write Scalability'. The trade-off is that *reading* the celebrity's data now requires a scatter-gather query across all the sub-shards you created, increasing the read complexity for that specific entity.
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)?