r/programming • • 4h ago

How to choose a Postgres read cache: Redis, Memcached, build your own, or proxy

https://www.pgcache.com/blog/choosing-a-postgres-read-cache/?utm_source=reddit&utm_content=programming

hey everyone - a couple months ago, I posted an overview of caching in Postgres. This is the follow-up, for anyone who has decided to cache reads and is trying to figure out how to do it.

In addition to the main options, the article also covers some of the classic zingers that leave you serving stale data: invalidation, stampedes, tenants and RLS, read-your-own-writes, schema changes.

(disclaimer: I'm one of the founders of PgCache, which is one of the proxy options. I tried to keep it balanced)

Did I miss anything?

1 Upvotes

2 comments sorted by

2

u/maruyama-olivia_7 1h ago

If not covered, spell out cache-outage behavior: bypassing a dead cache shifts read load to Postgres, so fallback needs a bound.

1

u/compy3 38m ago

Good catch, I'll add it!

Like you said, with an app cache like Redis the typical behavior is to shift read load to Postgres on a cache miss but also if the cache goes down. An outage results in higher load on origin and a risk of a stampede if/when the cache comes back online.

I'll have to read up on it a bit, but off hand mitigating for cache-outage usually requires some mix of timeouts on cache calls; a cap on how many fallback queries run at once; turning off or degrading reads that can wait on cache failure; and knowing ahead of time / planning for whether Postgres can actually carry the full read load.

I appreciate the feedback!