WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

MySQL · Expert · question 68 of 100

How do you configure and use MySQL’s semi-synchronous replication to achieve a balance between data durability and performance?

📕 Buy this interview preparation book: 100 MySQL questions & answers — PDF + EPUB for $5

MySQL’s semi-synchronous replication feature ensures that a transaction is committed to the upstream master and at least one replica before the user is notified that a write operation has succeeded, providing a balance between data durability and performance.

To configure MySQL’s semi-synchronous replication, the following steps need to be taken:

1. Enable semi-synchronous replication on the master server by setting the "rpl_semi_sync_master_enabled" variable to true:

mysql> SET GLOBAL rpl_semi_sync_master_enabled = 1;

2. Enable semi-synchronous replication on the replica server(s) by setting the "rpl_semi_sync_slave_enabled" variable to true:

mysql> SET GLOBAL rpl_semi_sync_slave_enabled = 1;

3. Set the "rpl_semi_sync_master_wait_for_slave_count" variable to the number of replicas you want to wait for before considering the write operation successful. For instance, to wait for one replica, set the value to 1:

mysql> SET GLOBAL rpl_semi_sync_master_wait_for_slave_count = 1;

4. Start the MySQL server on the replica server(s).

After configuring the semi-synchronous replication feature, write operations will now behave differently. When a client issues a write operation, the following will happen:

1. The master server receives the write operation and immediately sends an acknowledgement to the client that the write operation succeeded.

2. The master server waits for at least one replica to acknowledge receipt of the write operation by sending a "commit" message back to the master.

3. Once the master server receives an acknowledgement from at least one replica, the transaction is considered complete.

By waiting for a replica to acknowledge receipt of the write operation before considering it successful, we achieve a balance between data durability and performance. However, this comes at the cost of increased latency, as the client has to wait for the master to receive an acknowledgement from at least one replica.

It’s important to note that semi-synchronous replication doesn’t guarantee that the data is fully replicated to all replicas at the time of acknowledgement. There is still some data loss risk if the master server crashes before the write operation is fully propagated to all replicas.

In conclusion, MySQL’s semi-synchronous replication is a useful feature for achieving a balance between data durability and performance. By configuring it correctly, you can increase the durability of your data without sacrificing too much performance.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic MySQL interview — then scores it.
📞 Practice MySQL — free 15 min
📕 Buy this interview preparation book: 100 MySQL questions & answers — PDF + EPUB for $5

All 100 MySQL questions · All topics