Support for Read Replicas (Postgres, MySQL) or setting Client in read-only mode
Problem
Latest update Check this comment below for the Client Extension that enables this functionality! https://github.com/prisma/prisma/issues/172#issuecomment-1718089127 🥳 --- @matthewmueller's update Problem Currently we don't support read-replicas. This is a common need for scaling databases. Solution I agree with @dpetrick's solution below. One thing I would additionally suggest is to provide a `Readonly` interface that you can pass through. This `Readonly` interface would omit the `Create`, `Update`, `Delete` methods. --- > Does prisma2 support the ability to direct queries to master db or read-only replicas based on read/write? This is useful functionality that lots of db drivers support. Hopefully since prisma2 aims to replace the db driver, it would also have this functionality. > > > (User feedback) > > This can be handled in various ways (the list if from the top of my mind): > > 1. Not natively in Prisma, have actual read/read-write nodes in the DB natively and multiple `datasource` blocks and multiple `generate` blocks to generate read-only, read-write photon. > > [code block] > > 2. Natively in Photon with a read only parameter > > [code block] > > Other ways are also possible. Additional context * https://github.com/prisma/prisma/issues/3389
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Support for Read Replicas (Postgres, MySQL) or setting Client in read-only mode
My first intuition on the subject was neither of your options, but the possibility to provide a read-only endpoint directly in the datasource, which would cause Prisma to internally either load balance or direct all read traffic to the read db. Both your options are severely limited in use: - Option 1) requires you to annotate models with a source... and then you suddenly need 2 annotations for
Trust Score
8 verifications
- 1
My first intuition on the subject was neither of your options, but the possibili
My first intuition on the subject was neither of your options, but the possibility to provide a read-only endpoint directly in the datasource, which would cause Prisma to internally either load balance or direct all read traffic to the read db. Both your options are severely limited in use:
- 2
Option 1) requires you to annotate models with a source... and then you suddenly
- Option 1) requires you to annotate models with a source... and then you suddenly need 2 annotations for read and write.
- 3
Option 2) would imply that the whole photon client is just throwing out write qu
- Option 2) would imply that the whole photon client is just throwing out write queries and just allow read queries. Seems odd to me all around, because what's the point of having this when the approach is pretty much a glorified version of creating 2 photon clients and separating traffic on the client side.
- 4
For me, this is the most simple and intuitive version:
[code block] ... and Prisma handles the rest.
Validation
Resolved in prisma/prisma GitHub issue #172. Community reactions: 51 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep