Skip to content

Analytics and Data Warehousing: OLTP vs OLAP, Star Schema

Beginning of the lesson

Analytics and Data Warehousing: OLTP vs OLAP, Star Schema

Why the database that runs your shop is the wrong shape for analysing it

Big idea: A live application database is tuned to record one small change at a time — a single order, a single payment. A data warehouse is tuned for the opposite: scanning millions of past rows to answer "how much, by whom, when, where". These two goals pull the schema in opposite directions. The classic answer is the star schema: one central fact table of measurements surrounded by dimension tables of context.
By the end of this topic you will be able to:
  • distinguish an OLTP workload from an OLAP one and say why one schema cannot serve both well;
  • identify the fact table and the dimension tables in a design, and state the grain;
  • build a star schema and write aggregate queries against it;
  • explain why warehouses deliberately denormalize;
  • handle changing descriptive data with slowly changing dimensions (Type 1 vs Type 2).

1. Two very different jobs: OLTP vs OLAP

You already know how to design a normalized schema, add indexes and wrap changes in transactions. Those skills serve OLTP — Online Transaction Processing — where the database backs a running application: a checkout, a booking, a bank transfer. The workload is many tiny reads and writes, each touching a handful of rows, all needing to be correct right now.

OLAP — Online Analytical Processing — is the reporting and analytics side: "revenue by category by quarter", "the ten cities with the fastest-growing sales", "average basket size on weekends". A single such query may read millions of historical rows, group and aggregate them, and it does not need this second's newest order — data that is a few hours old is fine.

AspectOLTP (the app database)OLAP (the warehouse)
Typical queryread/insert a few rows by keyscan and aggregate millions of rows
Writesconstant, small, one row at a timebulk loads on a schedule (nightly / hourly)
Schema goalnormalized, no redundancydenormalized, easy to aggregate
Rows per query1 to a fewthousands to millions
Usersthe application, end customersanalysts, dashboards, reports
Freshnessmust be up to the millisecondhours-old data is acceptable

The two workloads want opposite things, so mature organisations keep them apart: the app writes to its OLTP database, and a periodic ETL (Extract, Transform, Load) job copies and reshapes that data into a separate warehouse for OLAP. Running heavy analytics directly on the live OLTP database competes with real customers for locks and buffer memory, and can slow checkout to a crawl.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers