Zstandard

Also known as: zstd

On this page 7

Zstandard, usually abbreviated zstd, is a lossless data compression algorithm and file format that combines compression ratios comparable to zlib or better with much higher speed, especially during decompression. In server performance work, it is used to shrink HTTP responses, logs, backups, database pages and network transfers while keeping CPU overhead low.

Zstandard was created by Yann Collet, released as open source in 2016 and standardized for the web in RFC 8878, which defines the zstd content coding for HTTP. Its defining trait is a very wide tuning range: the same format serves real-time compression at hundreds of megabytes per second and slow archival compression that rivals xz.

How Zstandard compresses data

Zstandard follows the classic LZ77 plus entropy coding design. A match finder searches previous data inside a sliding window for repeated sequences and replaces them with references of length and offset. The remaining literals and the match descriptions are then encoded with Huffman coding for literals and Finite State Entropy (FSE), an implementation of tabled asymmetric numeral systems, for the sequence fields.

FSE is a key reason for its speed: it reaches near-arithmetic-coding efficiency while decoding with simple table lookups and few branches. Data is organized in frames containing blocks of up to 128 KB, and each frame can carry a content checksum and the original size. Because the decoder does almost the same work regardless of the compression level, decompression speed stays high even for data compressed at the slowest settings.

Two further features distinguish it from older codecs. Trained dictionaries capture common content from samples, which greatly improves compression of small payloads such as JSON records. Long-distance matching extends the window to hundreds of megabytes, which helps with large backups containing distant duplicates.

Zstandard compression levels and parameters

The compression level is the main control. Levels run from negative “fast” levels through 1 to 22, with level 3 as the default. Levels above 19 are called ultra levels and require much more memory on both sides because of larger windows. Exact throughput depends heavily on hardware and data, so the figures below are indicative ranges for one modern core.

Level rangeCompression speedRelative ratioTypical server use
Negative levelsAbove 500 MB/sLowestReal-time streams, caches
1 to 3About 300-500 MB/sSimilar to gzip -6HTTP responses, logs, file systems
4 to 12About 50-200 MB/sModerately betterNightly backups, packages
13 to 19About 5-40 MB/sHighStatic assets precompressed once
20 to 22Below 5 MB/sHighestLong-term archives
Typical behavior of zstd levels on one CPU core

Other important parameters include the window size (--long or windowLog), the number of worker threads (-T), and the checksum flag. Decompression typically runs at one gigabyte per second or more per core across all levels, which is why compressing once at a high level pays off for data that is read many times.

Zstandard compared with gzip and Brotli

Zstandard competes mainly with Gzip compression (DEFLATE) and Brotli on servers. Gzip is universal but slow for its ratio; Brotli achieves excellent ratios for text with its built-in web dictionary but compresses slowly at high levels. The table summarizes the practical differences.

CodecStrengthWeaknessBrowser support
GzipUniversal compatibilityLower ratio, slower decompressionAll browsers
BrotliBest ratio for static textSlow at high levelsAll modern browsers
ZstandardBest speed-to-ratio balanceNewer HTTP supportChromium-based browsers and Firefox
Zstandard, gzip and Brotli on servers

For dynamic HTTP responses, zstd at low levels often matches Brotli’s ratio at a fraction of the CPU cost, which reduces response time and raises requests per second. For precompressed static assets, Brotli at level 11 remains a strong choice. Outside the browser, in backups, logs, file systems and databases, zstd has largely displaced gzip.

Where Zstandard improves server performance

Zstandard helps wherever bandwidth, disk I/O or storage is the bottleneck and spare CPU exists. The decision table below maps common server scenarios to sensible settings.

ScenarioSuggested settingReason
Dynamic web responsesLevel 3 to 6Low latency, good ratio
Static assetsLevel 19, precompressedCompressed once, served often
Log rotationLevel 3 with multithreadingFast, roughly halves gzip time
Database or file systemLevel 1 to 3Transparent with minimal I/O stall
Backup archivesLevel 10 to 19 with --longFinds distant duplicates
Small JSON messagesTrained dictionarySmall inputs lack context
Choosing zstd settings by scenario

Common integrations include Nginx and Apache modules, Btrfs and ZFS transparent compression, MySQL and PostgreSQL features, Kafka message batches, the Linux kernel and initramfs images, and tar --zstd for archives. In each case the benefit comes from moving fewer bytes through slow resources while the decoder adds little latency.

Limitations and common mistakes with Zstandard

Zstandard is not free of trade-offs, and several configuration errors cancel its advantages. Typical problems include the following.

  • Using high levels for dynamic content: level 19 per request wastes CPU and raises tail latency.
  • Compressing already compressed data: JPEG, video and ZIP files gain nothing and cost CPU.
  • Ignoring memory limits: ultra levels and --long windows need matching decoder memory, which embedded clients may lack.
  • Missing fallback negotiation: clients without zstd support must still receive gzip through Accept-Encoding handling.
  • Losing dictionaries: data compressed with a dictionary cannot be decoded without the same dictionary.
  • Compression and secrets: compressing attacker-influenced input together with secrets enables BREACH-style attacks, as with any codec.

The idea in brief

Zstandard is a way to make data smaller quickly so that servers can store and send it faster. It looks for repeated pieces and writes short notes such as “same as earlier” instead of repeating them.

Its special talent is speed. Packing can be fast or very thorough depending on a dial, while unpacking is always fast. That makes it useful for websites, logs and backups alike.

A practical scenario

An online retailer runs a JSON API behind Nginx that returns product listings averaging 180 KB per response. The servers used gzip at level 6, and under evening peaks the CPU on the web tier reached 85 percent, while median response time rose noticeably. The operations team enabled zstd at level 3 for clients that advertise it and kept gzip as a fallback for others.

After the change, compressed responses were slightly smaller than before and compression CPU time fell by more than half on the measured workload. Peak CPU dropped to about 60 percent, the 95th-percentile response time improved, and the team postponed adding two servers. Nightly log archives were also switched to zstd -T0, which cut rotation time from forty minutes to under ten.