SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
  • Relational Databases
  • Document Databases
  • Key-Value Databases
  • Full-Text Search Engines
  • Wide Column Databases
  • Time Series Databases
  • Graph Databases
  • Vector Databases
  • NewSQL Databases
  • Columnar Databases
  • In-Memory Databases
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Data and Storage/Database Types (Deep Dive)

Columnar Databases

Store data column by column, so analytics reads only what it needs and compresses well.

⏱ 13 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A columnar database stores data column by column instead of row by row. All the values of one column sit together on disk.

  • An analytic question like "total sales per country" needs only two columns. A columnar store reads just those two and skips the rest.
  • Values in one column look alike, so they compress very well, which means even less to read.
  • The price: reading or changing one whole row is slower, because its pieces are spread over many column areas.
  • That is why columnar stores power analytics (OLAP), not busy shopping carts (OLTP).

02Concept: What is it?

A normal row store keeps each record together: id, name, country, plan, age and spend, then the next record. That is perfect when you want one customer's full details. The database finds the row and everything is right there.

An analyst asks different questions: "what is the average spend of customers over 40?" The table may have 200 columns and a billion rows, but the question uses only two columns. A row store must still read every row in full, wasting most of what it reads.

A column store keeps all the spend values together, all the age values together, and so on. The query reads two columns and ignores the other 198. On top of that, a column holds one kind of value, such as many repeats of "US" and "UK", so it squeezes into much less space.

Same table, two layouts
Row layout
1 · Ana · US · 0
2 · Ben · UK · 90
3 · Chen · US · 0
Column layout
id1, 2, 3
nameAna, Ben, Chen
countryUS, UK, US
spend0, 90, 0
A row store keeps whole records side by side. A column store keeps each column side by side.
🧠Do not mix it up with wide-column stores
Columnar analytic databases (ClickHouse, BigQuery and similar) are different from wide-column stores like Cassandra or Bigtable. Wide-column stores keep rows with flexible column families and are built for huge writes and key lookups. Columnar stores are built for scanning and summing.

03Real-Life Example

🍵A School Register vs Subject Folders
A school keeps one big filing cabinet. In the row way, each student has a folder with everything about them: name, address, marks in every subject. To read one student's whole story, you open one folder. In the column way, there is a folder per subject, holding every student's mark in that subject. To find "the average maths mark of the school", you open one folder and ignore the rest. But to read one student's whole story you must visit every subject folder.
The school
The database
A folder per student
Row storage
A folder per subject
Column storage
Average maths mark of everyone
An aggregate over one column (fast in a column store)
One student's whole story
A full-row lookup (fast in a row store)
Marks in a subject are all numbers 0 to 100
Similar values in a column, so they compress well
Adding a new student means a note in every folder
Inserting a row touches every column area
Collect new students in a box, then file them in a batch
Write buffer merged into column storage later
What each query reads
Average age and spend
Column store2 of 10 columns
Row storeall columns of every row
Show customer 42 in full
Row storeone place
Column storeevery column area
Faster Slower

04Why Do We Need It?

📉Read less
A query touches only the columns it names. With wide tables, that can be a tiny part of the data.
🗜️Compress more
Equal or similar values sit side by side, so run-length, dictionary and delta encoding shrink them a lot.
⚡Fast scans
Engines process a whole block of values at once with the CPU, which suits sums, counts and averages.
💾Lower storage cost
Smaller data means less disk and less money, especially in the cloud.
📊Built for analysis
Dashboards, reports and ad-hoc questions over billions of rows are the sweet spot.
🔌Skip data early
Blocks often store min and max values, so a filter can skip whole blocks without reading them.
Analytics asks about a few columns of many rows. Store by column and you read only what you ask about.

05Where Do We Use It?

🏢Data warehouses
Warehouses are mostly columnar, so reports on huge history stay fast.
📈Product analytics
Counting events, funnels and users over billions of rows.
📡Logs and metrics analysis
Scanning huge event tables for a few fields.
🧪Data science
Reading a few feature columns from very wide tables.
📁Data lake files
Formats like Parquet and ORC store data by column inside files.
💰Finance reporting
Totals and averages over years of transactions.
📝Note
Examples include ClickHouse, Amazon Redshift, Google BigQuery, Snowflake and the Parquet and ORC file formats. They differ in many details, such as how they handle updates.

