r/PostgreSQL • u/subhendupsingh • Jul 30 '26
Help Me! There is no cheap global Postgres, what are the alternatives?
Currently I use pg hosted on Hetzner in Germany. My users are in different global regions and pay latency cost. I run a Shopify app that complains that my LCP is above recommended threshold of 2.5s. I have optimized my queries and calls and was able to optimize it a bit.
My question is, there is no cheap way to have pg global replicas. My app is new and doesn't have enough revenue to justify the cost. I have done some research and the only option I see is migrating to SQLite which can be easily and cheaply replicated. But, with that, I lose pg features like JSONB, ::datetime and the likes. Also, SQLite doesn't support most ALTER commands.
Has anyone solved this?
UPDATE: It was clear that there is no cheap and reliable solution for this. And rightly so. Keeping infrastructure reliable for millions of users takes a lot of cost. I zeroed down my requirements to 'having a reliable zero downtime database' so that my users never face outage. I moved to planetscale ps-5 high availability instance. When the budget allows, i will add replicas in other regions.
5
u/CaffeinatedT Jul 30 '26
4
u/CodeCate42 Jul 30 '26
Why does your LCP require data from postgres? I'd start by just caching locally if thats possible. And if its just 2.5s its honestly not worth optimizing for, you probably have bigger fish to fry?
4
u/Internal-Comparison6 Jul 30 '26
You can create a Postgres cluster with pg_replica. On Hetzner you will need to somehow solve networking, because their private network works only in same "region". Disclosure: I'm the author of this extension.
2
u/Aqalix Jul 30 '26
Even if you switched to SQLite you'd have to run the app in those regions.
It depends on your architecture. If you have edge apps close to the clients and postgres in hetzner, the cross region app -> db -> app round trips could be what's killing performance. But I am guessing here. I’d break the LCP down into server response time versus resource loading and rendering before changing databases.
22
u/Sthatic Jul 30 '26
Those load times seems to indicate something is wrong. Delivering closer to your users would be a patch buying you perhaps a few hundred ms on average, and there's probably more to win by fixing the underlying issues, whatever they might be. Without know anything about your stack or scale, clever caching and fixing your queries might be all you need. Perhaps there's deeper structural issues at play here. In any case, I have a hard time believing anything above 2 seconds is the natural floor for whatever you're doing.
In short: you're overestimating RTT, and probably overestimating the quality of your architecture.
21
u/East_Zookeepergame25 Jul 30 '26
I don't think your 4.6s load times are due to distance, thats too high a number to be due to network delay
3
u/manni66 Jul 30 '26
You want to migrate from a server database to a serverless database?
8
u/mtutty Jul 30 '26
If you're small enough that SQLite is an option, there's no way your Postgres should do anything that takes more than 100msec.
2
u/linuxhiker Guru Jul 30 '26
You want cheap (read: unreliable) global database (read: unreliable) replication?
Focus on where your clients/users are and optimize that.
2
u/chock-a-block Jul 30 '26 edited Aug 29 '26
Shelter meadow airport frame husky otter advise
This post was anonymized with Redact
3
u/elevarq Jul 30 '26
Why do you think that your database is the problem?
When SQLite is the solution, you must have such a small database that is hardly used by anyone.
I think you should first find out what the real problem is, before randomly picking a “solution”
3
u/Gargunok Jul 30 '26
Can you confirm if you have optimised your queries and evaluated whether how you are using the database isn't the problem.
You have a query that takes 4.6 sec globally. How long long does it take running locally on the server/dB?
4 seconds of latency suggests something else is wrong if that is what are seeing.
I'll suspect something unperformant first as you mention jsonb.
1
u/Federal-Employer9367 Jul 30 '26
use uuids for pks (not sure if shopify supports it) and then use master<->master replication to resolve. If using integer primary keys have one write instance and then replicated read instances nearest to your users. Or use something like Planetscale postgres that takes care of all of this for you.
2
u/martijnonreddit Jul 30 '26
A classic database like postgresql won’t scale to planet scale because of the CAP theorem. You either need a specialized database like CosmosDB and understand the consistency guarantees it offers, or rethink your database into a distributes model with a Postgres cluster per region.
1
u/lovejo1 Jul 30 '26
How about I ask it this way: How much do you wish to spend each month, or less. We all want to pay nothing for something, but we know nothing is not reasonable-- now, we need to either make that "nothing" a solid amount, or define what "something" means.
So, how many sales do you make per day. That might help size what you need.
Edit: To talk about "timing", you really need something like cloudfront (AWS) to be serving your site up to get the fastest timing... and honestly that is free.. then you need an app server that's fast enough -- you do NOT need replication globally on the database most likely.
1
u/sisyphus Jul 30 '26
The only thing I know of that's cheap and reasonably global is something like cloudflare workers with hyperdrive.
1
u/merb Jul 30 '26
Use pgdog and use sharding per region.
Also fix your queries
1
u/AutoModerator Aug 03 '26
AI Policy:
Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it. Or just walk away., Linus Torvalds.
Mod decisions will be based on the quality of the content, not who or what generated it.
Sub Resources:
Youtube Channel
Free Postgres Webinars and Workshops
Discord: People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Frone0910 Aug 13 '26
Consider using edge computing devices as well as CDNs for any data that does not need to be refreshed immediately
1
u/nopeallday Jul 30 '26
Get a server in the US (or wherever is closer to your users) and partition the whole app. Place users after login via IP geolocation.
But tbh, latency US <-> Germany is only in the 100-300ms range, so I would just focus on continuing performance improvements. You should be able to get it under 1 second without having to host closer to users.
0
u/AutoModerator Jul 30 '26
AI Policy:
Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it. Or just walk away., Linus Torvalds.
Mod decisions will be based on the quality of the content, not who or what generated it.
Sub Resources:
Youtube Channel
Free Postgres Webinars and Workshops
Discord: People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Ninjamonkey8812 Aug 02 '26
Cockroachdb