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
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
  • Batch vs Stream Processing
  • Change Data Capture (CDC)
  • MapReduce
  • ETL Pipelines
  • Data Lakes
  • Data Warehousing
  • Data Lakehouse
  • Lambda Architecture
  • Kappa Architecture
  • Streaming Engines
  • Spark and Hadoop
  • Workflow Orchestration (Airflow)
  • Parquet and Columnar File Formats
  • Data Governance and Feature Stores
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Advanced Data Topics/Big Data Processing

Data Warehousing

A database built for analysis: clean, organised data for reports and dashboards.

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

01Quick Summary

A data warehouse is a database built for analysis, not for running the app. It holds clean, organised data from many sources, so people can ask big questions and get reports fast.

  • It collects data from many systems (orders, payments, support) into one place with one shape.
  • It is built for reading lots of rows ("total sales per month"), usually with column-based storage.
  • Data is usually shaped into a star schema: a central fact table of events, surrounded by dimension tables that describe them.

02Concept: What is it?

Your app database is built for OLTP (online transaction processing): many small, fast operations such as "add this order" or "get user 42". A warehouse is built for OLAP (online analytical processing): a few huge questions such as "what was revenue per region per month for the last three years?"

Running those huge questions on the app database would slow the app for everyone. So the data is copied into a separate warehouse, cleaned and shaped on the way (schema on write), and kept with its history. Analysts and dashboards then query the warehouse without touching the app.

Two ideas make warehouses fast. First, columnar storage: each column is stored together, so a query that needs 3 of 40 columns reads only those 3, and similar values compress well. Second, parallel processing: the work is spread over many nodes, each scanning its own slice.

App database vs data warehouse
Operational database (OLTP)
๐Ÿ›’Place an order1 row, milliseconds
๐Ÿ‘คGet user 421 row, index lookup
โ†’โ†“extract, clean, load
Data warehouse (OLAP)
๐Ÿ“ŠRevenue per monthmillions of rows, few columns
๐Ÿ”ŽTrends over 3 yearshistory is kept
Different jobs, different designs. Data flows one way, from the app side to the warehouse.
๐Ÿง Warehouses are for questions, not for orders
A warehouse is not a place to save a customer's order. It is slow at single-row lookups and updates. Save orders in the app database, then copy them over for analysis.

03Real-Life Example

๐ŸตThe Shop Ledger and the Annual Report
A busy shop writes every sale on a till receipt all day (the app database). At the end of the year the owner wants to know which products sell best in which months. Nobody reads a million receipts one by one. Instead, an accountant copies the figures into a tidy ledger: one page per product, one column per month, all in the same format and with old years kept. Now the owner can answer the question in minutes, and the till is never slowed down. The tidy ledger is the data warehouse.
Shop
Data warehouse
Till receipts during the day
Operational (OLTP) database
The accountant copying figures into a ledger
An ETL or ELT pipeline
One tidy format for every product
A common schema, shaped on write
A page of sales and pages that describe products
A fact table and dimension tables
Keeping past years in the ledger
Historical data kept for trends
Totals by month, by product, by shop
Aggregation queries (OLAP)
Reading one column of the ledger
Column-based storage reads only what is needed
A star schema
๐Ÿ“…dim_dateday, month, year
๐Ÿ“ฆdim_productname, category
โ†•
๐Ÿงพfact_salesdate_id, product_id, store_id, quantity, amount
โ†•
๐Ÿฌdim_storecity, region
๐Ÿ‘คdim_customersegment, country
Fact: one row per sale Dimension: describes the sale
One central fact table of events. Dimension tables around it describe who, what, where and when.

04Why Do We Need It?

๐Ÿ›ก๏ธDo not slow down the app
Heavy reports run on a separate system, so customers using the app are not affected.
๐Ÿ”—One place for all data
Sales, support and marketing data live together, so you can join them and ask cross-team questions.
โšกFast big queries
Columnar storage, compression and parallel nodes scan billions of rows in seconds to minutes.
๐Ÿ“œHistory is kept
The app database only stores the current state. A warehouse keeps the past, so you can see trends.
โœ…One trusted answer
Data is cleaned and defined once (what counts as 'revenue'), so teams stop quoting different numbers.
๐Ÿ“ŠWorks with BI tools
Dashboards and report tools talk to warehouses using ordinary SQL.
Keep the app database for running the business, and a warehouse for understanding it.

05Where Do We Use It?

