Earlier quoted context omitted.
I keep hoping Postgres will one day have the ability to mark a timestamp column as an expiry column. It would be useful for all kinds of things beyond caching, including session tokens, feature flags, background jobs, rate limiting, delayed deletion (as a variant of soft deletion), etc. It seems like the autovacuum could take care of these expired rows during its periodic vacuum. The query planner could automatically…
One could use a trigger for this. All we need is to setup a trigger that would delete all expired records looking at some timestamp column on update. That would eat up some latency but as was said, most projects would find it good enough anyway.
Redis is fast – I'll cache in Postgres
101–110 of 311 posts
Re: Redis is fast – I'll cache in Postgres
#102Why do we promote articles like this that have nice graphs and are well written, when they should get a grade 'F' as an actual benchmark study. The way it is presented, a casual reader would think Postgres is 2/3rds the performance of Redis. Good god. He even admits Postgres maxxed out its 2 cores, but Redis was bottlenecked by the HTTP server. We need more of an academic, not a hacker, culture for benchmarks.
Re: Redis is fast – I'll cache in Postgres
#103My laptop running OOTB Postgres in docker does 100k requests per second with ~5ms latency. How are you getting 20x slower?
[0]: https://dizzy.zone/2025/03/10/State-of-my-Homelab-2025/
Re: Redis is fast – I'll cache in Postgres
#104Earlier quoted context omitted.
A TTL doesn't really tell you if it's stale though. It gives you an upper bound on how long it can have been stale. But something becomes stale when the underlying resource is written to, which can happen an hour or an instant after you cache it. You should probably evict it when the write comes in. In my mind, it's for evicting things that aren't in use (to free up memory).
> A TTL doesn't really tell you if it's stale though (...) Non-sequitur,and imaterial to the discussion. > You should probably evict it when the write comes in. No. This is only required if memory is maxed out and there is no more room to cache your entry. Otherwise you are risking cache misses by evicting entries that are still relatively hot.
You said:
> The whole point of a TTL is to be able to tell whether a cache entry is still fresh or it is stale and must be revalidated.
So I responded to it. I don't really understand why you think that's nonsequiter.
> No.
I'm a bit confused. We're not using TTLs and we're not evicting things when they become invalid. What is your suggestion?
Re: Redis is fast – I'll cache in Postgres
#105Earlier quoted context omitted.
A TTL doesn't really tell you if it's stale though. It gives you an upper bound on how long it can have been stale. But something becomes stale when the underlying resource is written to, which can happen an hour or an instant after you cache it. You should probably evict it when the write comes in. In my mind, it's for evicting things that aren't in use (to free up memory).
> A TTL doesn't really tell you if it's stale though (...) Non-sequitur,and imaterial to the discussion. > You should probably evict it when the write comes in. No. This is only required if memory is maxed out and there is no more room to cache your entry. Otherwise you are risking cache misses by evicting entries that are still relatively hot.
Re: Redis is fast – I'll cache in Postgres
#106Earlier quoted context omitted.
most people with blogs don't know what they're doing. or don't care to know? sadly they get hired at companies and everyone does what they say cuz they have a blog. i've seen some shit in that department it's wild how much some people really are imposters.
> most people with blogs don't know what they're doing. or don't care to know? I don't see any point to this blend of cynical contrarianism. If you feel you can do better, put your money where your mouth is. Lashing at others because they went through the trouble of sharing something they did is something that's absurd and creates no value. Also, maintaining a blog doesn't make anyone an expert, but not maintaining a…
Re: Redis is fast – I'll cache in Postgres
#107Earlier quoted context omitted.
It's not a paper or a journal but you could at least try to run a decent benchmark. As it is this serves no purpose other than reinforcing whatever point you started with. Didn't even tweak postgres buffers, literally what's the point.
I still end up recommending using postgres though, don't I?
Re: Redis is fast – I'll cache in Postgres
#108Earlier quoted context omitted.
I like to call cases like this "premature distribution." Or maybe you could call it "premature capacity." If you have an application running in the cloud with several thousand requests per day, you could probably really benefit from adding a service like Redis. But when you have 0-10 users and 0-1000 requests per day, it can make more sense to write something more monolithic and with limited scalability. Eg, doing ev…
To be clear my question isn’t claiming redis isn’t premature optimization, but rather asking why the op thinks that it is. Being new doesn’t automatically mean that there is no need for latency sensitivity. Making that assumption could be just as premature. Ripping something out that is already working also takes time and the trade offs need to be weighed.
But I agree that it would be appropriate to start out that way in some projects.
Re: Redis is fast – I'll cache in Postgres
#109Earlier quoted context omitted.
I didn't say it's cheaper for the same cache size. But yeah a base tier Redis that will carry a small project tends to be a lot cheaper than the base tier Postgres.
> I didn't say it's cheaper for the same cache size. So be specific. What exactly did you wanted to say? > But yeah a base tier Redis that will carry a small project tends to be a lot cheaper than the base tier Postgres. This is patently false. I mean,some cloud providers offer nosql databases with sub-20ms performance as part of their free tier. Just go ahead and provide any evidence, any at all,that support the ide…
Re: Redis is fast – I'll cache in Postgres
#110Earlier quoted context omitted.
I still end up recommending using postgres though, don't I?
"I'll use postgres" was going to be your conclusion no matter what I guess? I mean what if an actual benchmark showed Redis is 100X as fast as postgres for a certain use case? What are the constraints you might be operating with? What are the characteristics of your workload? What are your budgetary constraints? Why not just write a blog post saying "Unoptimized postgres vs redis for the lazy, running virtualized wit…
Within the constraints of my setup, postgres came out slower but still fast enough. I don't think I can quantify what fast enough is though. Is it 1000 req/s? Is it 200? It all depends on what you're doing with it. For many of my hobby projects which see tens of requests per second it definitely is fast enough.
You could argue that caching is indeed redundant in such cases, but some of those have quite a lot of data that takes a while to query.