System Design · Practice problem · Easy
Keep a Read-Heavy API Fast
A read-heavy API stays fast when most reads never reach the database. Serve them from a cache or read copies, and set a lifetime short enough that answers stay fresh. Build that here, then run it under real traffic.
Easy means one bottleneck to find. You solve it on a canvas that runs your design. The canvas needs JavaScript; everything on this page works without it.
What is the situation?
You run the product pages for a busy shop. Customers read prices all day, and the merchandising team changes a price now and then. Most visitors look at the same popular products. Design the system behind these two APIs, so that pages stay fast, prices stay fresh, and the bill stays under budget.
What must your design do?
- Reads answer within 100 ms at the 99th percentile.
- At least 99.9% of reads and of writes are served.
- No reader sees a price older than 60 seconds.
- The system costs $1,250 a month or less.
- Reads and writes both reach durable storage.
What does Run test?
Run works without an account. It checks your design against 2 tests you can read before you start:
- A normal morning. 8,000 requests a second for 20 seconds, 98% of them reads, starting with 50,000 products already in any cache you built.
- An empty cache. The same morning, but any cache you built starts empty, so the first reads for every product miss.
What does Submit add?
Submit needs an account. It runs 2 more tests you cannot read in advance, and stops at the first one your design fails, showing what happened and why. Passing every test, or giving up, unlocks the written solution.
Which parts can you use?
- Load Balancer: about 50,003 a second, $18 a month each
- App Server: about 2,000 a second, $45 a month each
- Cache: about 100,003 a second, $30 a month each
- Database: about 5,000 a second, $120 a month each
- Read Replica: about 5,000 a second, $90 a month each
Every connection takes 1 ms, and the budget is $1,250 a month.
What does this problem leave out?
- Cache memory limits and eviction.
- A cache server dying.
- Invalidating a cache on write.
- Connection pools and serialisation.
- Regions.
Where does this problem fit?
Its category is Read-heavy: Serve billions of reads fast. It practises caching, partitioning, replication and consistency.
By GOAT Engineer. Explore System Design · Privacy Policy · Contact.