Interview: an analyst query locked checkout

Finance was granted every table in the service database. Publish a small reporting table the service owns, and treat that schema as an API.

More on Ticket interviews

Keep learning

The analyst query locked checkout for four minutes

Finance got direct SQL access to the orders database. One join stalled checkout. hide internal tables push a subset the report schema is an API no prod credentials Checkout p99 hit 8 s during a finance report Analysts query the live service database directly

Checkout timed out while finance ran a report

At 09:12 checkout p99 crossed 8 seconds. A finance join on orders and payments had run for four minutes. The shared analyst login can read every table, even the outbox. lock wait 4 min tables visible ad hoc Restated: an internal database is used as a public SQL endpoint. A report can stall the writer.

What they were given, and what they needed

The grant is the bug. The query is a reasonable question asked in the wrong database. The service pushes a row it is willing to support. Finance queries only this table. What they got SELECT on every table: orders, payments, outbox, migrations. What they needed Four columns of order history: id, date, amount, status.

Four checks, in order

Does a reporting endpoint exist? look for a DB owned for outside reads No. Finance connects to the service database. Is the grant as small as the question? compare the SELECT to the privileges They need two columns of history. They can read every table. Is the internal schema treated as stable? ask who fixes reports after a rename Nobody. The next migration breaks every saved report. Does it hold on a busy morning? a long SELECT on the primary It competes with checkout. A replica helps load but still leaks the schema. Protects checkout Hides internal schema Grant on the primary (today) Read replica, same grants Reporting DB with order_facts Only a published subset fixes both problems.

You design the published table. The model writes the job.

Order changes orders service Upsert or outbox same transaction reporting DB Finance SQL only this table The service owns and pushes the data. Finance never touches orders. Removes the credential, instead of moving the leak to a replica. Publishes a subset with a schema the service promises to keep. Names who writes the reporting row, so it cannot drift. Renames go through a view, like an API version.

Say these without the model

Why is a read replica of the service database the wrong end state? Load moves off the primary. Reports still read internal tables. Reporting DB Own schema, maybe own engine. Only what you support. It fixes load, not coupling (reports tied to internal tables). A rename in the service still breaks every report. Fine as a bridge while you build the real fix. A reporting DB exposes only a schema you promise to keep. replica helps load schema is the coupling published subset The upsert to reporting fails after the order commits. What did the customer experience? Order commits Upsert fails Report lags Outbox retries That is a lag bug, not a lost checkout. To keep them together, upsert in the same local transaction, or use an outbox. Do not add a distributed transaction to hide the lag. checkout already committed same database or outbox no distributed transaction Finance wants every column, because they do not know what they will ask next. What do you publish? Every column Becomes the internal schema with a new name. Questions → facts Publish what they ask. Add more like an API change. The facts behind the questions they actually ask. A wide table you won’t maintain is the internal schema renamed. New questions are endpoint changes, reviewed like API changes. questions first a supported schema API change, not a grant

They need SQL this week

What do you give finance on Monday? Revoke the grant. Publish order_facts. Replica only as a bridge. Reports run on a small table you own, and the schema can change. A dated replica login covers the gap. Checkout protected Schema freedom Ad hoc power Read replica and the same grants The lock leaves the primary. The next migration still breaks their queries. statement_timeout on finance_ro and leave the grant Long queries die at 30 s. Internal tables stay visible, and short queries can still block.

Did you show these?

Revoked access to the internal schema Published a service-owned subset Treated that table like an API Used a replica only as a bridge Refused a distributed transaction

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.