Row-Oriented vs Columnar Storage Formats & Compression (Snappy, Gzip, Zstd)
Understand when row vs columnar storage wins and how compression codecs trade CPU for bytes on disk.
In plain words
Whole rows versus selected columns. Next, row groups, pages, and encodings. Finally, file size, sort order, and dictionary cardinality.
Think of it like…
A row store is a stack of patient charts; a column store has one cabinet per vital sign, letting a fever query open only the temperature drawer.
Where you’ve seen it
SELECT customer_id, sum(amount) FROM read_parquet('sales/**/*.parquet') can skip the unrelated 80 columns, while an Avro ingest path preserves a whole order event for downstream consumers.
Words you’ll hear
- Columnar
- A physical layout optimized for reading subsets of columns and vectorized analytics with metadata, encodings, and compression per column chunk.
- Compression
- Reducing stored bytes through dictionary, run-length, delta, or general-purpose algorithms with a CPU/I/O trade-off.
- Codecs
- The implementation of compression-Snappy for speed, Zstd for tunable ratio/speed, and Gzip for broad compatibility and stronger compression at more CPU.
- Operational boundary
- Small files, poor sort order, or weak encodings leave columnar tables inefficient; high compression can save I/O but increase CPU and latency for random writes or row-by-row decoding. Measure decoded bytes, I/O, scan latency, and CPU; use Zstd when decompression/ratio balance matters, Snappy for low-latency analytics, and Gzip mainly for cold or interchange data.
Visual diagram
Theory & deep dive
Columnar: the working mechanism
Row formats place complete records together for writes and record reads, whereas columnar formats group one field at a time so scans read and compress only selected columns.
Whole rows versus selected columns. Row groups, pages, and encodings, then bytes, scan CPU, and wall time; this exposes the state governed by Codecs.
SELECT customer_id, sum(amount) FROM read_parquet('sales/**/*.parquet') can skip the unrelated 80 columns, while an Avro ingest path preserves a whole order event for downstream consumers.
Row-Oriented vs Columnar Storage Formats & Compression: failure mode and production response
Small files, poor sort order, or weak encodings leave columnar tables inefficient; high compression can save I/O but increase CPU and latency for random writes or row-by-row decoding.
Measure decoded bytes, I/O, scan latency, and CPU; use Zstd when decompression/ratio balance matters, Snappy for low-latency analytics, and Gzip mainly for cold or interchange data. Track Predicate pruning as "unused columns are never decompressed", and make Snappy visible to the dataset owner.
How it works, step by step
Step 1 of 41. Map access
Whole rows versus selected columns. Row formats place complete records together for writes and record reads, whereas columnar formats group one field at a time so scans read and compress only selected columns.
- Predicate pruning
- unused columns are never decompressed
- Compression
- Reducing stored bytes through dictionary, run-length, delta, or general-purpose algorithms with a CPU/I/O trade-off.
When to use it & trade-offs
What it is
Row formats place complete records together for writes and record reads, whereas columnar formats group one field at a time so scans read and compress only selected columns. SELECT customer_id, sum(amount) FROM read_parquet('sales/**/*.parquet') can skip the unrelated 80 columns, while an Avro ingest path preserves a whole order event for downstream consumers.
Why it matters: Small files, poor sort order, or weak encodings leave columnar tables inefficient; high compression can save I/O but increase CPU and latency for random writes or row-by-row decoding. Measure decoded bytes, I/O, scan latency, and CPU; use Zstd when decompression/ratio balance matters, Snappy for low-latency analytics, and Gzip mainly for cold or interchange data.
When to reach for it
- Understand when row vs columnar storage wins and how compression codecs trade CPU for bytes on disk.
- Choose Columnar because it provides this capability: A physical layout optimized for reading subsets of columns and vectorized analytics with metadata, encodings, and compression per column chunk.
- Keep evidence for Predicate pruning at "unused columns are never decompressed" so the last production stage-Tune - file size, sort order, and dictionary cardinality-remains testable.
When to avoid or be careful
- Small files, poor sort order, or weak encodings leave columnar tables inefficient; high compression can save I/O but increase CPU and latency for random writes or row-by-row decoding.
- Do not conflate Compression with Columnar. The second concept contributes different behavior: Reducing stored bytes through dictionary, run-length, delta, or general-purpose algorithms with a CPU/I/O trade-off.
- Release only after this guardrail is in place: Measure decoded bytes, I/O, scan latency, and CPU; use Zstd when decompression/ratio balance matters, Snappy for low-latency analytics, and Gzip mainly for cold or interchange data.
Columnar / Compression / Codecs - roles, limits, and operating cost
Strengths: A physical layout optimized for reading subsets of columns and vectorized analytics with metadata, encodings, and compression per column chunk. Row formats place complete records together for writes and record reads, whereas columnar formats group one field at a time so scans read and compress only selected columns.
Watch out: Small files, poor sort order, or weak encodings leave columnar tables inefficient; high compression can save I/O but increase CPU and latency for random writes or row-by-row decoding.
Strengths: Reducing stored bytes through dictionary, run-length, delta, or general-purpose algorithms with a CPU/I/O trade-off. In this workflow it supports: Benchmark codecs - bytes, scan CPU, and wall time.
Watch out: The operating cost is real: fast decode with a moderate compression ratio.
Strengths: The implementation of compression-Snappy for speed, Zstd for tunable ratio/speed, and Gzip for broad compatibility and stronger compression at more CPU. Its output can be checked with Zstd level.
Watch out: Operating guardrail: Measure decoded bytes, I/O, scan latency, and CPU; use Zstd when decompression/ratio balance matters, Snappy for low-latency analytics, and Gzip mainly for cold or interchange data.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for Columnar, and how would Predicate pruning reveal it?”
- “Why is Compression distinct from this behavior: the implementation of compression-Snappy for speed, Zstd for tunable ratio/speed, and Gzip for broad compatibility and stronger compression at more CPU?”
- Production clue: Small files, poor sort order, or weak encodings leave columnar tables inefficient; high compression can save I/O but increase CPU and latency for random writes or row-by-row decoding.
- Design probe: Measure decoded bytes, I/O, scan latency, and CPU; use Zstd when decompression/ratio balance matters, Snappy for low-latency analytics, and Gzip mainly for cold or interchange data.
Benchmarks & rules of thumb
- Predicate pruning
- unused columns are never decompressed
- Snappy
- fast decode with a moderate compression ratio
- Zstd level
- higher level usually improves ratio but raises encode time
Common mistakes & follow-ups
Common interview mistakes
- Small files, poor sort order, or weak encodings leave columnar tables inefficient; high compression can save I/O but increase CPU and latency for random writes or row-by-row decoding.
- Reporting success from a job exit code without checking Predicate pruning and Snappy.
- Treating this example as complete without replay, rollback, or access boundaries:
SELECT customer_id, sum(amount) FROM read_parquet('sales/**/*.parquet')can skip the unrelated 80 columns, while an Avro ingest path preserves a whole order event for downstream consumers.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: A physical layout optimized for reading subsets of columns and vectorized analytics with metadata, encodings, and compression per column chunk.
- What does the recovery plan do when this occurs? Small files, poor sort order, or weak encodings leave columnar tables inefficient; high compression can save I/O but increase CPU and latency for random writes or row-by-row decoding.
- When is Columnar insufficient for Snappy, and what does adding Compression cost in Predicate pruning?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Row-Oriented vs Columnar Storage Formats & Compression (Snappy, Gzip, Zstd) with data engineer interview Q&A and hands-on practice.