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

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.