Interview: the menu is slow, and the proposal is event sourcing
Reads are 98% of the load and the query is one SELECT. Put it on a replica before building a second model, and keep that choice inside the service.
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: the bestsellers report now takes nine minutes
- 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: 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
The menu page is slow, and the proposal is event sourcing
read replica first CQRS is internal measure, then build projection lag Menu p99 is 1.4 s One cheap SELECT floods the primary A read replica behind GET /menu, not event sourcing
Menu p99 is 1.4s. The rewrite is six weeks.
GET /menu is one SELECT. Every page view hits the primary. Writes: about forty item edits a day. A design doc proposes event sourcing. No load test attached. 1 SELECT 6 weeks The proposal Rebuild writes as an event log, project a read model. 6 weeks. The problem Reads flood the primary. Writes are fine. Restated: the primary is doing read work, but the proposal rebuilds the write path.
Four checks, in order
Is the slow part the read or the write? Split query stats by calls. The read. One cheap SELECT, called constantly. Does a replica serve that SELECT? Can the menu be seconds stale? Yes. A sold-out item may linger briefly. That’s acceptable. Does the query need a different shape? Read the SELECT. No. It returns the table as-is. What does an event log add this month? List new failure modes. Projection lag, rebuilds, two models. None beat a replica. of DB time is reads SELECT, no joins load tests in the doc
You pick the smallest move that the numbers support
Fixes the read bottleneck, not the fine write path. Hides the replica behind the existing endpoint. Sets a lag ceiling with a primary fallback. Saves a read model for a query that needs one.
Say these without the model
When would you actually split the read model? Busy primary? add a replica Need a new shape? search, rollup, feed Split read model inside the service Only when reads need a different shape than writes. Examples: a search document, a per-store rollup, a feed. A busy primary alone doesn’t justify it. A replica does that. different question shape hidden inside the service replica first What new ways can the menu be wrong after you project it from events? event sourcing Event log Menu page PriceChanged 9 → 11 GET /menu shows 9 apply PriceChanged catches up shows 11 Lag, projector bugs, and two models that disagree. Projection lag: customers see old prices until it catches up. A projector bug rebuilds wrong rows from a correct log. projection lag two models can disagree The replica is 30 seconds behind during a sale. What do you do on the request? Measure lag. Past your ceiling, that request reads the primary. The primary stays the source of truth. which screen tolerates lag fall back to primary one source of truth
The design doc is already on the calendar
What do you start this week? A replica behind GET /menu, with a lag ceiling Reads leave the primary. Callers don’t change. A read model stays possible later. Primary spared New machinery Stale menu Event log plus a projected menu Six weeks rewriting a write path that wasn’t broken. Adds lag. Cache GET /menu in the app for 30 seconds Fast and cheap. But each instance has its own copy, and deploys start cold. Spares primary Little new machinery Fresh data Replica + lag ceiling Event log + projection 30 s app cache The three options at a glance
Have one ready
Tell me about a data model you did not build. What you measured. Simpler move Replica, index or cache first. The number that would justify more.
Did you show these?
Busy primary ≠ write-model problem Replica first Hidden behind the endpoint Projection lag and rebuild costs Read model only for new query shapes
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.