Challenge 15: Sales rank by category
The situation
Shoppers read each category's best sellers, and every purchase updates the ranking of its category. Traffic is far from even: a large share of it concerns one category, the current best-seller list, and each category's ranking lives on one cache partition. Every shopper sees the same ranking, and one a minute old is fine. A popular category page is requested again before a cached copy expires; a rarely viewed one is not. All the rankings fit in the rank cache's memory, so nearly every read that reaches it is a hit.
Traffic
30,000 requests a second. 50% of requests are for one key at a time. Each write also updates one entry in a cache, or in the store when there is no cache.
| Operation | Share | Steps |
|---|---|---|
| Read | 90% | Read data |
| Write | 10% | Write data |
- Read90%Read data
- Write10%Write data
Data
A CDN can answer 80% of reads at an edge. A cache answers 99% of the reads that reach it.
What you are proving
When one key carries a large share of the traffic, adding partitions does not help: the reads for it have to be answered before they reach the one partition that holds it.
Rules
- Each category's ranking stays one key, on one partition.A ranking is read whole, so splitting it would make every read gather all its parts; the lab keeps the hot category on one partition however many there are.
- A ranking may be up to a minute old.Rankings change at most hourly in the primer's design, so a copy cached for a minute costs shoppers little.
Builds on
Further reading: System Design Interview, volume 2, chapter 10.
Targets
- Serve all 30,000 requests a second
- At least 99.99% available, with no single point of failure
- At most 3,000 USD a month
- Any tier loses one instance: nothing dropped, no tier over 80% busy