For most of MySQL’s history, the replica had one apply thread — no matter how parallel the primary’s commit was, the replica replayed it serially. On a primary that runs 10000 transactions per second with multi-core writes, a single-threaded apply means the replica is permanently catching up. Parallel replication breaks that bottleneck. This article is the operator-grade tuning we apply: scheduler choice, worker count, ordering settings, and the metrics that confirm parallelism is actually engaging.
How to verify
The replica’s parallel apply state lives in Performance Schema, in the replication_applier_status_by_worker and replication_applier_status_by_coordinator tables.
mysql -e "SHOW GLOBAL VARIABLES LIKE 'replica_parallel%';"
mysql -e "SHOW GLOBAL VARIABLES LIKE 'replica_preserve_commit_order';"
mysql -e "SELECT * FROM performance_schema.replication_applier_status_by_worker;"
mysql -e "SELECT * FROM performance_schema.replication_applier_status_by_coordinator;"
mysql -e "SHOW REPLICA STATUS\G" | grep -E '(Running|Seconds_Behind)'
The replication_applier_status_by_worker table should show as many Worker_* rows as replica_parallel_workers. If only one is ON, parallel apply is configured but not actually parallel — usually because the workload has no parallel slots to fill.
What’s happening
Two scheduler types exist. DATABASE assigns each transaction to a worker based on the database it touches; transactions in different databases run in parallel, transactions in the same database serialize. Useful only if you have many databases with comparable write rates — rare in practice.
LOGICAL_CLOCK is the production scheduler. The primary marks each transaction with the “last committed” sequence at the time it started preparing. Two transactions whose last-committed marks overlap with another transaction’s commit window can apply in parallel on the replica — they did not see each other’s commits, so they could not have depended on each other. This works even within a single database and is dramatically more effective than DATABASE.
In MySQL 8 with the binlog_transaction_dependency_tracking=WRITESET (or WRITESET_SESSION) variable on the primary, the marking is even tighter: instead of approximating dependencies by commit timing, the primary writes the actual write-set of each transaction into the binlog. The replica can then prove two transactions touched disjoint rows and run them in parallel even when they overlapped on the primary. This is the highest-throughput parallel apply mode and what we configure in our engagements.
replica_preserve_commit_order is the safety belt. With parallel apply, two workers can finish their transactions in a different order than they committed on the primary. Most applications notice — read-your-own-writes consistency on a replica breaks, foreign-key cascades may run before their parent transaction. With replica_preserve_commit_order=ON, workers commit in the original order at the cost of some throughput; with it off, they commit as soon as they finish, in whatever order. We default to ON.
The procedure
-
On the primary, enable writeset-based dependency tracking. This is the variable that lets the replica realize how parallel the workload actually was.
[mysqld] binlog_format = ROW binlog_transaction_dependency_tracking = WRITESET transaction_write_set_extraction = XXHASH64 binlog_transaction_dependency_history_size = 25000 -
On the replica, configure parallel apply with logical-clock scheduling and commit-order preservation.
[mysqld] replica_parallel_workers = 16 replica_parallel_type = LOGICAL_CLOCK replica_preserve_commit_order = ON replica_pending_jobs_size_max = 128MThe worker count is workload-dependent. We start at the CPU core count, watch utilization, and tune. Sixteen is a reasonable starting point on a modern 16-core replica.
-
Restart the replica’s SQL thread to apply.
STOP REPLICA SQL_THREAD; START REPLICA SQL_THREAD; SHOW REPLICA STATUS\G -
Confirm workers are engaging. The
replication_applier_status_by_workertable is the truth.SELECT WORKER_ID, THREAD_ID, SERVICE_STATE, LAST_APPLIED_TRANSACTION FROM performance_schema.replication_applier_status_by_worker ORDER BY WORKER_ID;Each worker should be
ONand theLAST_APPLIED_TRANSACTIONshould advance across many workers during a burst, not just one. -
Measure the apply rate. The primary’s
Innodb_rows_insertedrate vs the replica’sHandler_writerate gives a rough ratio; if the replica is keeping up, the ratio is near 1.mysql -h primary -e "SHOW GLOBAL STATUS LIKE 'Innodb_rows_inserted';" mysql -h replica -e "SHOW GLOBAL STATUS LIKE 'Handler_write';" -
Watch for the worker bottleneck. If only a few workers are busy and the rest are idle, the workload has insufficient parallelism for the chosen worker count —
binlog_transaction_dependency_tracking=COMMIT_ORDERis the older default and yields less parallelism thanWRITESET. -
If lag persists despite parallel apply, the bottleneck is probably elsewhere — disk IOPS on the replica, a slow query the replica must serialize behind, or a missing index that makes the apply read amplification dominate.
Common pitfalls
replica_preserve_commit_order=OFFfor “speed” — application reads of recent writes break in subtle ways. Cascading foreign keys can hit the child before the parent. Keep itONunless you have measured it as the bottleneck and accept the application impact.- Worker count higher than CPU cores — context switching dominates; throughput drops. Two to four times the core count is the upper end before diminishing returns.
replica_parallel_type=DATABASEon a single-database workload — every transaction goes to the same worker; you have parallel apply enabled and serial apply running.binlog_transaction_dependency_tracking=COMMIT_ORDERon the primary — older default, less parallelism on the replica. The newerWRITESETmode requirestransaction_write_set_extraction=XXHASH64, which must be set together.- Mixing servers with different parallel-apply versions — Group Replication and InnoDB Cluster require every member to have compatible settings, especially around
replica_preserve_commit_order.
Parallel replication is what makes the difference between a replica that keeps up at 100k transactions per second and one that falls hours behind during a burst. In the engagements we run, the writeset dependency tracking is on, the worker count is sized for the replica’s hardware, and the replication_applier_status_by_worker view is in our observability stack so a worker that goes idle while others are busy raises an eyebrow. For the broader pattern of operating MySQL replication topologies, see /en/knowledge-base/mysql-replication-tuning-async/.