๐Ÿ“ŠBusiness dashboards
Sales, marketing and finance reports that must be correct and quick.
๐ŸงฎFinance and compliance
Month-end numbers and audit trails need clean, consistent, historical data.
๐ŸงฒCustomer analytics
Combine orders, visits and support tickets to understand customer behaviour.
๐Ÿ”ฌProduct analytics
Funnels, retention and experiments (A/B tests) over huge event tables.
๐ŸคSharing data
Teams and partners query one governed source with access rules.
๐Ÿง Feeding other systems
Aggregated tables from the warehouse can feed models or reverse-ETL back to apps.

06Types / Parts / How It Works

Inside a warehouse

The usual layers
BI tools and SQL clientsdashboards, notebooks, reports
Marts (summary tables)for finance, marketing, product
Core modelfact and dimension tables (star schema)
Stagingraw copies loaded from the sources
Sourcesapp databases, SaaS tools, event streams
Many teams add a staging area, then modelled tables, then small summary tables for dashboards.

Modelling choices

ModelHow it looksGood and bad
Star schemaOne fact table joined to flat dimension tablesSimple, fast queries. Some repeated data in dimensions.
Snowflake schemaDimensions are split into further tablesLess repeated data. More joins and harder to read.
Wide denormalized tableEverything pre-joined into one big tableVery fast, easy for analysts. Large and harder to change.

OLTP vs OLAP

OLTP (app database)OLAP (warehouse)
Typical queryGet or change one rowScan and add up millions of rows
Storage layoutRow basedColumn based
DataCurrent stateHistory, over many years
UsersApp and customersAnalysts and dashboards
UpdatesConstant, smallLoaded in batches or micro-batches
GoalFast and correct transactionsFast answers over big data
VisualizerRow store vs column store: how much data is read?Run the report with 3 columns and watch the column store read far less. Then switch to a single-row lookup, and see why a warehouse is a poor home for order lookups.
What is the query?
Row store (like a normal database): rows stored together. Blue = read from disk
Data read160.0 GB in 1.3 min
Column store (warehouse): each column stored together
Data read3.0 GB in 1.5 s
Row store reads
160.0 GB
1.3 min
Column store reads
3.0 GB
1.5 s
Column store is
53.3x less
data read
The report needs only 3 of 40 columns. A row store keeps each row together, so it must read all 40 columns of every row. A column store reads just the 3 it needs, and they compress well, so it scans about 53 times less data (3.0 GB instead of 160.0 GB).

A simplified model with no random numbers: every value is 8 bytes, columns compress about 4 to 1, a node scans about 500 MB per second, and a lookup is served by an index. Real engines also skip data with statistics and partitions, so real numbers differ.

07How to Use It / Steps / Implementation

Building a warehouse step by step

  1. 1
    Start with the business questions
    List the reports people need: revenue by region, churn by month. Let the questions decide what to model.
  2. 2
    Pick the grain of each fact table
    Decide what one row means, such as 'one line item on one order'. A clear grain prevents double counting.
  3. 3
    Design facts and dimensions
    Put numbers you add up (amount, quantity) in the fact table, and descriptions (product, date, customer) in dimension tables.
  4. 4
    Load from the sources
    Use ETL or ELT pipelines, often with Change Data Capture, to copy data in on a schedule or continuously. Land it in a staging area first.
  5. 5
    Clean and conform
    Fix types, remove duplicates and use the same definition of a customer or a revenue figure everywhere.
  6. 6
    Handle history
    Decide what happens when a customer moves city. A common choice (slowly changing dimension type 2) keeps the old row and adds a new one with dates.
  7. 7
    Tune for reads
    Choose partitions (often by date), sort or cluster keys, and build summary tables for hot dashboards. Add access control and cost monitoring.
๐Ÿ’กETL or ELT?
ETL transforms data before loading it. ELT loads raw data into the warehouse first and transforms it there with SQL. Modern cloud warehouses are powerful and cheap enough that ELT is very common.
โš ๏ธDo not select * on a column store
Asking for all columns throws away the main advantage of a columnar warehouse. Select only the columns you need, and filter on the partition column such as date.

08Key Terms to Know

