Hello, I didn’t read the full thread but this might give you some ideas.
We have a similar setup (Node - Nestjs - Prisma)
And what we do to access replicas (and avoid the magic with the fly-replay header), is we make 2 instances. 1 for write (always connects to our leading db) and 1 for read (connects to the current replica and if it’s not present, then it just falls back to the leading db).
This involves some code changes though, because you always need to specify which instance you want to use, this should be straightforward. I recommend wrapping these 2 instances into 1 class/object so you can just do databaseService.read.table.readingAction or databaseService.write.table.writingAction.
Hope it helps!
Also, here is a little utility to parse the current replica URL. (typescript)
private getRegionalDbUrl(
dbUrl: string,
region: string,
): { root: string; replica: string } {
const parts = dbUrl.split('@');
return {
replica: `${parts[0]}@${region}.${parts[1]}`.replace('5432', '5433'),
root: dbUrl,
};
}