Interview: everything got slow and the disk keeps growing
A forgotten transaction blocks purge. MVCC hidden columns, read views, undo chains, history list length, and why DELETE never shrinks the file.
More on Ticket interviews
- Database Interviews in the AI Era: The Ticket Format
- Interview: the same job runs twice
- Deadlock Interview Question: Find and Fix It in SQL
- Slow Query Interview: One Keyword Made It 40× Slower
- Interview: rate limit is 2/min, 30 requests get through
- Interview: “just add an index” slowed ingestion
- Interview: “I changed my name, refresh shows the old one”
- Interview: importing 10M rows takes six hours
- Lost Update Interview: Wallet Balance Wrong Under Load
- Interview: API p99 jumps 10× every night at 2 am
- Interview: profile lookups got 40× slower, writes are fine
- Interview: inserts stall, and only one page is hot
- Interview: the write succeeded, the next read shows an empty cart
- Interview: inventory stayed locked after the coordinator restarted
- Interview: for four minutes, both regions took orders
- Interview: shoes show a 0% discount, then the report crashes
- Interview: March gained $50 after the deploy, and the months don’t add up
- Interview: the new branch’s dashboard takes 38 seconds
- Interview: the index is right there, make Postgres use it
- Interview: warehouse and checkout overwrite the same order
- Interview: the bestsellers report now takes nine minutes
- Interview: an analyst query locked checkout
- Interview: the member is active and the email went out twice
- Interview: one shard is at 96% CPU and the other is idle
- Interview: the menu is slow, and the proposal is event sourcing
- Interview: four dashboards disagree about whether the database is slow
- Interview: checkout got slow the hour the warehouse job started
- Interview: the query is fast in staging and slow in production
- Interview: login looks up an email and reads the whole customers table
- Interview: the proposal splits one database into three shards
- Interview: the order page joins four tables on every view
- Interview: every page view is a read-write query on the leader
- Interview: Sarah and John both debit version 1
- Interview: the CTO read a blog post and wants to move Postgres to MySQL
- Interview: one table takes 50,000 writes a second, another feeds dashboards. Which engine for each?
- Interview: EU users wait on the ocean for every write, can both regions take writes?
- Interview: users search cars by color, but the table is sharded by car id
- Interview: we added a fourth node and most of the data moved
- Interview: two people book the same room at noon, both get a confirmation
- Interview: everything is on the strongest consistency and far requests crawl
- Interview: the order is saved, the message to search and email never left
- Interview: rename a column on a 600 GB table while 30 servers keep serving traffic
- Interview: orders go to 16 shards in 2 regions, what should the order id be?
- Interview: one celebrity posts, and every timeline in the app slows down
- Interview: 5,000 customers share one database, and one of them slows down everyone
Keep learning
Overview
+10 updates Version chain in the data page undo log · report sees this versions kept undo hops for the report’s read No old snapshot open: purge cleans old versions soon after commit. Chains stay short.
Everything got slow since Monday, and the disk keeps growing
No deploy, no traffic change. One forgotten transaction is blocking all history cleanup. undo log read view history list length long transactions An idle open transaction blocks purge of old versions.
Slow queries everywhere, undo tablespace at 180 GB
DBA on-call Since Monday, primary-key reads are 5–20× slower. Undo storage grew from 2 GB to 180 GB. No deploys since Friday. Traffic is normal. History list length undo size PK read p99 Restated: old row versions (undo, kept for old readers) are not cleaned up, and reads pay for it.
Look for the oldest open transaction
Opened Monday 09:02, still open, running nothing. A BI notebook ran BEGIN + one query, then went to sleep. INNODB STATUS Purge is stuck right behind that old transaction. BI notebook App traffic Mon 09:02 — snapshot taken (idle, never commits) connection sleeps for 3 days UPDATE stock … × millions each leaves an old version in undo purge trx < 421993 cannot pass the open snapshot walks longer version chains One idle snapshot from Monday pins every version written since.
Connect the symptoms
What is the history list length? INNODB STATUS 41M undo records waiting for purge. Normal is thousands. Why can’t purge clean them? “Purge done for trx < 421993” Purge keeps anything an open snapshot might need. Trx 421993 dates from Monday. Who owns that transaction? innodb_trx + processlist An analytics notebook: BEGIN, one SELECT, idle three days. Why are normal reads slower? Think about version chains. Hot rows have long undo chains to check. Undo pages also crowd the cache.
Fix now, then prevent
Kill now KILL 88412 — it only read, so rollback is instant. Fresh snapshots BI uses autocommit + READ COMMITTED. Idle timeout Kills an idle read-only transaction, so rollback is instant. Prevents recurrence with settings, a timeout and alerts. Moves long reads to a replica, away from primary purge.
No AI from here
Each row has hidden DB_TRX_ID (last writer) and DB_ROLL_PTR (previous version). A read view lists transactions active when the read started. Too-new version? Follow DB_ROLL_PTR back through undo. No row lock needed. hidden columns read view walk the undo chain Row v5 too new for me undo v4 too new undo v3 visible ✓ A reader follows the roll pointer until a version is visible. REPEATABLE READ vs READ COMMITTED: when is the snapshot taken? RR: once per transaction. RC: once per statement. RR (InnoDB default) builds its view at the first read and keeps it. RC takes a fresh view each statement, so it pins nothing between them. That is why this idle RR transaction pins three days of history. REPEATABLE READ One snapshot for the whole transaction. Pins history while open. READ COMMITTED New snapshot per statement. Pins little. Why didn’t the table file shrink after we deleted 100M rows last month? Freed space is reused inside the file, not returned to the OS. Rebuild to reclaim: OPTIMIZE TABLE or ALTER TABLE … FORCE. Undo tablespaces can be truncated once purge catches up. delete-mark + purge reused, not returned rebuild to reclaim Is this a MySQL-only problem? No. PostgreSQL bloats the same way, inside the table itself. A long transaction holds back the xmin horizon (oldest visible point). VACUUM can’t remove dead rows, so tables and indexes grow. Postgres offers idle_in_transaction_session_timeout for exactly this. xmin horizon MySQL / InnoDB Old versions in undo log → purge blocked Old versions in the table → VACUUM blocked Why is killing a big write transaction more dangerous than killing this one? Rollback must undo every change, which can take as long as the work. A 50M-row update may hold locks for hours while rolling back. This one only read, so it has nothing to undo. rollback cost ∝ changes made
Analysts need consistent multi-query reports
How do they get a stable snapshot without hurting production? Run reports on a replica Long snapshots only block purge on the replica. Seconds-old data is fine for reports. Prod safety READ COMMITTED + autocommit Nothing is pinned. But two queries in one report may disagree. Keep it on the primary, with a 10-minute timeout Damage is capped at 10 minutes. Long reports still strain purge at peak. Export nightly to a warehouse Best for heavy analytics. Data is a day old, and it is another pipeline.
Have one ready
Tell me about a time a long-running transaction caused trouble. Slow reads, growing disk. History length, innodb_trx, idle session. Idle in transaction is a bug.
Did you show these?
Knew what history length counts Found the oldest trx Purge can’t pass an open snapshot MVCC: hidden columns, read view, undo RR vs RC snapshot timing Why DELETE doesn’t shrink files Safe kill plus prevention
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.