Interview: the bestsellers report now takes nine minutes
A join left SQL and became one catalog call per SKU. Bulk the lookup, snapshot the name on the sale, and stop pretending a foreign key can cross databases.
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: 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
How names are loaded one call per SKU one bulk call name on the sale catalog calls where the join runs report service
The monthly bestsellers report now takes nine minutes
Products moved to their own database. The report now calls catalog once per SKU. join in the app bulk read snapshot column monthly cache A monthly report went from seconds to nine minutes. The SQL join became a loop of 40 HTTP calls.
Bestsellers email is still running at lunch
It took seconds. Since the catalog split, about nine minutes. It sometimes times out. Logs: 40 SKUs, then 40 one-by-one GETs to catalog. 1 SELECT catalog calls 2 this quarter Before the split One SELECT. The planner joins sales and products. After the split One query, then a loop of 40 HTTP calls. Restated: the join still happens. It moved from the planner into a loop.
Four checks, in order
Does a join still exist? Find every product-name lookup. Yes. It is a loop of HTTP calls after the sales query. Is the lookup shaped for a set? Read the catalog API. Is the name needed live? Ask what the report is for. No. It covers last month. The name at sale time is the honest value. Does it hold at 4,000 SKUs? Multiply the round trips. No. Monthly survives 40 calls. A daily full-catalog job will not.
Pick the shape before the model writes the client
Turns N lookups into one capped call. A historical report wants the name from sale time. Bulk API is a bridge, not the permanent join. calls · loop per SKU call · bulk lookup calls · name on the sale
Say these without the model
Why is this slower than the old SELECT even after you bulk it? Bulk removes the N, but the join still spans two systems. Before: one engine read two local indexes. Now: a query, a network hop, another query, then merging in the app. Fine for a monthly email. Maybe not for a page view. one engine vs two bulk removes N, not the hop fit fix to cadence Sales query Network hop Catalog query Merge in app Four steps where SQL needed one. Someone wants a foreign key from sales.sku to products.sku across the two databases. What do you say? Not possible: a foreign key only works inside one database. Check at write time: catalog must know the SKU when the sale is saved. Or store a snapshot, and stop assuming the live row exists. A nightly orphan report is a check, not a constraint. FK is local check at write time a job is not a constraint Nightly orphan job Finds bad rows after they exist. Check at write time Rejects the bad sale before it is saved.
Finance wants the report fast and the names current
What do you ship for this monthly job? Snapshot the name on the sale, bulk-lookup until backfill finishes One query again, and renames do not rewrite last month. Bulk covers older rows. Report time Honest history Live rename on old rows Only the bulk endpoint One round trip. But reports still need catalog up, and renames rewrite history. Put products back in the sales database Fast again, but catalog loses ownership. The next split repeats this ticket.
Did you show these?
The join moved into the app One bulk call, not a loop Name stored on the sale No foreign key across databases Fix fits a monthly job
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.