Bugpit

Lessons › From one user to millions

Add a cache

20,000 req/s at peak, 95% of them reads, and the machine budget is $1,800/month. Adding more and more replicas is getting expensive.

Play this level

Free with an account. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

Most traffic hits a small set of popular data. A Cache (Redis) keeps it in memory: about 1 ms per read instead of ~10 ms, and ~100,000 operations/sec per instance (§7).

Cache-aside: the app checks the cache first. On a miss it reads the database and stores the result. The hit rate decides how much load the database still sees.

What you have to achieve

20,000 requests a second at the busiest hour, 5% of them writes.

What you learn

A 90% hit rate cuts database reads by 10×. Look at the bill too: internet traffic costs far more than the machines, and every byte you send counts.

Check yourself

A cache has a 90% hit rate. How much does it cut database reads?

Show the answer

By 10×. Only 1 read in 10 misses and reaches the database, so it sees a tenth of the reads.

In cache-aside, what happens on a miss?

Show the answer

The app reads the database and stores the answer in the cache. The app checks the cache first. On a miss it reads the database, then saves the result so the next read hits.

Try it yourself

More in From one user to millions

← Scale out CDN, queues and no single point of failure →