A system-design interview can turn on a deceptively small follow-up: “Could we compress it?” The proposed change saves network or storage bytes, but introduces CPU work, buffering, new decoder dependencies, and another way for hostile input to consume resources. Senior and staff engineers need to explain where the saving appears and who pays for it.
Use a document-export service as a running practice problem. Customers create exports, download them repeatedly, and sometimes retrieve a small portion. Some exports contain sensitive customer data. The goal is to choose a representation that remains readable, affordable, and bounded under failure. The scenarios and practice rubric below are illustrative preparation tools, not an employer's scoring system.
1. Identify the bottleneck before choosing a codec
Ask whether the service is constrained by network throughput, storage capacity, compression CPU, decoder memory, or time to first byte. Establish the workload: typical and largest export sizes, creation rate, downloads per export, retention, and client capabilities. Distinguish a public static download from an authenticated response assembled for each request. Reusing one compressed artifact can amortize encoding work; recompressing every response cannot.
Define the objective in observable terms. For this exercise, aim to reduce transferred bytes while preserving a download latency target and a fixed worker-memory budget. State that compression is lossless: decoding must reproduce the intended byte sequence. If the application instead accepts approximate numeric values or resized images, that is a separate product contract requiring explicit agreement.
The Zstandard project's benchmark documentation names its hardware, compiler, corpus, and algorithm settings. Treat that specificity as a model for your own evidence. A published throughput result does not describe your production JSON, CPU architecture, concurrency, or network. Compare candidate settings on representative data and report both compression and decompression costs.
2. Make the latency and CPU arithmetic explicit
Illustrative calculation: suppose an export is 10 MB, compresses to 4 MB, and travels over a link delivering 20 MB per second. Ignoring protocol overhead, transfer time drops from 0.50 seconds to 0.20 seconds. If encoding takes 0.08 seconds and decoding takes 0.02 seconds, a sequential model predicts 0.30 seconds rather than 0.50. Those are invented inputs for reasoning, not measured codec results.
Then challenge the model. Streaming can overlap encoding, transmission, and decoding; buffering a full export delays the first byte. A cached compressed export removes encoding from subsequent requests, while a CPU-saturated encoder adds queueing delay. A faster network shrinks the byte-saving benefit. State what runs sequentially and what can overlap before adding stage times.
Turn per-request work into a capacity budget
With the same illustrative 0.08 CPU-seconds of encoding work and 100 new exports per second, encoding alone consumes eight CPU-seconds each second: eight fully utilized core equivalents before overhead or headroom. That is a throughput estimate, not a safe provisioning recommendation. Add measured queue latency, worker concurrency, cancellation, and room for bursts before selecting capacity.
A useful benchmark matrix varies payload size, repetition, codec level, and concurrency. Include tiny records, already compressed files, and unusually large exports. Track encoded size, CPU time, peak memory, first-byte latency, and completion latency. Keep a no-compression baseline. The decision should survive a less favorable data mix rather than depend on one especially repetitive sample.
3. Choose the compression unit around the read path
A single compressed stream is convenient for a complete download. A client seeking a small logical record needs an independent decoding boundary or must reconstruct earlier state. For the export service, propose independently decodable chunks plus an index if partial reads are an actual requirement. Record logical offsets, stored offsets, lengths, codec, and integrity metadata. The index becomes part of the artifact's correctness contract.
Apache Parquet's compression specification provides a concrete example: data and dictionary pages can be compressed, with buffer-size information in page headers. It also documents interoperability differences between the deprecated LZ4 codec and LZ4_RAW. Naming the algorithm is insufficient; readers must agree on its container and framing.
Smaller independent units bound how much data one point read decodes and localize retries. Larger units can expose more repetition but increase the work needed to recover a small slice. Treat that as a workload-dependent tradeoff. Benchmark random retrieval as well as full scans, and include index size and request overhead when comparing layouts.
Separate encoding from general compression. Parquet dictionary encoding replaces repeated column values with integer identifiers and can fall back to plain encoding when the dictionary grows too large. That column-level representation differs from a trained codec dictionary. Explain the scope of each dictionary and the information needed to reconstruct a value.
4. Treat dictionaries as durable dependencies
A shared dictionary can help short, similar messages that offer little repetition individually. The Zstandard command-line documentation describes training dictionaries from samples. For a service, choose samples representing the target population, evaluate on held-out messages, and compare total stored bytes including dictionary distribution. Do not train on a convenient sample and assume it represents every tenant or future schema.
RFC 8878 defines Zstandard dictionary identifiers and notes that, when the identifier is absent, the decoder must otherwise know which dictionary to use. Build an application envelope that identifies the format version, codec, and required dictionary unambiguously. An identifier alone does not deliver the dictionary or prove its authenticity.
For this design, retain immutable dictionary bytes with a verified digest for as long as any retained export or backup requires them. Roll out decoder support before new writers. Test recovery on a machine with an empty cache. If a dictionary is missing, return an explicit failure or use an independently retained alternative representation; guessing another dictionary is not a recovery strategy.
Consider tenant boundaries during training and distribution. A dictionary derived from private documents is another data artifact that needs access controls, retention rules, and review. Measure whether separate tenant dictionaries justify their operational cost. A global dictionary trained on approved public templates may be a simpler starting point when sensitive content is involved.
5. Account for the storage engine and HTTP representation
Compression at one layer does not make every other layer cheaper. RocksDB documents per-column-family compression and a separate bottommost-level setting, allowing heavier compression where much of the data resides. It also warns that compression differences can prevent trivial compaction moves. Ask about background rewrite CPU and write stalls alongside steady-state disk savings.
PostgreSQL 18's TOAST documentation explains that large values can be compressed and moved out of line, with compression selected through column settings or an insertion-time default. Changing application payload compression therefore changes the input seen by storage. Measure the combined result instead of multiplying independently advertised saving ratios.
For downloads, compression also creates an HTTP representation choice. RFC 9110's content-negotiation example uses different strong entity tags for encoded and unencoded representations. Honor accepted content codings, label the selected coding correctly, and use Vary: Accept-Encoding when that request field influences selection. Test caches and range requests against the actual representation bytes.
Keep rollout reversible by preserving readers for historical formats. Disabling a new writer setting does not convert old exports. Inventory retained formats, test mixed-version readers, and decide whether a rewrite is worth its temporary storage and compute. The rollback plan must cover existing data as well as future requests.
6. Bound decompression and examine information leakage
A small compressed request is not a small resource request. Enforce limits on incoming bytes, produced bytes, decoder memory, elapsed time, and concurrent decoding work. Charge output progressively while streaming. Do not allocate a claimed output size without validating it against policy, and do not assume that a memory-window limit caps the total amount of output.
There is an important HTTP-specific rule: RFC 9659 requires zstd HTTP decoders to support windows through 8 MB and forbids encoders from requiring a larger window. This updates the earlier recommendation. Reject nonconforming oversized windows, and separately cap total output and worker concurrency; many valid streams can still exhaust a service together.
Encryption does not hide every compression signal
The original BREACH researchers describe attacks involving HTTP response compression, reflected attacker input, and secrets in response bodies. Observable encrypted response sizes can reveal information under the attack's conditions. TLS alone does not eliminate that application-layer compression channel.
For the practice design, avoid compressing sensitive dynamic responses that combine secrets with attacker-controlled text until the threat model and mitigations are reviewed. Keep static public exports and authenticated dynamic pages as separate decisions. Test malformed frames, missing dictionaries, truncated streams, excessive expansion, and cancellation during decoding. Define whether partial output is discarded or staged until complete validation before a consumer can use it.
7. Rehearse a decision that survives changed assumptions
Illustrative practice rubric: spend five minutes defining the workload and success criteria, ten comparing uncompressed and compressed paths, ten choosing chunk and dictionary boundaries, and ten handling failures and rollout. Use the remaining five to summarize your decision and the evidence that could reverse it. This forty-minute structure is a rehearsal aid, not a prediction of interview timing.
Ask a partner to change one assumption: exports become mostly JPEGs, clients need random records, decoder CPUs are weaker than servers, or a dictionary disappears during disaster recovery. A strong answer updates the affected budget and dependency rather than defending the original codec at all costs. Explain what remains safe while the optimization is disabled.
Finish with a concrete proposal: precompute a supported representation for reusable exports, add independent chunks only when partial-read measurements justify them, retain decoder dependencies, and enforce resource limits at ingestion. Define a canary comparing bytes, CPU, memory, errors, and latency against the baseline. That chain of requirements, measurements, and recovery behavior gives an interviewer something precise to challenge—and gives you a useful way to practice engineering judgment.
Practice the compression tradeoffs
Use Interview Copilot to prepare technical explanations, rehearse follow-up questions, and refine your senior or staff engineer interview preparation.
Start practicingSources & References
- Zstandard: benchmark methodology and reference implementation
- Apache Parquet: compression formats and framing
- Apache Parquet: dictionary and other encodings
- Zstandard manual: dictionary training and decoding options
- RFC 8878: Zstandard frames and dictionary identifiers
- RocksDB: compression placement and compaction implications
- PostgreSQL 18: TOAST storage and compression
- RFC 9110: content negotiation, validators, and representations
- RFC 9659: HTTP zstd window requirements
- BREACH researchers: compression side channels and mitigations