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.

Play the level

Date as shard keyTap, drag or use arrow keys to change the shard key

Date key · busiest shard 18,000 writes/s, one shard takes 10,000

Hash of the order IDTap, drag or use arrow keys to change the shard key

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.

Case 1
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
HTTP/2HTTP/2HTTP/2UsersUsersUsersWide-column…1 vCPU · 1 GBWide-column…1 vCPU · 1 GBWide-column…1 vCPU · 1 GB
HTTP/2HTTP/2HTTP/2UsersUsersUsersWide-col…Wide-col…Wide-col…
Date as shard key: misses a goal
HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2UsersUsersUsersWide-column…1 vCPU · 1 GBWide-column…1 vCPU · 1 GBWide-column…1 vCPU · 1 GB
HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2HTTP/2UsersUsersUsersWide-col…Wide-col…Wide-col…
Hash of the order ID: meets the goals