OLTP and OLAP: one database cannot do both
Everything in this course so far has been one workload: a user does a thing, a handful of rows change, an answer comes back in milliseconds. That workload has a name — OLTP, online transaction processing — and Tier 3 built you a very good machine for it.
Then someone from finance asks: "revenue by product category by week, last two years, split by whether the customer was new." That query touches four billion rows, returns forty, and takes ninety seconds. It is not a bad query. It is a different workload, and the machine you built is the wrong machine for it.
The two shapes, side by side
| OLTP | OLAP | |
| Query count | Thousands per second | A few per minute |
| Rows touched per query | One, or a few | Billions |
| Columns touched | All of them | Three or four |
| Access | Point lookup by key | Full scan with filters |
| What matters | Latency, p99 | Throughput, cost per scan |
| Writes | Constant, tiny, transactional | Bulk, append, periodic |
| Data age | Now | Two years of history |
Look at the third row in particular, because it is the one that decides the storage engine. OLTP reads whole records; OLAP reads narrow slices of enormous ones. Lesson 7.02 is entirely about what falls out of that.
Four ways the analytical query hurts the transactional database
It is not simply that the big query is slow. It is that running it where your users live damages them:
- It evicts the working set. Your database keeps hot pages in memory — that is why point lookups are fast. A scan of four billion rows pulls every one of those pages through the buffer pool and throws your hot data out. The scan finishes; your p99 stays broken for the next twenty minutes while the cache refills. This is Tier 4's cache-eviction lesson, happening inside your database without anyone choosing it.
- It holds a snapshot open. Under MVCC, a long-running reader forces the database to retain every row version that existed when it started. Ninety seconds of scanning means ninety seconds of accumulated garbage that vacuum cannot reclaim — and on a busy table, that bloat outlives the query.
- It competes for the same finite resources. The same CPU, the same disk queue, the same connection pool. Lesson 13.27's dojo point in production: the analytical query occupies connections that checkout needs, and saturation arrives long before anything looks broken.
- Its indexes are useless. Tier 3's B-Tree is built for selectivity — find the few rows out of many. A query that reads 60% of the table is faster with no index at all, so all that carefully-tuned index machinery sits there being maintained on every write and used by nothing.
"Just add a read replica" — half right, and worth knowing which half
The instinctive fix is to point the reporting query at a follower. It genuinely solves problems one and three: the scan no longer competes with user traffic, and the primary's buffer pool stays intact.
It solves nothing about the fourth, because a replica is the same storage engine holding the same rows in the same layout. The query is still reading sixty columns to aggregate three, still scanning a row store, still ninety seconds. And it introduces a new failure: replication lag balloons while the replica is busy, so your failover target is now behind.
So the honest rule, and it is the answer to a question people ask constantly:
- Operational reporting — this week's orders, an admin screen, a customer support view over recent rows — belongs on a replica. Same data model, modest volumes, no pipeline to build. Do this and stop.
- Analytics — years of history, wide aggregations, joins across domains, the numbers the business is steered by — needs a different engine and therefore a copy. That copy is the rest of this tier.
What "a different engine" implies
The moment you accept a second store, three things become architecture rather than plumbing, and each gets its own lesson:
- Something must move the data. A pipeline — batch or streaming, and that is a real decision with real consequences (7.03). It will use the tools Tier 6 gave you: change data capture, event logs, the outbox.
- The copy is stale, by design. How stale is a product decision, not a technical accident. "Yesterday" is a legitimate and often correct answer.
- The copy has a schema someone must own. Which is where the numbers start disagreeing (7.05).
A note on the products that claim to do both — HTAP, hybrid engines, "one database for everything". The good ones are real, and they work by keeping two representations internally: a row store for writes, a column store for scans, kept in sync for you. That is a genuine convenience and it removes the pipeline. It does not remove the two machines; it moves the boundary into a vendor's configuration file, where you will meet it again as a tuning problem. Judge the claim by asking where the second copy lives, because there is always a second copy.
Running the month-end report against the production primary because "it is only once a month". Once a month is the end of the month — the day with the highest transaction volume of the cycle, when finance needs the number and users need the service. The query that has been harmlessly slow all year picks precisely that day to evict your working set. If a report exists, it has a schedule; the schedule is when it will hurt.