Sharding easy
What is the primary advantage of 'Directory-Based' sharding over 'Hash-Based' sharding?
- A It uses an explicit 'Lookup Table' or 'Map' service to track data locations, allowing for the granular movement of individual records without a cluster-wide rehash.
- B It relies on a fixed mathematical formula (like modulo) that requires no central coordination or storage.
- C It is significantly faster because it eliminates the need for any mathematical calculations during a query.
- D It avoids the need for a central registry, making it a truly decentralized architecture.
Answer: A. It uses an explicit 'Lookup Table' or 'Map' service to track data locations, allowing for the granular movement of individual records without a cluster-wide rehash.
Hash sharding is simple but rigid—if you change the number of servers, the algorithm might map every key to a new location. 'Directory-Based' sharding provides much more control by using a service that says 'User 123 is on Server A'. This allows you to move specific users to different machines to balance load. The trade-off is the 'Lookup Table' itself, which becomes a critical point of failure and adds a small amount of latency to every database request.
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)?