Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose replicas as $replica() #21

Merged
merged 2 commits into from
Oct 25, 2023
Merged

Conversation

casey-chow
Copy link
Contributor

To unstall #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 #18 (comment).

@casey-chow casey-chow mentioned this pull request Oct 16, 2023
@janpio janpio requested a review from SevInf October 17, 2023 16:31
@tbell511
Copy link

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
Copy link
Contributor Author

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
Copy link

@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 🙂

.envrc Outdated Show resolved Hide resolved
@SevInf
Copy link
Member

SevInf commented Oct 23, 2023

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
Copy link
Contributor Author

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 SevInf merged commit 122c90a into prisma:main Oct 25, 2023
1 check passed
SevInf added a commit that referenced this pull request Oct 25, 2023
Doc for the feature added in #21.
Since we decided that queryRaw would always go to primary by default,
we are also removing non-working code for routing it to replica instead.
@SevInf
Copy link
Member

SevInf commented Oct 25, 2023

Released in 0.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants