~learn.
0:00 / 1:26
W04 · Caching

The page said $99. The card was charged $79. For an hour.

transcript

The page says 99 dollars. The card is charged 79. And it lasts a whole hour.

Monday. Customer support tickets spike. Flash sale price not showing. Wrong price displayed. And 147 more. Everyone asks one thing: why didn't the cache update?

At 10 o'clock, the sale drops the database price to 79. But the cache still holds 99, with a 1 hour TTL. For an hour, users see 99 and pay 79. At 11, it expires. The cache did exactly what it was told. Nobody told it the price changed.

So tell it. The service writes the database, and publishes an event. An invalidator consumes it, and deletes the Redis entry. About 100 to 500 milliseconds. Not an hour.

But here's the catch. Event delivery isn't guaranteed. Lose one event, with no TTL, and that price is stale forever.

Events only? One lost message, and nothing ever fixes it. So keep a short TTL under the events. Say 5 minutes. Normally, the event clears it in about 100 milliseconds. Lose an event? It expires within 5 minutes anyway.

Events make it fast. The TTL makes it safe. Stale for minutes. Never stale forever.

Full breakdown in the lecture.