Support for Read Replicas (Postgres, MySQL) or setting Client in read-only mode
See original GitHub issue@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):
- Not natively in Prisma, have actual read/read-write nodes in the DB natively and multiple
datasource
blocks and multiplegenerate
blocks to generate read-only, read-write photon.datasource ReadOnlyDB { provider = "postgresql" url = "<read only DB credentials>" } datasource ReadWriteDB { provider = "postgresql" url = "<read-write DB credentials>" } generator ReadOnlyPhoton { provider = "photonjs" datasource = "ReadOnlyDB" // API is not final } ...
- Natively in Photon with a read only parameter
generator ReadOnlyPhoton { provider = "photonjs" readOnly = true // API is not final }
Other ways are also possible.
Additional context
Issue Analytics
- State:
- Created 4 years ago
- Reactions:73
- Comments:56 (18 by maintainers)
Top Results From Across the Web
Working with read replicas for Amazon RDS for PostgreSQL
PostgreSQL read replicas are read-only. Although a read replica isn't a writeable DB instance, you can promote it to become a standalone RDS...
Read more >Read queries on replicas - Azure SQL Database & SQL ...
Azure SQL provides the ability to use the capacity of read-only replicas for read workloads, called Read Scale-Out.
Read more >AWS RDS Read Replicas - Jayendra's Cloud Certification Blog
Supported for MySQL, PostgreSQL, MariaDB, and Oracle. · Not supported for SQL Server · Cross-Region Read Replicas help to improve · A source...
Read more >Resource: aws_db_instance - hashicorp - Terraform Registry
replica_mode - (Optional) Specifies whether the replica is in either mounted or open-read-only mode. This attribute is only supported by Oracle instances.
Read more >AWS RDS - Cross-Region Read Replicas for MySQL
AWS RDS : Cross-Region Read Replicas for MySQL and Snapshots for PostgreSQL · Migration Between Regions: The replica could be used for the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 read and write.
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.
For me, this is the most simple and intuitive version:
… and Prisma handles the rest.
It would also be very convenient when using AWS Aurora ❤️