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 🎄🎁

  • lemmyvore@feddit.nl
    link
    fedilink
    English
    arrow-up
    10
    ·
    edit-2
    11 months ago

    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.

  • key@lemmy.keychat.org
    link
    fedilink
    English
    arrow-up
    5
    ·
    11 months ago

    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.

    • Mateleo@lemmy.dbzer0.comOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      11 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.

  • vsis@feddit.cl
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    11 months ago

    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.

    • Mateleo@lemmy.dbzer0.comOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      11 months ago

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

      • Atemu@lemmy.ml
        link
        fedilink
        English
        arrow-up
        1
        ·
        11 months ago

        I’d cross that bridge when I get there.

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

  • vzq@lemmy.blahaj.zone
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    16
    ·
    11 months ago

    Nothing here is self hosted. You are running VPS (!!) and want to expand to other continents where presumably you don’t live.

    Go bother someone in a random web hosting forum.

    • IsoKiero@sopuli.xyz
      link
      fedilink
      English
      arrow-up
      5
      ·
      11 months ago

      While I agree with @[email protected], this isn’t strictly speaking on-topic for this community, that kind of knee-jerk response is very much out of the topic as well. The first community rule is to be civil and in general I, perhaps optimistically, would like that conversation over fediverse in global would be civil, or at least well argumented, a bit like it used to be (more or less, YMMV) back in the usenet days.

      And on the topic of self-hosting, that’s a line drawn in the water. I run various of things by myself (postfix+dovecot, LAMP, bitwarden, seafile, nextcloud…) on a rented servers running linux+kvm. And I get money by doing that, it’s a very much a business case, so I’m a bit reluctant to ask questions about the setup I have in here as I think it wouldn’t be fair to ask for advice from hobbyists in a project where money is directly involved. But for me personally that setup checks both sides of things. I get money by doing it, but at the same time I personally can get out of the walled gardens like M365 or Gsuite.

      TL;DR: There’s no need to be rude, you can choose to politely point people in the right direction.

      • Mateleo@lemmy.dbzer0.comOP
        link
        fedilink
        English
        arrow-up
        1
        ·
        11 months ago

        I wasn’t quick enough to answer @vsq, but I’d really like to know, as a false beginner, isn’t renting a VPS server considered as selfhosting? Even if I have all my services on it (Jellyfin, n8n, Immich, TeamCity etc).