Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 10/ 160
01. Data Engineering Foundations, Python & Linux

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.

IntermediateColumnar · Compression · Codecs3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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

Loading interactive 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.

Row-Oriented vs Columnar Storage Formats & Compression in one concrete design

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.

Key takeaway: 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

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.

Key takeaway: 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.

How it works, step by step

Step 1 of 4
Columnar

1. 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.

whole rows versus selected columns
Key numbers at this step
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

Columnar
Best for: A physical layout optimized for reading subsets of columns and vectorized analytics with metadata, encodings, and compression per column chunk.

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.

Compression
Best for: Reducing stored bytes through dictionary, run-length, delta, or general-purpose algorithms with a CPU/I/O trade-off.

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.

Codecs
Best for: The implementation of compression-Snappy for speed, Zstd for tunable ratio/speed, and Gzip for broad compatibility and stronger compression at more CPU.

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?
Interview tip: Lead with the data path and failure boundary: 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. Then make the answer operational: 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.

Knowledge check

Loading quiz

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.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Working with File Formats (CSV, JSON, XML, Parquet, Avro, ORC)
Next topic
Reading & Writing Data with Pandas & Polars (Lazy Execution)