Drizzle / PlanetScale : (How to properly handle replicas)

Hey all, I'm using NextJS 14 with Server Actions, Vercel, Clerk for auth, Drizzle and PlanetScale. There are users in USA/Canada and Asia. I want to make it so the users in Asia have just as fast an experience as users from USA/Canada. PlanetScale has global replicas, where if I understand it correctly, I can have a main DB, then replicas wherever I want: https://planetscale.com/blog/introducing-global-replica-credentials What is currently set up is a main DB in Oregon, USA with a read-only replica in Singapore. The only issue is writes will always have to be done in the main DB in Oregon, but that shouldn't be a problem as the application is more read heavy. I can see that Drizzle has a way to handle read replicas via withReplicas: https://orm.drizzle.team/docs/read-replicas Given I'm using NextJS. Would I be able to, within withReplicas, get the location of the request and use that to choose which DB connection to use? Is that even an approach that makes sense or is there something more clever I can do? I'm also a little concerned with how fast replication happens after writing to the main DB. Any help is appreciated, Thank you
Introducing global replica credentials — PlanetScale
With global replica credentials, you can now automatically route reads to the closest replica.
Drizzle ORM - Read Replicas
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server