Interview: the query is fast in staging and slow in production

Same SQL, wider rows, a working set that no longer fits, synchronous replication, and a spike. Price the factor, then change that one thing.

More on Ticket interviews

Keep learning

The query is fast in staging and slow in production

Same SQL, very different speed. This tests the factors around the query, not the query itself. row width working set Same query: 40 ms in staging, 700 ms in prod. Wider rows, more data, sync replication, distance, hourly spikes.

GET /order is 40 ms in staging and 700 ms in prod

Staging: 50k narrow rows. Prod: 80M rows with a JSON payload. Readers in three regions. The primary lives in one. Sync replication turned on last week. Traffic spikes 10× each hour. prod p99 80 million 50k rows · narrow row · one region · async · flat traffic 80M rows · JSON payload · 3 regions · sync commit · 10× spikes Restated: the SQL did not change. The world around it did. Name the factor you pay for.

Four checks, in order

Did the row get wider? The payload moved off the main page. One lookup is now two reads. Did the working set stop fitting? Compare cache hit rate at 50k vs 80M. Staging fits in memory. Production misses and goes to disk. Did consistency or distance get added? Check replication mode and client region. Each commit now waits for another zone. Far readers pay a round trip. Is 700 ms steady state or the spike? Split top-of-hour from the rest. Baseline is 180 ms. The 700 ms is the hourly spike. prod baseline prod at minute :00 One p99 hides two problems: a slower baseline and a spike.

You price each factor instead of rewriting the query

Row width Data volume Working set no longer fits RAM. Locks and queues peak together. Sync commit waits for a second zone. Far clients pay a network round trip. Spiky load 10× for ten minutes each hour. Six costs the SQL text never shows. Make the AI price each one. Refuses a query rewrite for an environment gap. Splits one p99 into baseline and spike. Makes consistency and distance explicit, measurable costs. Asks for one change, aimed at the biggest factor.

Say these without the model

How do item size and item type change a lookup that “returns one row”? row shape Wider rows mean more pages read for the same lookup. A narrow row packs many records per page (disk block). JSON or blob columns need parsing and are hard to index inside. A staging stub column does not test the real production row. rows per page staging row is fake Narrow row Many rows per page → 1 read Wide / off-page row Row + payload pages → 2+ reads What does dataset size change even when the plan stays an index lookup? Mostly whether the hot data still fits in memory. The index gets a little taller. That cost is small. At 80M rows, cache misses go to disk. That cost is large. Row-count estimates go stale, so the plan can change without a deploy. working set vs RAM index height is small stats drift +1 page taller index disk read each cache miss How do consistency and geography show up in latency? distance and durability Both add network waits to the request path. Sync commit waits for another copy before returning. A far client pays a round trip staging never paid. High availability means extra acks: you buy failover with latency. sync commit waits HA costs latency other region + ocean RTT Standby ack + zone RTT Commit returns Why is “average concurrency” the wrong model of this traffic? Because the system breaks at the peak, not the average. At 10× load, queues form and latency is the queue. Connections, locks and disk all peak together. Size for the spike you accept, or shed load. peak not average test the traffic shape

You can relax one requirement

The 700 ms is mostly commit wait plus cross-region reads. What do you change? Local reads on a replica, synchronous commit only for pay Order reads go local and accept slight lag. Payments still wait for the second zone. Read latency Durability of pay Stale order page Turn off synchronous replication entirely Commits get faster. A lost primary can now lose recent transactions. Move the primary to the busiest region and keep sync on

Have one ready

Tell me about a query that was fast until the data or the deployment changed. What changed Width, volume, region or durability. Not the SQL. How you saw it The metric that isolated that factor. What you refused A rewrite that ignored that factor.

Did you show these?

Fits in memory ≠ SQL text Spike split from baseline

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.