Multi region database guide

@pier Hmm … yes if your request was going to the AMS vm or the LAX vm was actually connecting to the AMS database, that would explain slowness. As for how to see which database vm the app’s vm is actually using for a read (for writes, you know of course!) I’m not sure :thinking:. I don’t know if the logs for the database (after all, a database on Fly is just another app behind the scenes - you can even clone their repo and make your own version of it … at least you could with v1, not sure if that’s the case with the v2) show.

I was just looking how I revealed debugging info when trying using Planetscale’s read replicas (this time with an Express app, also Node, and since they use MySQL-only, with the mysql2 client). The same idea, connecting to the closest one, except instead of using Fly’s internal magic to decide which is the closest one, here it does some logic Ignore that though - you can see here I made a read and write route, and after doing a query they return the region they were served from:

The Fly region being got from an environment variable that Fly apps provide you with at run-time:

The PRIMARY_REGION is manually provided in the fly.toml, as of course you know the region your primary database is in.

Here I returned JSON however you could return those region values in headers instead.

1 Like