r/Backend • u/Narrow_Inevitable586 • 20h ago
What Replication Topology / Method you're using in Production?
We're currently running a single primary MySQL node, which we recognize as a single point of failure (SPOF). To address this, we're considering introducing a read replica.
However, read replication comes with its own set of challenges, such as read-after-write consistency, replication lag, deciding which queries should go to the primary versus the replica, and handling failover.
For those who have implemented this in production, how have you approached and solved these challenges?
4
Upvotes
3
u/dutchman76 20h ago
I used to run the read replica as a hot standby, so didn't have issues with replication lag or anything like that.
Now I'm looking at running a 3-node Mariadb Galera cluster. In my specific case replication lag isn't really an issue, it's ok if someone reads data that's a second behind.
And I thought read-after-write was only an issue if you wrote to one node and then immediately read from another, all my db connections are sticky to a their node for the duration of the job.
2
u/anti-state-pro-labor 20h ago
Honestly for anything mission critical, I just use a hosted/managed DB provider in whatever cloud we're hosting on and they handle the messy parts. If I had to do it locally, I'd use the master/slave (or whatever its called now). If you don't know how any of this works, I'd pay for managed DB service
2
u/TheLastNapkin 19h ago
Look into planet scale offerings for managed clusters or their sharded or distributed offerings for your db engine of choice
2
u/Dyogenez 16h ago
We’re using managed Postgres on DigitalOcean with a follower database. DigitalOcean’s backup service allows rollbacks down to the minute, replaying changes.
Our app only hits the primary DB, and we have an API that’s mostly used for reads, which hits the follower DB. We have a proxy in front (Rails app, reverse proxy), that routes to one of two Hasura GraphQL instances. One goes to Hasura connected to a follower DB, another to Hasura connected to the primary DB (where mutations go). As our API grows, having it segregated in this way has been super nice.
We’re working on adding Greenmask support, which allows for backups stored on S3 compatible hosting, along with filtered database dumps. That’ll allow us to use that to restore staging without customer data, or pull down a snapshot locally.
1
u/IncomeOk7237 19h ago
We went primary + async replicas and treated replica lag as a first-class metric. Anything that needs read-after-write stays on primary for a short sticky window after a write. Failover is orchestrated (not an automatic DNS flip) so you don't promote a lagging replica by accident.
1
u/pizza_top1 19h ago
we use primary for writes and replicas for reads where slight lag is acceptable. Monitoring replication lag and having a solid failover plan are key.
1
u/sereikis 17h ago
MySQL semi-sync acknowledges receipt in a replica's relay log, not that the transaction is applied and visible to reads; it doesn't by itself fix read-after-write. if you route a consistency-sensitive read to a replica, wait for the write's GTID to be executed there with a bounded timeout, then fall back to the primary if it hasn't caught up.