Support separate DB endpoint for read and write operations
Alexander
TL;DR;
Add support for specifying separate read-write and read-only database endpoint when configuring strapi instance.
Details
Modern web apps often deployed on cloud platforms like AWS or GCP or Azure.
These platform offers very powerful Managed Database Services like RDS, Aurora (on AWS) or CloudSQL (Google cloud).
These services are built to scale and offer separate database replicas for read and write operations to help distributing the load on the Database.
Here: (https://cloud.google.com/sql/docs/postgres/replication/create-replica) and here (https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html)
Currently, Strapi only supports specifying a single DB endpoint that is used for all operations.
This request is to add support for separate endpoints
for write operations and one or many endpoints (could be round-robin balanced under the hood) for read-only operations.Thomas Obernberger
We are running Strapi 5 with MariaDB Galera and MaxScale and have experienced data inconsistencies caused by small delays between database nodes. Strapi sometimes writes data and immediately reads it again. If that read is routed to another node before the new data is available, Strapi receives stale content and may continue processing it. We have seen required component data disappear after saving.
Supporting separate read and write endpoints and keeping reads after a write on the writer would help prevent these consistency issues.
Derrick Mehaffy
Thomas Obernberger
This is a common pattern we see on the Strapi support team, we would recommend setting the casual read setting of maxscale to either local or session in your maxscale config like
causal_reads = local
this allows maxscale to track the replication after a write action and instead forward the read request to the write node.
You can see the MariaDB/Maxscale guide here: https://mariadb.com/docs/maxscale/maxscale-use-cases/readwrite-split-router-usage/ensuring-causal-consistency-with-maxscales-readwrite-split-router
Marco Autiero
Merged in a post:
Separate Read and Write Databases?
D
David
is it possible to have a separate active and passive databases with same data synced in between?
Active database - to be used by the primary website with huge traffic
Passive database - to be used for APIs and 3rd party uses
C
Christian Probst
We are using CloudNativePG Operator to run our Postgres Database on k8s. It deployes a primary and n standby Pods. One Feature is a read-only DB k8s-Service for round-robin usage of all Instances. Unfortunately STRAPI writes data to strapi_core_store_settings at Startup, which is not possible through the read-only Service. So +1 for this feature request.
Niklas Funke
In case of mysql you can use proxySQL (https://github.com/sysown/proxysql) or something similar to achieve read/write splitting. So no need for a build-in solution.
S
Samuel Hodges
This would be a super handy feature for projects of scale
H
Hi
Could you not just point it to the write enabled instance(s) of your database cluster?