Eric Smith
Eric Smith
DTDrizzle Team
Created by Eric Smith on 5/7/2024 in #help
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
1 replies