Databases 6 min read

MySQL Binlog Transaction Compression with ZSTD (MySQL 8.0.20)

The article explains MySQL 8.0.20's binlog transaction compression feature using the ZSTD algorithm, describes its internal implementation, outlines usage steps, presents performance test results, and lists important considerations for deploying compression in production environments.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
MySQL Binlog Transaction Compression with ZSTD (MySQL 8.0.20)

MySQL introduced binary log (binlog) transaction compression in version 8.0.20, using the ZSTD algorithm to reduce the disk space occupied by binlog files and to lower replication bandwidth consumption.

Feature description – When enabled, each transaction is compressed as a unit and written to the binlog. The compressed payload is transmitted to replicas or clients (e.g., mysqlbinlog ) in its compressed form.

Implementation details

Compression is performed per transaction using ZSTD.

New class Transaction_payload_event (derived from Binary_log_event ) stores the compressed payload, its size, compression type, and uncompressed size.

New enum binary_log::transaction::compression::type defines NONE (no compression) and ZSTD (ZSTD compression).

The mysqlbinlog tool decodes and decompresses the payload, printing the algorithm, transaction format, compressed size and original size as comments.

Replicas receive the Transaction_payload_event , write it unchanged to the relay log, and the SQL thread handles decompression during replay.

Important notes

Compression works only for transactional engines and ROW‑based binlog format.

Only ZSTD is supported today, but the design allows future algorithms (e.g., zlib, lz4).

Compression is performed in parallel before the binlog is flushed to disk.

CPU and memory are consumed during compression; if the bottleneck is local processing power, compression may increase replication lag.

Feature testing

Environment: MySQL 8.0.20, one‑master‑one‑slave semi‑synchronous setup.

Steps:

Enable compression: set binlog_transaction_compression=on;

Set compression level (default 3, example level 10): set binlog_transaction_compression_level_zstd=10;

Results:

Binlog size reduced from ~300 MB to ~150 MB (≈50 % compression).

Under limited network bandwidth, compressed binlog improved replication TPS (from 183 queries/s to 203 queries/s) and slightly increased transaction rate.

Conclusion

Enabling binlog transaction compression with ZSTD at a high compression level can halve binlog storage requirements and mitigate network‑induced replication latency, while maintaining or slightly improving overall throughput.

performanceDatabaseMySQLbinlogReplicationZSTDcompression
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.