prisma / extension-read-replicas

Prisma Client Extension to add read replica support to your Prisma Client
Apache License 2.0
104 stars 7 forks source link

Expose replicas as $replica() #21

Closed casey-chow closed 1 year ago

casey-chow commented 1 year ago

To unstall https://github.com/prisma/extension-read-replicas/pull/18, I'm setting up a $replica() client-level call that forces use of a randomly-selected replica. This allows maximal developer control without sacrificing clarity for now, as suggested in https://github.com/prisma/extension-read-replicas/pull/18#issuecomment-1741314933.

tbell511 commented 1 year ago

Does this change the default behavior where for example, prisma.user.findMany() would use the primary writer/read DB?

But prisma.$replica().user.findMany() would then use a reader instance?

If so, then great! That makes way more sense to me than having the default be reader instances.

casey-chow commented 1 year ago

Does this change the default behavior where for example, prisma.user.findMany() would use the primary writer/read DB? But prisma.$replica().user.findMany() would then use a reader instance?

No, it does not. This only allows the developer to control when to use a replica, especially when a query would otherwise hit the primary. The key use case is with $queryRaw which currently hits the primary but I may want to hit a replica instead.

If so, then great! That makes way more sense to me than having the default be reader instances.

How so? The point of read replicas are to offload reads from the primary database instance, so changing this behavior to hit the primary by default largely defeats the purpose of having read replicas.

tbell511 commented 1 year ago

@casey-chow

How so? The point of read replicas are to offload reads from the primary database instance, so changing this behavior to hit the primary by default largely defeats the purpose of having read replicas.

Great point 🙂

SevInf commented 1 year ago

Overall this looks good. I've left one question. After it is clarified, this is ready to be merged. Sorry it took longer to get to the review and thanks a lot for sending in the patch.

casey-chow commented 1 year ago

Overall this looks good. I've left one question. After it is clarified, this is ready to be merged. Sorry it took longer to get to the review and thanks a lot for sending in the patch.

Thanks @SevInf! I've made the fix, ptal.

SevInf commented 1 year ago

Released in 0.3.0