Live data from Hacker News

Redis is fast – I'll cache in Postgres

dizzy.zone

61–70 of 311 posts

Re: Redis is fast – I'll cache in Postgres

#61
post #53

Earlier quoted context omitted.

I might be ok with this if it were built in, but pg_cron is an extension, so first off you might not even have access to it. And then you still have to monitor it.

Seems like it's available on all the major providers.

Heroku doesn't have it. That's actually kinda annoying that they don't, cause the others do. AND they no longer have free Redis, so that changes things a bit.

Edit: well a tiny bit, max $3/mo

Re: Redis is fast – I'll cache in Postgres

#62
Given there is nothing at all said about the many config options that would contribute to Postgres for this use case, we must assume no configuration has been done.

Also, no discussion of indexes or what the data looks like, so we must assume no attention has been paid to their critical factors either.

So, another case of lies, damned lies and benchmarks.

It seem strange to me people are so willing to post such definitive and poorly researched/argued things - if you're going to take a public position don't you want to be obviously right instead of so easily to discount?

Re: Redis is fast – I'll cache in Postgres

#63

Earlier quoted context omitted.

I'm comfy with Postgres though, like I'll center my entire backend around it and do the heavy lifting in SQL (never ORM). It's more that I don't want to depend on a cronjob for something as fundamental as a cache. Usually Postgres costs a lot more than Redis if you're paying for a platform. Like a decent Redis or memcached in Heroku is free. And I don't want to waste precious Postgres connections or risk bogging down…

> Usually Postgres costs a lot more than Redis if you're paying for a platform. You need to back up your unbelievable assertion with facts. Memory cache is typically far more expensive than a simple database, specially as provisioning the same memory capacity as RAM is orders of magnitude more expensive than storing the equivalent data in a database.

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.

Re: Redis is fast – I'll cache in Postgres

#64
post #58

Earlier quoted context omitted.

> Yeah, the article was like "I always need a DB anyway" but then sets up an extra cronjob to expire keys, plus more code. You do not need cron jobs to do cache. Sometimes you don't even need a TTL. All you need is a way to save data in a way that is easy and cheaper to retrieve. I feel these comments just misinterpret what a cache is by confusing it with what some specific implementation does. Perhaps that's why we…

If we don't use a TTL, aren't we going to have to either accept that our cache will grow without bounds or take an even more sophisticated approach (like tracking access times instead of creation times)? Is there something simpler I'm not seeing?

I've tried it this way. You can get away with no TTL if your keys are constrained. Sometimes there are enough keys to be a problem. I'd rather just set up a TTL and not worry about this.

Re: Redis is fast – I'll cache in Postgres

#65

> Both postgres and redis are used with the out of the box settings Ugh. I know this gives the illusion of fairness, but it's not how any self-respecting software engineer should approach benchmarks. You have hardware. Perhaps you have virtualized hardware. You tune to the hardware. There simply isn't another way, if you want to be taken seriously. Some will say that in a container-orchestrated environment, tuning go…

Fully agree.

Postgres is a power tool usable for many many use cases - if you want performance it must be tuned.

If you judge Postgres without tuning it - that's not Postgres being slow, that's the developer being naive.

Re: Redis is fast – I'll cache in Postgres

#66
Is this engagement bait? Sigh... fine, at least I bite the bait here:

1. The use-case is super specific to homelab where consistency doesn't matter. You didn't show us the Redis persistence setup. What is the persistence/durability setting? I bet you'd lose data the one day you forgot and flip the breaker of your homelab.

2. What happened when data is bigger than your 8GB of RAM on Redis?

3. You didn't show us the PG config as well, it is possible to just use all of your RAM as buffer and caching.

4. Postgres has a lot of processes and you give it only 2 CPU? Vanilla Redis is single core so this race is rigged to begin with. The UNLOGGED table even things out a bit.

In general, what are you trying to achieve with this "benchmark"? What outcome would you like to learn? Because this "benchmark" will not tell you what you need to know in a production environment.

Side note for other HN readers: The UNLOGGED table is actually very nifty trick for speeding up unit tests. Just perform ALTER to UNLOGGED tables inside the PG that's dedicated for CI/CD: ALTER TABLE my_test_table SET UNLOGGED;

Re: Redis is fast – I'll cache in Postgres

#67

Why 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.

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 blog doesn't mean you are suddenly more competent than those who do.

Re: Redis is fast – I'll cache in Postgres

#68

Earlier quoted context omitted.

I'm comfy with Postgres though, like I'll center my entire backend around it and do the heavy lifting in SQL (never ORM). It's more that I don't want to depend on a cronjob for something as fundamental as a cache. Usually Postgres costs a lot more than Redis if you're paying for a platform. Like a decent Redis or memcached in Heroku is free. And I don't want to waste precious Postgres connections or risk bogging down…

> Usually Postgres costs a lot more than Redis if you're paying for a platform. You need to back up your unbelievable assertion with facts. Memory cache is typically far more expensive than a simple database, specially as provisioning the same memory capacity as RAM is orders of magnitude more expensive than storing the equivalent data in a database.

Why would you cache the entire database though? Seems like an apples to oranges comparison.

Re: Redis is fast – I'll cache in Postgres

#69

Earlier quoted context omitted.

> Usually Postgres costs a lot more than Redis if you're paying for a platform. You need to back up your unbelievable assertion with facts. Memory cache is typically far more expensive than a simple database, specially as provisioning the same memory capacity as RAM is orders of magnitude more expensive than storing the equivalent data in a database.

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 idea that Redis is cheaper than Postgres. Any concrete data will do.

Re: Redis is fast – I'll cache in Postgres

#70

Earlier quoted context omitted.

> Usually Postgres costs a lot more than Redis if you're paying for a platform. You need to back up your unbelievable assertion with facts. Memory cache is typically far more expensive than a simple database, specially as provisioning the same memory capacity as RAM is orders of magnitude more expensive than storing the equivalent data in a database.

Why would you cache the entire database though? Seems like an apples to oranges comparison.

> Why would you cache the entire database though?

I have no ideas where did you got that from.

Post reply on HN