← Back to System Design, page 5

system-design-0093 · Easy fresher

What is the difference between OLTP and OLAP systems, and why do companies keep a separate data warehouse instead of running reports on the production database?

OLTP (online transaction processing) systems handle many small, fast reads and writes of individual records, such as placing an order, and need strong consistency. OLAP (online analytical processing) systems run fewer but huge queries that scan and aggregate millions of rows, such as revenue by month. They use different storage layouts (row-oriented versus column-oriented), so analytics run in a separate warehouse fed by ETL or change data capture, keeping heavy reports from slowing down users.

Full answer

OLTP

Examples: placing an order, updating a profile, recording a quiz attempt.

  • Query shape: touch a few rows by key; SELECT * FROM orders WHERE order_id = 812.
  • Many concurrent users, thousands of transactions per second, millisecond latency.
  • Normalised schema to avoid duplicated data; transactions and constraints.
  • Row-oriented storage: all columns of a row are stored together, ideal for reading or updating whole records.
  • Databases: PostgreSQL, MySQL, SQL Server, Oracle.

OLAP

Examples: monthly revenue by country, course completion rates by cohort, which videos learners drop out of.

  • Query shape: scan millions or billions of rows, few columns, with group-by and aggregates.
  • Fewer users (analysts, dashboards); seconds to minutes per query is acceptable.
  • Denormalised star or snowflake schemas: a fact table (enrolments, events) with dimension tables (course, user, date).
  • Column-oriented storage: each column stored together, compressed; a query reading 3 columns skips the other 50.
  • Systems: BigQuery, Snowflake, Redshift, ClickHouse, Databricks.

Why separate them

  1. Performance isolation. A report scanning 500M rows on the production database competes for CPU, memory and disk with checkout queries and slows them down.
  2. Storage layout. Row storage is slow for big scans; column storage is slow for single-row updates. One layout cannot be best for both.
  3. History and integration. A warehouse combines data from many sources (orders, payments, marketing, product events) and keeps years of history that the production database does not need.

Getting data from OLTP to OLAP

  • ETL or ELT: batch jobs extract data (often nightly), transform and load it.
  • Change data capture: stream every change from the production database's log into the warehouse within minutes.

Example

An edtech company keeps enrolments and payments in PostgreSQL (OLTP). Each change streams to a warehouse where analysts ask "what share of learners who watch lesson 3 finish the course?" Running that on PostgreSQL during exam season would slow down every learner's dashboard.

A middle ground

HTAP databases and read replicas can serve light analytics, but heavy, long-running reporting still belongs in a dedicated OLAP system.

By level

Fresher: Explain OLTP as everyday app operations and OLAP as big reports, with one example each. A fresher should say why reports should not run on the live database.

Mid: Compare row and column storage, schema styles and data movement with ETL and CDC. Give a realistic separation example.

Senior: Discuss HTAP options, freshness requirements, cost of warehouse scans, schema design for analytics and governance. Expect clear judgement on when a replica is enough.

Key points

  • OLTP: many small transactional reads and writes by key
  • OLAP: few large scans and aggregations
  • Row storage suits OLTP; column storage suits OLAP
  • Separate warehouses isolate heavy reports from users
  • Data moves by ETL or change data capture

Common mistakes

  • Running heavy reports on the production primary database
  • Assuming one storage layout is best for both workloads
  • Normalising warehouse schemas like transactional ones without reason
  • Ignoring data freshness needs when choosing nightly ETL

Follow-ups

  • What is a star schema?
  • When would a read replica be enough for reporting?
  • How does columnar compression work?

Tips

  • Give one example query of each type
  • Explain row versus column layout simply
  • Mention how data gets to the warehouse

Evaluation rubric

  • Correct definitions and examples
  • Storage layout difference explained
  • Clear reasons for separation
  • Knows ETL and CDC