Every application database answers two very different kinds of questions. The first kind is "create this order", "show me order 4812", "mark it as paid". The second kind is "what was revenue per region per month over the last two years?". Both are SQL, both touch the same data, but they stress a database in opposite ways. That is why the industry has three names: OLTP, OLAP and HTAP.
OLTP: online transaction processing
OLTP is the workload behind the app itself. Many users, many small requests, each one reading or writing a handful of rows found by key.
- Typical query:
SELECT * FROM orders WHERE id = 4812;or anINSERTof one order with its lines. - What matters: low latency per request, high concurrency, and correctness under concurrent writes (transactions, ACID, constraints).
- Storage: usually row-oriented. A whole row sits together on disk, so fetching or updating one order is one small read or write. B-tree indexes find rows by key quickly.
- Schema: normalized, so each fact lives in one place and updates stay consistent.
- Examples: PostgreSQL, MySQL, SQL Server, Oracle, SQLite in an app.
OLAP: online analytical processing
OLAP is the workload behind reports, dashboards and data science. Few users, few queries, but each query scans millions or billions of rows and reads only a few columns.
- Typical query:
SELECT region, date_trunc('month', created_at), sum(total) FROM orders GROUP BY 1, 2; - What matters: scan throughput. Reading as little data as possible and processing it fast.
- Storage: column-oriented. All values of
totalare stored together, then all values ofregion. A query that needs 3 columns out of 40 reads only those 3. Similar values next to each other also compress very well. - Execution: vectorized processing (working on batches of values at once) and often parallel across many cores or machines.
- Schema: denormalized or star schemas (a fact table plus dimension tables), loaded in bulk by ETL or ELT pipelines.
- Examples: ClickHouse, DuckDB, Snowflake, BigQuery, Amazon Redshift, Apache Druid.
The price: single-row updates and point lookups are slow or awkward in a column store, because one row is spread across many column files.
HTAP: hybrid transactional/analytical processing
The classic setup is two systems: an OLTP database for the app, and a pipeline that copies data into a warehouse every hour or every night. Reports are therefore always a bit stale, and the pipeline is one more thing to run.
HTAP systems try to serve both workloads from one system, on fresh data. The usual trick is to keep two representations of the same data: a row store for transactions and a column store (or columnar replica) for analytics, kept in sync automatically. The optimizer sends point lookups to the row side and big scans to the column side.
- What matters: fresh analytics without a separate pipeline, while keeping analytical queries from slowing down transactions.
- Examples: TiDB (TiKV row storage plus TiFlash columnar replicas), SingleStore, Oracle Database In-Memory, SQL Server with columnstore indexes on transactional tables, and the AlloyDB columnar engine.
The price: more complex engines, usually a commercial or less common product, and you still need to watch resource isolation. HTAP does not make a full warehouse with years of history from many sources unnecessary.
Side by side
| OLTP | OLAP | HTAP | |
|---|---|---|---|
| Typical query | Read or write a few rows by key | Aggregate millions of rows | Both, on one system |
| Users | Many, concurrent | Few analysts, dashboards | Both |
| Storage layout | Row-oriented | Column-oriented | Row plus columnar copy |
| Latency goal | Milliseconds per request | Seconds per big query | Milliseconds and seconds |
| Data freshness | Live | Minutes to a day behind | Near real time |
| Schema | Normalized | Star or denormalized | Normalized |
| Examples | PostgreSQL, MySQL | ClickHouse, Snowflake, BigQuery | TiDB, SingleStore |
Common mistakes
Running heavy reports on the production primary. A big GROUP BY over the orders table competes with checkout traffic for CPU, memory and I/O. A first step is a read replica for reports; the next is a real analytical store.
Using a warehouse as an app backend. Column stores are built for scans. Thousands of small UPDATE statements per second or "fetch one user by id" in a hot path are a poor fit, and some cloud warehouses also bill per query or per data scanned.
Choosing HTAP to avoid thinking about data. If you need history from ten sources, data cleaning and modeling, you still want a warehouse. HTAP shines when the analytics are mostly about the operational data itself and need to be fresh.
Forgetting that PostgreSQL can stretch. For modest data sizes, good indexes, materialized views and a replica often cover reporting for a long time before a separate OLAP system is needed.
When to pick which
- OLTP when you are building the application: users signing up, placing orders, updating records. This is your default primary database.
- OLAP when questions span large history: dashboards, business intelligence, product analytics, ad hoc analysis. Feed it from your OLTP database through a pipeline or change data capture. For local analysis of files, an embedded engine like DuckDB is often enough.
- HTAP when the business needs analytics on live operational data (fraud checks, real-time dashboards on current orders, inventory views) and running a separate pipeline is the main pain.
Most teams end up with OLTP plus OLAP, connected by a pipeline. HTAP is a way to remove that pipeline for the cases where freshness matters most.
In short
OLTP is many small, key-based reads and writes on row storage. OLAP is few large scans over column storage. HTAP keeps both layouts in one system so analytics run on fresh data. Pick by the shape of your queries, not by the brand.
Watch the animated version: https://youtu.be/0ERCvw2QrYo
Originally published at abdeldjalilchougui.biz.
Top comments (0)