Use Primary DB when conection to read replica is refused. #4433
Replies: 3 comments
|
I encountered this issue as well. I just followed the documentation. and there's no automatic fallback to the primary. When my replica hits its connection limit, it just throws an error. It's not ideal. |
|
@AndriiSherman (sorry to tag you directly 🙇🏼) but can we please have this? atleast a documentation update would be cool |
|
withReplicas is a replica-selection mechanism, not a health-check or automatic failover layer. If the selected replica connection returns ECONNREFUSED, the query rejects; Drizzle does not transparently retry that read against the primary. The callback can be useful for choosing a replica based on application state, but it should not perform a network probe for every query. For libraries such as Better Auth that accept only one db object, the usual options are:
Keep the retry bounded and do not apply it blindly to writes or transactions, because a connection error does not always tell you whether the server received the previous operation. |
Uh oh!
There was an error while loading. Please reload this page.
I am using drizzle with a primary cloud db and a read replica that is co-located with my server. I am doing something like this to set up the connection:
Now, the problem is that when my local db goes down I get an error for read operations. This would be manageable for queries that I make myself since I could make a wraper function that checks for an
ECONNREFUSEDerror when making the query and then switches to the primary. But there's external libraries likebetter-authornext-authto which you can only pass thedbobject.Is there an option for drizzle to detect that the read replica is down and then switch to the primary? Another option I see is that one checks in the callback that decides which db to use if the read replica is still there:
All reactions