06Types / Parts / How It Works

The tricks that make it fast

TrickHow it worksHelps with
Column pruningRead only the columns the query namesLess data read from disk
Run-length encodingStore a value and how many times it repeats in a row, like US x5Sorted or low-variety columns
Dictionary encodingReplace long repeated values (like country names) with small numbers and keep a lookup tableText columns with few different values
Delta encodingStore the difference from the previous value, like +1, +1, +2 for timestampsSlowly changing numbers and times
Vectorised executionProcess thousands of values per CPU step instead of one at a timeSums, counts, filters
Min/max per blockRemember the smallest and largest value of each block, and skip blocks that cannot match the filterRange filters like date between
Sort key / partitioningKeep rows in an order that suits common filters and split data by something like dateSkipping data, and better compression

Run-length encoding in one picture

A sorted column, before and after
before:  free free free free pro pro team team team
after:  free x4 | pro x2 | team x3     (3 runs instead of 9 values)

in insertion order:  free pro free team pro free team pro team
after:  9 runs of 1  (no saving at all)
💡Sorting is a compression tool
The same data compresses far better when equal values sit together. Choosing a good sort key is one of the biggest tuning levers in a columnar store.

How writes work

Adding one row means adding one value to every column area, which is slow if done one row at a time. So columnar engines collect new rows in a small write buffer (often row-shaped, in memory), then write them out to column storage in large batches, and merge them in the background. That is why they prefer big bulk loads to many tiny inserts.

VisualizerRow layout vs column layout, and run-length encodingRun each query and compare how many cells a row store and a column store must read. Then open the compression view and sort a column to watch the runs shrink.
What to explore
Run this query
idnamecountryplanagespend
1AnaUSfree310
2BenUKpro4590
3ChenUSfree280
4DiaINteam39240
5EliUKpro5290
6FayUSfree240
7GusINteam47240
8HanaUSpro3690
Row layout on disk: one row after another
Column layout on disk: one column after another

Cyan = read and useful. Amber = read but not needed. Dark = not touched. Each box groups the cells that sit side by side on disk.

Row store reads
48
cells, 8 places
Column store reads
8
cells, 1 place
Row store wasted
40
cells read for nothing
Adding up spend (total 750): the row store reads 48 cells because rows are stored whole, and only 8 matter (amber = read for nothing). The column store reads just the 8 spend cells, in one place.

A tiny teaching model with 8 rows and 6 columns. Real engines read in blocks of thousands of values, keep per-block min and max values to skip data, and combine run-length encoding with other tricks such as dictionaries.

07How to Use It / Steps / Implementation

Using a columnar database well

  1. 1
    Use it for analysis, not transactions
    Keep your live app on a row-based OLTP database. Copy data into the columnar store for reports and dashboards.
  2. 2
    Load in big batches
    Bulk loads and streaming in micro-batches work well. Thousands of single-row inserts and updates work badly.
  3. 3
    Choose the sort key
    Sort or order by the columns you filter on most (often a date plus one more). It lets the engine skip data and compress more.
  4. 4
    Partition by time
    Splitting by day or month lets queries touch only the relevant slice, and makes it simple to drop old data.
  5. 5
    Select only the columns you need
    Avoid SELECT *. Every extra column is extra data to read.
  6. 6
    Prefer wide, flat tables for scans
    Many columnar systems are happiest with denormalised tables, because big joins cost a lot.
  7. 7
    Mind the cost model
    Some cloud engines charge by the data scanned. Fewer columns and good partitions cut the bill directly.
⚠️Not for point lookups
If your main query is "get customer 42", a columnar store has to gather pieces from many column areas. Use a row store or a key-value store for that job.

08Key Terms to Know

