What is lz4

Last updated: April 1, 2026

Quick Answer: LZ4 is a fast, lossless compression algorithm designed for real-time data compression, prioritizing speed over maximum compression ratio, and is widely used in databases and streaming applications.

Key Facts

What is LZ4 Compression

LZ4 is a modern, high-speed lossless compression algorithm created by Yann Collet. Unlike compression algorithms that prioritize maximum file size reduction, LZ4 is specifically designed for speed, making it ideal for scenarios where fast compression and decompression are more important than the smallest possible file size.

Performance Characteristics

LZ4 achieves remarkable performance metrics. Compression speeds typically exceed 300 MB/s, while decompression frequently exceeds 1 GB/s on modern processors. These speeds make LZ4 practical for real-time compression where other algorithms would create bottlenecks. The compression ratio is typically 2:1 to 4:1, which is reasonable though not as aggressive as algorithms like LZMA.

How LZ4 Works

LZ4 uses a sliding window approach similar to LZ77, with a default window size of 64KB. The algorithm searches for matching sequences and replaces them with shorter references. The design emphasizes simplicity and speed—the algorithm avoids expensive operations that would slow decompression, even at the cost of slightly lower compression ratios.

Common Applications

LZ4 has become the compression standard in several important systems. Databases like RocksDB and MongoDB use LZ4 for log compression. Logging frameworks employ LZ4 to reduce I/O overhead. Real-time data streaming systems, network protocols, and in-memory caches benefit from LZ4's exceptional decompression speed. It's also used in frame formats and containerization systems.

Advantages and Use Cases

LZ4's primary advantage is speed—it's one of the fastest compression algorithms available. This makes it ideal for systems where latency matters more than achieving the absolute smallest file size. The algorithm also has excellent cache efficiency and scalability. Disadvantages include lower compression ratios compared to LZMA or ZSTD for certain data types, making it less suitable when storage space is the primary concern.

Related Questions

How does LZ4 compare to GZIP?

LZ4 is significantly faster than GZIP for both compression and decompression, but GZIP typically achieves better compression ratios. Choose LZ4 for speed-critical applications and GZIP when maximum compression matters.

Is LZ4 better than ZSTD?

ZSTD offers better compression ratios than LZ4 and similar speed, making it superior for most use cases. LZ4 is simpler and slightly faster, making it better for extremely time-sensitive applications.

Can LZ4 compress any type of data?

LZ4 can compress any data type but works better on data with repetitive patterns. Random or highly encrypted data compresses poorly with LZ4, as with most compression algorithms.

Sources

  1. Wikipedia - LZ4 CC-BY-SA-4.0
  2. LZ4 GitHub Repository BSD