this post was submitted on 23 Dec 2023
15 points (94.1% liked)

Selfhosted

40133 readers
1015 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS
15
Scale to other countries (lemmy.dbzer0.com)
submitted 10 months ago* (last edited 10 months ago) by [email protected] to c/[email protected]
 

Hello everyone !
I have a node app and a PostgreSQL DB in VPS using Docker, with Coolify as a CI/CD, nothing too fancy, you might say.

My question is the following.
I have a lot of read/write on my DB and even the lowest increase in DB latency can have an impact on my users' experience. As my VPS is in France, what could be the best/easiest (selfhosted?) option to solve this problem in other regions (North America, Asia...) ?

Thks in advance πŸŽ„πŸŽ

all 17 comments
sorted by: hot top controversial new old
[–] [email protected] 11 points 10 months ago* (last edited 10 months ago) (2 children)

Caching and/or DB hosted in a region closer to your users, or perhaps even in their browsers (if the data is not sensitive).

Naturally, if you use secondary DBs you will have to deal with data replication.

Is hitting a real RDBMS absolutely necessary? Consider producing precomputed data sets which can be cached as JSON or with other non-dynamic, storage-only methods. A distributed CDN can be much cheaper than a VPS.

Also consider if Postgres is really your best option. You could use various other database engines that can optimize certain factors: some could be cheaper, or make replication easier etc.

For example (just one example out of many, may not even be applicable to you) using CouchDB on server and PouchDB on browser would make data replication and propagation extremely easy, and it's also a very efficient and scalable query engine.

[–] [email protected] 3 points 10 months ago

I've never used it, but I believe cockroachdb is also an option for multi-region replication.

[–] [email protected] 2 points 10 months ago

I'll check it out, I'll learn more about CouchDB. Thks ;)

[–] [email protected] 5 points 10 months ago (1 children)

Your app and DB should be deployed together in the same datacenter to minimize latency between app and DB. Nothing should be hitting your DB besides your app and any etl tools if applicable. So latency to your DB shouldn't be an issue.

If you need to add redundancy with a deployment in another region you should consider having separate environments between regions with totally separate data which allows you to better manage data protection/export regulations appropriately.

If that doesn't work you'll need a multi region database, a vendor with support for that such as aws rds would be the sanest method but you can always hack it yourself.

There's other options but those require an architecture designed to be heavily distributed and that depends a lot on the nature of your application and you'd ideally hire an architect experienced in such deployments.

[–] [email protected] 1 points 10 months ago

My app and DB are on the same server, even more the same Docker Network. Environments separated by region seem to be the best solution for my use case. I hadn't thought of that at all, thank you very much.

[–] [email protected] 4 points 10 months ago* (last edited 10 months ago) (1 children)

You may have one psql server per region and then use Bucardo to synchronize them.

I've never done this in production, so take my advice with a grain of salt.

[–] [email protected] 1 points 10 months ago

I'll make a note of that, thanks!

[–] [email protected] 2 points 10 months ago (1 children)

Who are your users? Where are they located?

[–] [email protected] 1 points 10 months ago (1 children)

France 100%, so for the moment it's not a problem at all. But I was thinking about for the future.

[–] [email protected] 1 points 10 months ago

I'd cross that bridge when I get there.

Are you expecting to have users in far away countries any time soon?