TermMeaning in easy words
Columnar storageStoring each column's values together instead of storing whole rows together
Row storeThe classic layout: one whole record after another
OLAPAnalytic workload: few queries that read a lot of data
OLTPTransaction workload: many small reads and writes of single records
Column pruningReading only the columns a query uses
Run-length encoding (RLE)Replacing a repeated value with the value and a count
Dictionary encodingReplacing values with small codes plus a lookup table
Vectorised executionProcessing a batch of values at once
Zone map (min/max)The smallest and largest value of a block, used to skip blocks
Sort keyThe order in which rows are kept, which affects speed and compression
Parquet / ORCOpen file formats that store tables by column

09Pros, Cons and Trade-offs

✅ Pros
  • Reads only the needed columns
  • Very good compression
  • Fast sums, counts and averages over huge tables
  • Lower storage and scan cost
  • Good fit for dashboards and reports
⚠️ Cons
  • Slow single-row lookups
  • Slow row-by-row inserts and updates
  • Updates and deletes may be heavy or delayed
  • Joins over huge tables can be costly
  • Not a replacement for your main transactional database

Trade-offs

ChoiceWe gainWe lose
Column layoutFast scans and small storageSlow whole-row reads and writes
Row layoutFast single-record workWasted reads for analytics
Sorting by a columnBetter compression and skippingOther filters benefit less
Bigger write batchesEfficient loadingNew data appears a little later
Wide denormalised tablesNo big joins at query timeRepeated data and larger load jobs
Strong compressionLess I/O and diskSome CPU time to decompress

10Common Problems and Mistakes

Common mistakes

  1. Using it as the app's main database. Lots of small updates and point reads fit a row store much better.
  2. Tiny inserts. Writing one row at a time creates many small files and slows everything.
  3. SELECT *. It throws away the main advantage of the layout.
  4. Ignoring the sort key. Without a sensible order, filters scan far more than they need to.
  5. Confusing it with wide-column stores. They have similar names but solve different problems.
  6. Expecting instant updates. Many engines handle updates and deletes in the background, so results may lag.
  7. Too many partitions. Thousands of tiny pieces cost more in overhead than they save.

Things to watch

📦Small files
Many tiny files or parts slow down queries. Batch your loads and compact regularly.
🧮Skewed partitions
One huge partition makes some queries slow while others stay fast.
🔁Late updates
A changed row may show up after the next merge. Check how your engine handles it.
💸Scan-based pricing
Some services charge per byte scanned, so one careless query can cost real money.

11Real-World Examples

🟡ClickHouse
An open-source columnar database used for fast analytics on event data.
🔷BigQuery
A managed analytics service from Google that stores data by column.
🟥Amazon Redshift
A cloud data warehouse with columnar storage.
❄️Snowflake
A cloud data platform that stores table data in a columnar format.
📄Parquet and ORC
File formats that bring columnar storage to a data lake.
🧰Row-oriented databases with columnar options
Some traditional databases add columnar indexes or extensions for analytics.
📝Note
Product details change. The names above are examples of the idea, not a buying guide.
Mini case: shop analytics
🛒Shop app
→↓orders
🗄️Row databaselive orders
→↓copy (ETL / CDC)
📊Column storereports
Transactions (OLTP) Analytics (OLAP)
The shop keeps its live data in a row store and copies it to a column store for reports.

12Related Topics to Read Next

OLTP vs OLAP→

The two workloads that row and column storage serve.

Data Warehousing→

Warehouses are usually columnar.

Data Lakehouse→

Lakehouses use columnar file formats on cheap storage.

Compression and Deduplication→

Why similar values in a column shrink so well.

Wide Column Databases→

A different idea with a similar name. Compare them.

Indexing→

Another way to avoid reading everything.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: data stored column by column, not row by row.
  • ✔Good at: sums, counts and averages over huge tables, reading few columns.
  • ✔Bad at: single-row lookups, and many tiny inserts or updates.
  • ✔Why fast: column pruning, strong compression, vectorised work, block skipping.
  • ✔Compression: run-length, dictionary and delta encoding. Sorted columns shrink most.
  • ✔Tuning: sort key, partition by time, select only needed columns, load in batches.
  • ✔Not the same as: wide-column stores like Cassandra.
  • ✔One line: “Analytics reads a few columns of many rows, so store by column.”
← Previous
NewSQL Databases
Next →
In-Memory Databases