Data Warehouses & Analytics Storage
You'll learn to
- -Distinguish OLTP from OLAP workloads by the shape of their queries
- -Explain why running analytics on the production database causes damage
- -Explain row versus column storage with a worked scan, and why columns win for analytics
- -Describe how data gets into a warehouse, and why reports are slightly behind
Everything in this course so far has served the product: a customer places an order, a profile loads, a balance updates. But the business also has questions about the product: what was revenue by region last quarter, which signup source retains best? Those questions look nothing like the product's queries, and trying to answer them on the same database that serves customers is a classic way to cause an outage. This chapter explains why, and what to do instead.
An Analogy: The Checkout Till and the Annual Accounts
A shop's till handles one customer at a time: scan an item, take a payment, print a receipt. It has to be fast and it is used all day. The accountant who prepares the annual figures wants something entirely different: totals across every sale of the year. If the accountant sat at the till to do that work, the queue would stretch out of the door. So the shop copies its sales records to the back office, and the accountant works there.
- -The till is the OLTP database: many small, quick reads and writes, one record at a time.
- -The annual accounts are OLAP: a few huge queries that scan millions of records.
- -The back office, working on a copy, is the data warehouse.
OLTP vs OLAP
Everything built so far is an OLTP workload (Online Transaction Processing): place an order, update a balance, fetch a profile. OLAP (Online Analytical Processing) is the opposite shape: a handful of large queries that scan millions of rows to answer questions such as total revenue by region, by month, for the last two years. Running those directly against the production database does real damage: large scans hold locks and burn the disk and memory that live traffic needs, so customers feel it.
Rows Versus Columns
The second half of the answer is how the warehouse stores data. A normal database stores a table row by row, with all of one record's columns together on disk, which is ideal for fetching or updating one whole record. A warehouse stores it column by column, with all the values of one column together. See what that does to an analytical query. Take 100 million orders with 20 columns, around 200 bytes per row. To total revenue by region you need only two columns, region and amount.
- -Row storage reads whole rows, so it scans 100 million x 200 bytes = 20 GB to use two columns.
- -Column storage reads only the two columns it needs, roughly 10 bytes per row, so about 100 million x 10 bytes = 1 GB, around twenty times less.
- -Values in a column look alike (a few dozen regions repeated millions of times), so they compress very well, and the real amount read is smaller still.
The price is that column storage is poor at fetching or updating one whole record, which is why it complements the OLTP database rather than replacing it. The card below describes the warehouse component as it appears in the lab:
A data warehouse is like a massive library designed specifically for answering BIG questions. Your regular database (PostgreSQL, MySQL) is optimized for doing one thing at a time quickly: 'Get user #42's profile,' 'Update order #5678 status to shipped.' A data warehouse is optimized for scanning BILLIONS of rows to answer analytical questions: 'What's our total revenue by product category by region for the last 2 years?' 'Which acquisition channel brings users who spend the most in their first 30 days?' It stores data in COLUMNS instead of rows (columnar storage), which is perfect for analytics. When you need the SUM of a 'revenue' column across 2 billion rows, the database only reads that one column from disk, ignoring the other 50 columns. This makes analytical queries 10-100x faster than row-based databases. Data gets loaded into the warehouse from your production databases, event streams, and third-party sources through an ETL pipeline (Extract, Transform, Load). Business analysts, data scientists, and dashboards all query the warehouse. NEVER your production database!
Examples: Snowflake (most popular cloud DW), Google BigQuery (serverless, pay-per-query), AWS Redshift, ClickHouse (open-source, incredibly fast), Apache Druid (real-time analytics), Databricks Lakehouse
How Data Gets There
Data is copied from the production databases into the warehouse by a pipeline: extract it, transform it (clean it, join it with other sources, reshape it), and load it. This is called ETL, or ELT when the transformation happens after loading, inside the warehouse. It may run nightly, or continuously by streaming changes out of the database. The diagram shows the shape:
Production data is copied into the warehouse by a pipeline, so analysts never run queries against the live database
Two consequences follow. First, a warehouse is slightly behind the product: a report is only as fresh as the last load, from minutes to a day. That is fine for business questions, but never use the warehouse to decide whether an order may be placed. Second, warehouse data is mostly appended, not edited row by row: you add new loads and query across them.
In one line: OLTP is the till and OLAP is the annual accounts. Keep analytics off the production database, copy data into a warehouse that stores columns so a scan reads only what it needs, and accept that its numbers are a little behind.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Level 14 (Google Drive) and Level 15 (Web Search Engine) apply this module directly.
Discussion0
Join the Discussion
Sign in to leave comments, reply to others, or like insights.
No comments yet. Be the first to start the thread!