Date shard key vs hash shard key
A date key sends all of today's orders to one shard. A hash of the order ID spreads them evenly. With three shards, the date key drives one shard to 180 percent CPU and availability falls to 55.8 percent. The hash key keeps p99 at 3.6 ms.
Date key · busiest shard 18,000 writes/s, one shard takes 10,000
Order ID hash · busiest shard 6,000 writes/s, one shard takes 10,000
Case 1
Three shards take new orders. One user sends two thirds of them, and every order has today's date. CPU must stay below 85 percent, p99 below 100 ms and availability above 99.5 percent.
| Measure | Goal | Date as shard key | Hash of the order ID |
|---|---|---|---|
| p99 latency (*) | under 100 ms | 848 ms Fail | 4.9 ms Pass |
| Availability (*) | at least 99.5% | 55.8% Fail | 100% Pass |
| CPU use | under 85% | 180% Fail | 60% Pass |
| Monthly cost | 12 USD/mo | 12 USD/mo | |
| p99 latency | 808 ms | 3.6 ms | |
| Error rate | 42.9% | 0% | |
| Level rules | none broken | Board is not complete Fail | Pass |