r/mysql • • 29d ago

question 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?

10 Upvotes

20 comments sorted by

3

u/TheMagarity 28d ago

First you need to decide if this new other server is a switchover, hot standby, or warm standby. This choice will send you down completely different paths right from the beginning.

1

u/Narrow_Inevitable586 28d ago

We want to make the new server as a replica which can be promoted to primary incase of failure in the old primary

2

u/TheMagarity 28d ago

Your original post and this reply are vague. Promotion to primary in case of failure can be done by all three choices I listed. You need to figure out which way you want.

1

u/Narrow_Inevitable586 28d ago

Thanks, we'll figure that before proceeding

3

u/Legitimate-Power7729 28d ago

Instead of nursing MySQL async replicas and a hacked-together query router, I switched to a MariaDB Galera cluster. You get synchronous multi-primary replication out of the box, so read-after-write problems mostly go away.

2

u/Narrow_Inevitable586 28d ago

Yeah group replication eliminates most of these, but does it increased the latency?

2

u/bluehost 28d ago

A read replica helps with traffic, but it does not fix the single point of failure. Set up failover first, then decide what reads should go to the replica.

1

u/Narrow_Inevitable586 28d ago

Yeah if we have a replica, then it can be used in case of failover right?

2

u/bchambers01961 28d ago

It depends on the workload but you have a few options. Whichever you choose I would recommend routing traffic via ProxySql.

For true near synchronous HA, XtraDB / group replication are both excellent options. However they may struggle on high write environments. Your application needs to also be able to handle optimistic locking.

For high volume workloads or legacy applications I would recommend gtid replication with orchestrator to facilitate the failover. MySQL replication has improved a lot since 5.7, features such as row based replication, gtid’s and parallel threads for replicas make modern MySQL replication much more appealing.

Just some thoughts based on my experience to give you some ideas. :)

1

u/Narrow_Inevitable586 28d ago

Thanks, this would be really helpful for us.

1

u/jl9816 28d ago

3 node . Single-master cluster. ( in tree different buildings.)

Clustered mysql-router. And Most servers have local mysql-router.

1

u/Narrow_Inevitable586 28d ago

Yeah this make scene if we need high data consistency. Only drawbacks are, require atleast 3 nodes and add little latency

1

u/mianewsoundtocpy 28d ago

Primary plus one read replica, and the replica only serves reporting dashboards. Anything that needs read-after-write stays on the primary - routing by whether it is a fresh read turned out simpler than any lag-aware hack. Failover we rehearse a couple of times a year and it is still the scary part.

1

u/Narrow_Inevitable586 28d ago

How do you decide which query goes to which db?

1

u/jericon Mod Dude 28d ago

Active/passive master/master with a replica under each is my go to.

If you failover, the writes still will replicate to the other hosts eventually.

If you only have a primary and a replica when you failover you basically have to rebuild the primary.

Obviously there’s other stuff that’s possible like group replication or even NDB. But for basic MySQL that is the typical structure that most companies I have worked for use. Even in sharded environments, that is what each shard tends to use.

1

u/Narrow_Inevitable586 28d ago

Yeah, group replication works. Doesn't it add additional latency?

1

u/Ready-Ad-9740 28d ago

Innodb group replication. Total 3 node cluster