News for hackers. Stuff that matters.
Re:Redis is fast – I'll cache in Postgres by arp242 on Thursday September 25, 2025 @10:04PM (#45381776)
When I last benchmarked Redis vs. PostgreSQL for a simple k/v cache it was about ~1ms for PostgreSQL to fetch a key, and ~0.5ms for Redis with a similar setup as in this post (although I used "value bytea" instead of "value string" – I don't know if it matters, probably not; 1ms was fast enough that I didn't care to test).

I didn't measure setting keys or req/sec because for my use case keys were updated infrequently.

I generally find ms to be a more useful metric than reqs/sec or latency at full load, as this is not a typical load. Or at least wasn't for my use case.

Of course all depends on your use case etc. etc. In some cases throughput does matter. I would encourage everyone to run their own benchmarks suited to their own use case to be sure – should be quick and easy.

As I rule I recommend starting with PostgreSQL and using something else only if you're heavily using the cache or you run in to problems. Redis isn't too hard to run, but still just one less service to worry about. Or alternatively, just use a in-memory DB. Not always appropriate of course, but sometimes it is.

Re:Redis is fast – I'll cache in Postgres by xyzzy_plugh on Thursday September 25, 2025 @10:57PM (#45382116)
A difference of 0.5ms is negligible with single digit network latency. You would need significant batching to experience the effects of this difference.

Of course such sensitive environments are easily imaginable but I wonder why you'd select either in that case.

Re:Redis is fast – I'll cache in Postgres by arp242 on Thursday September 25, 2025 @11:01PM (#45382139)
> A difference of 0.5ms is negligible with single digit network latency

Yes, that was my take-away.

Re:Redis is fast – I'll cache in Postgres by Maskawanian on Thursday September 25, 2025 @10:37PM (#45381995)
When you benchmarked Postgres did you disable WAL for the cache table? That may minimize the difference.
Re:Redis is fast – I'll cache in Postgres by arp242 on Thursday September 25, 2025 @11:00PM (#45382135)
Unlogged table, yes. 1ms is more than fast enough so I didn't bother to look further.