OLTP vs OLAP

Transaction processing and analytics read data in opposite ways. This topic covers why they usually live in separate systems, how data moves between them, and how a warehouse is laid out.

Overview

Databases serve two very different kinds of work. Online transaction processing (OLTP) is the work an application does for its users: place an order, update a profile, read one account. Online analytical processing (OLAP) is the work analysts and dashboards do: total revenue by region last quarter, or the conversion rate per campaign. The first touches a few rows many times a second. The second reads millions of rows to produce one small answer.

Because the access patterns are opposite, the best storage layout for each is opposite too. That is why most companies copy data from their operational databases into a separate analytical system, a data warehouse.

Two workloads

The two workloads differ on almost every axis. OLTP queries come from the application, on behalf of its users. A typical one reads or writes a few rows by key, and writes arrive as many small inserts and updates. What matters is low latency per request and correctness under concurrency. The data is the current state, and the usual storage is row-oriented, with B-tree indexes. Examples are PostgreSQL or MySQL behind an app.

OLAP queries come from analysts, reports and dashboards. A typical one scans many rows and aggregates a few columns, and writes arrive as bulk loads or a stream of appends. What matters is throughput over large scans. The data is history over months or years, and the usual storage is column-oriented and compressed, as in Amazon Redshift or Google BigQuery.

Key concepts

  • OLTP
  • OLAP
  • Data warehouse
  • ETL and ELT
  • Fact table
  • Dimension table
  • Star schema
  • Column-oriented storage

Interview questions

  • Why is column-oriented storage better for analytics than row-oriented storage?
  • Design the analytics side of an online store.
  • Can you run analytics on a PostgreSQL read replica instead of building a warehouse?
  • What is a star schema, and why do warehouses use it?
  • ETL or ELT: what is the difference, and which would you choose?

Sign up free to read the full topic

More DDIA topics

Start free on Cariara · Coding problems · System design studio