Interview: four dashboards disagree about whether the database is slow

Average query time is 12 ms and checkout p99 is 900 ms. Separate execution time, latency, throughput, and utilization before you buy a bigger primary.

More on Ticket interviews

Keep learning

Four dashboards disagree about whether the database is slow

Average query time is 12 ms and CPU is 28%. Checkout p99 is 900 ms. execution time Checkout takes ~1 s, yet database dashboards look healthy. Each dashboard reads a different clock, not the user's. Measure p99 of the pay request, then find its wait.

Checkout feels slow. The DBA says the database is fine.

Shoppers wait almost a second on Pay. DB dashboard: 12 ms average query, 2,000 queries/s, CPU 28%. Proposal: buy a bigger primary. No wait data attached. avg query checkout p99 2,000 qps Execution time How long the engine worked on one statement. How long the shopper waited. The real complaint. How much work finishes per second. CPU 28% How busy one resource is. Restated: four clocks, and only one is what the user feels.

Four checks, in order

Is 12 ms the time the user waited? Ask where the timer starts and stops. No. It is one average statement inside the engine. Pool wait, network and other statements are missing. Does throughput prove the database keeps up? Compare arrivals, completions, queue depth. No. A saturated system still finishes 2,000/s while new requests queue. Does 28% CPU mean spare capacity? Check wait events, not only CPU. No. A session can wait on a lock or disk flush while CPU idles. Which number matches the complaint? Plot pay-request latency. p99 of the pay request. The 12 ms average is mostly cheap, unrelated statements. Pool wait get a connection each round trip 8 statements Lock / flush waits no CPU used what the shopper feels One request is many clocks added together.

You name the metric before anyone changes hardware

Separates the engine’s clock from the user’s clock. No scale-up until the wait event is known. Names the percentile the ticket is about.

Say these without the model

What is query execution time, and what does it leave out? execution time Time the engine spent on one statement. Nothing before or after it. It covers planning, reading pages, computing and logging. It skips pool wait, network trips, and app work between statements. Eight 12 ms statements already make ~100 ms per request. engine clock vs request statements add up pool and network are outside How can throughput be high while latency is bad? With enough running at once, 2,000/s can each take 900 ms. If arrivals beat completions, throughput flattens and the queue grows. The qps graph looks calm. The queue does not. completions vs arrivals queue growth qps graph Flat at 2,000. Looks calm. Arrivals > completions. Wait time keeps growing. Why is low CPU not evidence that the database is fine? Low CPU only rules out a CPU bottleneck. CPU, disk, memory and connections are separate resources. Lock waits, log flushes and replica acks take time but almost no CPU. Ask for the wait event (what the session is blocked on). which resource wait events CPU rules out only CPU Lock wait Blocked by another transaction. Log flush Waiting for fsync to disk. Replica ack Waiting for sync replication. Which of the four would you alert on for checkout, and why not the others? what you page on Page on p99 latency of checkout, measured in the app. That is the number in the ticket. Statement execution time is a diagnostic, not the symptom. Throughput and utilization show ceilings, not shopper waits. p99 of the request Page on it? Use for Request p99 latency user symptom Execution time

The proposal is a larger primary

What do you do before the change window? Break the pay request into execution, wait, and network, then fix the wait You may find a lock, missing index or extra round trips. A bigger box cannot shorten a lock wait. User latency explained Money spent blind Time to a wrong fix Scale the primary because CPU headroom means it will help You buy cores for work that is waiting, not computing. p99 stays near 900 ms. Drop the statement timeout so slow queries stop It caps damage but explains nothing. Timeouts are a backstop, not a diagnosis.

Have one ready

Tell me about a time the database looked idle and the product was slow. The number Dashboard clock vs user clock. The wait What ate the time without CPU. The fix What changed once the clocks were split.

Did you show these?

Execution time ≠ end-to-end latency Throughput is not a latency metric Named a non-CPU wait Paged on request p99 No scale-up before the wait event

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.