retrystorm · Learn · Interview practice · Glossary · Components

Home › Interview practice › Fresh Enough Prices

Fresh Enough Prices

Prices change behind the cache's back. Pick a TTL that keeps them fresh without drowning the database.

Inkwell Shop's prices now change all day: a pricing job adjusts them in the database every few seconds. The job writes straight to the database, so the cache in front of it never hears about the change.

Finance has one rule: a shopper may see a price that is a few seconds out of date, but never one that changed more than 5 seconds ago. The database is a small one, shared with the pricing job, and it can't be made bigger.

What it does

  • Read: a shopper opens a product page.
  • Write: the pricing job changes a price (it goes around the cache).

Workload

A steady 8 000 rps, 95% reads / 5% writes, for 20 seconds, against 20 000 products. A few bestsellers get most of the views.

How to build it

  1. Build the path: client, load balancer, app server, cache, database. The app server calls the cache, and the cache calls the database.
  2. Run it without a TTL and look at how old the stale prices get.
  3. Set the cache's TTL. Too long and prices go stale; too short and the database can't keep up.

Part of Chapter 13: Choosing a TTL.

About · Contact · Privacy · Terms of use