Interview: checkout got slow the hour the warehouse job started
Writes, reads, deletes, and a batch job break a primary in different ways. Move the competing report before you add an index for it.
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
- Interview: everything got slow and the disk keeps growing
- 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: 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
Checkout got slow the hour the warehouse job started
Pay clicks and a nightly batch job share one primary. Each workload type breaks in its own way. competing work Pay p99 doubles every night from 01:00 to 04:00 A report scan and a big purge share checkout’s primary
Pay p99 doubles from 01:00 to 04:00
Nothing shipped. At 01:00 a job purges old orders and rebuilds a report. Both run on the primary. The report is a full table scan. A campaign also raised insert rates this week. orders has 6 indexes. pay p99 6 on orders on primary Campaign inserts Each row updates 6 indexes. Sales report Full scan of orders. Nightly purge Old shipped orders removed. Restated: three workloads share one machine. Name the one hurting checkout first.
Four checks, in order
Is the pain writes maintaining indexes? compare insert cost with the campaign Daytime inserts got pricier as indexes grew. Real, but not the 01:00 cliff. Is the pain a read that misses cache? does the scan evict the buffer pool? Yes. The report pushes hot order pages out of memory. Checkout then reads them from disk. Is the pain deletes fragmenting the table? dead rows and vacuum during the purge The purge leaves dead space and vacuum I/O. Real, but not alone. Are real-time and batch fighting for one resource? both active on the primary at 01:00? Yes. Same disks, same memory, same locks on orders. sales report SELECT … WHERE id=? page in memory: 2 ms SELECT … FROM orders full scan starts scan reads cold pages hot pages pushed out DELETE … 90 days one huge transaction page on disk now: slow
You separate the workloads before you tune one query
Treats the report as a competing workload, not a missing index. Batches the delete so it is never one huge transaction. Refuses an index that would tax every campaign insert. Accepts a slightly stale report in exchange.
Say these without the model
What does a write-heavy workload spend its time on? INSERT row Update each index 6 extra page writes Append log Fight for hot pages and row locks Index maintenance, log writes, and contention on hot pages. Every insert updates the row and every secondary index. More indexes means more page writes per row. Fix: fewer indexes, spread keys, batching. Not a bigger cache. index maintenance lock and page contention log writes What does a read-heavy workload spend its time on? Big scan Hot pages evicted from memory Point lookup hits disk Complex queries and cache misses (pages not in memory). If the working set doesn’t fit in RAM, reads go to disk. One scan can evict the pages fast lookups need. Replicas, covering indexes, caches help reads, not writes. working set vs memory a scan evicts hot pages replicas serve reads Why do heavy deletes make later queries slower? Rows marked dead still take space Indexes bloat Same query reads more pages Dead rows keep taking space until vacuum or purge reclaims them. Indexes still point at dead entries, so everything fragments. One giant delete also blocks cleanup and bloats the log. So delete in batches. dead space index bloat batched deletes What is a competing workload, and why is “tune the slow query” the wrong first move? Real-time request Wants low latency. Small, fast queries. Batch job Wants throughput. Happily uses all disk, memory, locks. Two jobs with different goals sharing the same resources. A perfect index lookup still waits if a neighbour holds the cache. Separate first: report on a replica, purge in batches. Then tune whatever is still slow. same resources, different goals a fast query can still wait separate before you tune
You can only move one job tonight
Which move takes the 01:00 cliff off checkout? Run the report on a replica and batch the purge Checkout stops sharing cache and locks with a scan. Campaign insert cost is a separate daytime issue. Night latency Write amplification Stale report Add a covering index for the sales report Every insert now maintains one more index. The report still competes on the primary. Pause the purge until the campaign ends
Have one ready
Tell me about a slow query that was not the query. The job sharing the machine, and when. Cache, locks, or log: what they fought over.
Did you show these?
Named write amplification from extra indexes Named a scan evicting the hot pages Named dead space as the cost of big deletes Called the night job a competing workload Moved the report before adding an index
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.