AI Glossary / MLOps and deployment / Intermediate
Brotli
Definition
Brotli is a general-purpose lossless compression format and algorithm family for representing data in fewer bytes when its patterns permit. It combines references to repeated data, prefix coding, context modeling and a built-in dictionary. Correct decompression reproduces the original input bytes exactly.
What it means
Brotli can compress text and other byte sequences without changing their meaning or intentionally discarding detail. The decoder reconstructs bytes; interpreting those bytes as a document, image or program is a separate step.
The format is specified in RFC 7932. Different encoder settings can trade compression time against output size while producing valid Brotli streams. A smaller result at one setting does not establish the best end-to-end choice for every application.
Brotli is also used as the HTTP content coding named br. That identifies compression applied to a representation, not a new document language. A compressed HTML response remains HTML after decompression.
How it works
The encoder identifies repeated byte sequences and can represent them using a length and backward distance instead of writing every byte again. Literal bytes are used where a reference is unsuitable. Some references can instead identify entries in the format's static dictionary, with defined transformations.
Prefix codes compactly represent the resulting symbols and commands. Context modeling lets the coding arrangement reflect surrounding data rather than assuming every literal occurs in the same circumstances.
The stream is organized into meta-blocks. Their coding descriptions can differ, while references to earlier decoded data remain subject to the stream's window rules. A meta-block boundary therefore does not automatically provide arbitrary independent access.
The decoder follows the specified commands and maintains the required history. The raw stream does not supply a general integrity checksum or total uncompressed-length field. An application needing those properties must obtain them from an appropriate surrounding format or protocol.
Three practical examples
1. Website assets: A server can deliver a Brotli-compressed representation of a text resource to a client that supports it. Correct negotiation and response metadata are part of that delivery.
2. Repeated API data: An application can evaluate compression on representative structured responses. Very small or already compressed payloads may not justify the extra processing.
3. AI data transfer: A team can compress textual datasets for transport, then verify exact recovery before ingestion. Brotli reduces the representation's size; it does not improve labels, remove duplication semantically or train a model.
Think of it this way
Think of packing a document using instructions such as 'copy the earlier passage' and short codes for common pieces. A shared reference book can help describe some material even before it has appeared in the document.
The analogy has limits. Brotli follows precise byte-level rules; it does not paraphrase ideas or decide which sentences are unimportant. A compression error is not acceptable simply because the text still looks approximately readable.
Worked example
Worked example
Consider an invented 200,000-byte text asset. A measured test output is assumed to be 50,000 bytes at one Brotli setting. The size ratio is 200,000/50,000 = 4 to 1, and the reduction is (200,000 - 50,000)/200,000 = 75%.
For 10,000 uncached transfers, the uncompressed payload total would be 2,000,000,000 bytes. The compressed payload total would be 500,000,000 bytes, saving 1,500,000,000 bytes under these assumptions. This excludes protocol overhead and does not assume every page visit downloads the asset again.
Now suppose a more expensive setting produces 48,000 bytes. It saves another 2,000 bytes per transfer, or 20,000,000 bytes across the assumed transfers. Whether that is worthwhile depends on encoding cost, caching and how often the asset changes.
Precompressing a stable asset once differs from recompressing a changing response for every request. These numbers are hypothetical, not a Brotli benchmark. A real decision requires measuring representative inputs, and a complete correctness check confirms that decoded bytes match the originals.
Illustrative case study
Illustrative case study - fictional
A fictional training website evaluates Brotli for its lesson pages and scripts. Its team measures actual transferred bytes through the delivery system rather than only comparing local compressed files.
A test reveals that a cache serves an encoded response without the correct representation metadata in one path. The team fixes the delivery configuration and tests clients with different supported encodings before expanding use.
It also compares dynamic compression cost with precompressed static assets. The fictional project chooses settings from its own measurements; no universal speed or savings claim follows from the codec name.
Common misconceptions and mistakes
- Lossless compression does not mean every input becomes smaller.
- A high compression setting can consume more encoder time without a proportionate reduction in size.
- A Brotli stream is not automatically an archive with filenames, checksums and random access.
- Its static dictionary is part of the format, not a language model that understands the document.
- Already compressed images or media often offer less additional opportunity than repetitive text.
Business use
Brotli can be useful when transfer volume or storage for compressible data matters. Measure the complete workflow: compression time, decoded correctness, transfer size and client compatibility.
For websites, distinguish a local compression result from the bytes actually delivered after caching and negotiation. For data pipelines, document how integrity, expected size and resource limits are handled outside the raw stream when necessary. Avoid assuming that an apparent saving on a large text file predicts the result for small records, encrypted data or specialized media.
People also ask
Is Brotli encryption?
No. A compatible decoder can recover the original bytes. Confidentiality requires a separate protection mechanism.
Does it change image or audio quality?
Brotli itself is lossless for the bytes supplied to it. If those bytes contain a previously lossy image or audio file, decompression restores that file, not the earlier source material.
Is the smallest compressed result always the best setting?
No. Encoding cost, latency, update frequency and reuse can make a slightly larger output more practical.
Check your understanding
A new Brotli setting reduces a frequently changing response by 2% but substantially increases compression time. Has smaller output alone proved it is the better choice?
Answer: No. Evaluate total latency, processing cost and transfer benefit under the real workload, while confirming correct decoding.
Related terms
- Lossless compression
- LZ77
- Huffman coding
- static dictionary
- context modelling
- HTTP content encoding
- compression ratio
Learn next
Compare several settings on representative text, tiny records and already compressed files. Record encode time and output bytes, and verify decompression separately. Then distinguish one-time precompression from per-request work.
More in MLOps and deployment
- Binary Ordered Compression for Unicode - Binary Ordered Compression for Unicode (BOCU) is a Unicode text-compression approach designed to preserve code-point ordering in the encoded byte...
- Bit rate - Bit rate is the number of binary digits, or bits, transferred or represented per unit of time, normally measured in bits per second.
- Bitstream format - A bitstream format is the set of rules that defines how information is arranged and interpreted in a sequence of bits.
- Burrows - Wheeler transform - The Burrows - Wheeler transform (BWT) is a reversible rearrangement of a block of symbols that can make the block easier to compress.
- Canonical Huffman code - A canonical Huffman code is a Huffman-style prefix code whose bit patterns are assigned by a fixed ordering rule once each symbol's code length is known.
- CDR coding - CDR coding is a technique for reducing the memory occupied by Lisp list cells.
Sources
Sources: IETF RFC 7932, Brotli Compressed Data Format: https://www.rfc-editor.org/rfc/rfc7932.html ; official Brotli project: https://github.com/google/brotli . Relevant format, representation and byte-packing descriptions and the project's raw-stream metadata limitation were reviewed. The size comparison and website case are invented illustrations, not reported benchmarks.
Previous: Broadcasting Next: Brown clustering