TermMeaning in easy words
Data warehouseA database built for analysis, holding cleaned, organised data from many sources
OLTPOnline transaction processing: many small reads and writes for running the app
OLAPOnline analytical processing: big queries that summarise lots of data
Fact tableThe central table of events or measurements, such as one row per sale
Dimension tableA table that describes a fact: who, what, where, when
Star schemaA fact table with dimension tables around it, joined by keys
Columnar storageStoring each column together so queries read only the columns they need
GrainWhat exactly one row of a fact table stands for
Data martA smaller warehouse or set of tables for one team, such as finance
Slowly changing dimensionA way to keep history when descriptive data (like a customer's city) changes
ELTLoad raw data first, then transform it inside the warehouse

09Pros, Cons and Trade-offs

โœ… Pros
  • Fast queries over very large data
  • Keeps the app database free from heavy reports
  • Cleaned data with one shared definition for each number
  • History is kept for trend analysis
  • Plain SQL and wide BI tool support
  • Scales out with more nodes (cloud warehouses can scale compute on demand)
โš ๏ธ Cons
  • Slow at single-row lookups and frequent small updates
  • Needs upfront modelling work
  • Data is usually minutes to hours behind the sources
  • Costs can grow fast if queries are careless
  • Mostly structured data, so images and raw logs fit poorly
  • Changing the model later can mean reloading data

Trade-offs

ChoiceWe gainWe lose
Schema on writeClean, trusted dataLess flexibility, unplanned fields are lost
Star schemaSimple, fast queriesSome repeated data and upfront design
Snowflake schemaLess repeated dataMore joins, harder to query
Batch loadsSimple and cheapData is not fresh
Streaming or micro-batch loadsFresher dataMore complexity and cost
Pre-built summary tablesInstant dashboardsExtra storage and a job that keeps them current

10Common Problems and Mistakes

Common mistakes

  1. Using it like an app database. Single-row lookups and updates are slow here.
  2. An unclear grain. Mixing order-level and item-level rows in one fact table leads to double counting.
  3. No shared definitions. Two dashboards show two different "revenue" numbers, and trust is lost.
  4. Joining on dirty keys. Duplicate or missing keys silently multiply or drop rows.
  5. SELECT * on huge tables. It reads every column and runs up the bill.
  6. No partitioning or clustering. Every query scans the whole table.
  7. Forgetting history. Overwriting a dimension row means old reports change when they should not.

Things to watch

๐Ÿ’ธRunaway cost
Pay-per-scan or always-on clusters can get expensive. Set budgets and alerts.
โฑ๏ธStale data
Dashboards are only as fresh as the last load. Show 'last updated' on them.
๐Ÿ”€Late-arriving data
Events can arrive after the day was closed. Decide how to correct past totals.
๐Ÿ”Sensitive columns
A warehouse joins everything together. Mask personal data and control who sees what.

11Real-World Examples

โ˜๏ธCloud warehouses
Amazon Redshift, Google BigQuery and Snowflake are widely used managed warehouses.
๐ŸขClassic enterprise
Teradata, Oracle and SQL Server based warehouses run in many large companies.
โš™๏ธTransform tools
Tools like dbt let teams build and test warehouse models using SQL.
๐Ÿ“ŠBI tools
Tableau, Power BI and Looker query warehouses to draw dashboards.
๐Ÿ›’Retail
Sales, stock and promotions are joined to plan what to stock and when to run offers.
๐ŸฆBanking
Risk and compliance reports need a clean, auditable history of transactions.
๐Ÿ“Note
Product features and pricing models change often. Check the current documentation before choosing.
Mini case: from orders to a dashboard
๐Ÿ›’Orders DBOLTP
โ†’โ†“CDC or nightly load
๐Ÿ“ฅStagingraw copy
โ†’โ†“transform
๐Ÿ›๏ธWarehousestar schema
โ†’โ†“SQL
๐Ÿ“ŠDashboardrevenue per month
Data moves one way. The app is never queried by the dashboard.

12Related Topics to Read Next

Data Lakesโ†’

The raw, flexible store that often feeds a warehouse.

Data Lakehouseโ†’

Tries to give one system both warehouse and lake strengths.

ETL Pipelinesโ†’

The jobs that move and shape data into the warehouse.

Change Data Capture (CDC)โ†’

A way to stream changes from the app database into the warehouse.

Denormalizationโ†’

Wide tables trade extra copies for faster reads, as warehouses do.

Materialized Viewsโ†’

Saved results of heavy queries, like summary tables.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”What: a database built for analysis, with clean data from many sources and its history.
  • โœ”OLTP vs OLAP: app transactions vs big summary queries. Keep them apart.
  • โœ”Speed: column storage, compression and many nodes scanning in parallel.
  • โœ”Model: a fact table (events) plus dimension tables (descriptions) is a star schema.
  • โœ”Grain first: decide what one fact row means before anything else.
  • โœ”Loading: ETL or ELT, batch or CDC, through a staging area.
  • โœ”Avoid: single-row lookups, SELECT *, and scans with no date filter.
  • โœ”One line: โ€œCopy the data out of the app, tidy it once, and ask big questions without slowing anyone down.โ€
โ† Previous
Data Lakes
Next โ†’
Data Lakehouse