Codewerk.
Get a quote
Home/Blog/Redis caching: the four patterns that matter

Redis caching: the four patterns that matter

Redis is not magic. Used badly it serves stale prices to real customers. Four patterns, and how to invalidate without fear.

Photo: free stock photography (Unsplash licence) — see imprint

Cache-aside is your default

Read from Redis; on a miss, read the database, write it back with a TTL. It is simple, easy to reason about and survives a Redis outage — the shop just gets slower, not broken. Start here and only leave when you have a measured reason.

Never cache what must be correct

Stock levels, customer-specific prices and cart totals should be read live or cached for seconds, not minutes. A cached price that is 4% too low is not a performance win — it is a discount you did not authorise.

Beware the stampede

When a popular key expires, a thousand requests all miss at once and hit the database together. Use a short lock or serve the stale value while one worker refreshes. Most 'Redis made it worse' stories are actually stampede stories.

Tag your keys or regret it

When a product changes, you must be able to invalidate everything derived from it — listing, detail, search facet, sitemap. Without a tagging scheme you will end up flushing the whole cache, and then you have no cache at all.

Key takeaways
  • Cache-aside first; complexity only when measured.
  • Prices and stock: seconds, never minutes.
  • No tagging scheme, no real cache.

We do this for a living — Shopware, Node.js, React, ERP integration and automation for B2B.

Talk to an engineer

// Keep reading

Related articles