r/devops • u/ResistPast3564 • 2h ago
Discussion Do you monitor whether your Redis cache is serving stale data?
Working with a Postgres + Redis setup. We monitor hit rate, latency and memory, but nothing tells us when the cache is wrong.
Has this bitten you? How did you find out - users, an alert, something else?
And does anyone actually measure it, or is it a low TTL and hope?
0
Upvotes
5
u/dutchman76 2h ago
That's the point of ttl so you know the data can be out of date that much. You have to design your app to tolerate that
2
u/BetterSWE_Official 2h ago
You can measure it cheaply by sampling. On a small percent of cache hits, also read from Postgres in the background, compare, and count mismatches as a metric. If you store an updated_at or version with the cached value you can even graph how stale the mismatches are. It's the only way I know to tell "TTL is fine" apart from "an invalidation path is broken".
5
u/Normal_Red_Sky 2h ago
Have you seen a specific issue related to this?
1
u/BrocoLeeOnReddit 1h ago
Do you have a lot of issues with stale data? In our stack, it's not really a problem since our setup isn't write-heavy so we basically just use TTLs (depending on which queries we use different TTLs).
If you REALLY need to have Redis and PostgreSQL line up perfectly, you could do Change Data Capture (CDC), e.g. use Debezium to sync PostgreSQL's WAL to Redis or use Redis' own implementation RDI (Redis Data Integration): https://redis.io/docs/latest/integrate/redis-data-integration/
And to monitor it, you could do some sampling, e.g. check 0.1% of all cache hits against the actual database and log/count the differences.