Interview: one shard is at 96% CPU and the other is idle
A surname range does not spread writes. Partition by a stable id, hide the shard, and answer cross-shard questions off the request path.
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: 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
850 customers, two shards Partition key surname A–M / N–Z customer id shard A shard B Nguyen and Wang both land on N–Z. One shard takes most writes. The signup id spreads rows evenly. It never changes, so a rename never moves a row.
Shard B is at 96% CPU. Shard A is idle.
Customers were split across shards by surname letter. One shard got almost all the writes. even spread stable key partial outage Surname letters are uneven, and names can change. Shard by the signup id: even, stable, one hop per lookup.
Signups in half the alphabet time out
Signups with surnames N–Z fail. A–M is fine. Split: A–M on shard A, N–Z on shard B. The “customers over 18” count differs between reports. shard B CPU shard A CPU Restated: the key does not spread load. Cross-customer queries have no single home.
Four checks, in order
Does the key spread writes? count rows per shard No. Two common surnames sit after N. Is the key stable? ask what a name change does No. A rename moves the row. The signup id never changes. Can you fetch one customer? hash the key from the request Yes, with the id. One shard, no scan. What fails when shard B dies? count customers living there Everyone on B. A shard is a slice, not a backup copy. Rows and writes spread out. Value never changes. Each request carries it. Small blast What a good partition key needs. Surname fails the first two.
You pick the key. The model does not invent a range.
Chooses a key that spreads and never moves. Hides the shard from callers. Keeps “even load” apart from “survive a dead shard”.
Say these without the model
Shard B dies. What percentage of signups fail, and what would a replica change? Even split: about half. This split: most of the busy traffic. A replica does not move load to the idle shard. Partitions scale. Copies survive failure. You usually want both. a slice fails replica ≠ rebalance scale vs copies Splits data to scale. A dead shard loses its slice. Copies a slice. Keeps it up when one copy dies. How do you answer “how many customers are over 18?” Ask every shard and sum, or precompute it in a reporting table. A point read hits one shard. This question hits all of them. Fan-out on each page view adds every shard’s latency. Keep it off the customer-facing path. point read vs scatter sum or precompute not on the hot path Query A + B per request. Slowest shard sets the pace. Reporting table Updated in the background. One cheap read. The new key is right, and the data is on the old shards. How do you move it? Online: new writes by id, dual-read, copy in the background. Dual-read: try the id shard, fall back to the surname shard. Cut reads over at zero lag. Drop the surname route last. Offline rebuild means a multi-day outage. Say so first. background copy offline rebuild is costly New writes by id id, then surname Background copy Cut over Drop old route
Growth wants the timeouts gone today
What do you do first? New rows by customer id, dual-read, copy the rest New signups spread at once. Old rows move without a freeze. Even writes Caller changes Move the busiest surnames to shard A by hand CPU drops until the next popular name lands on B. The key is still wrong. Take the database down and reshuffle over a weekend Clean layout, but a real outage. Only if dual-read is impossible and the business agrees.
Did you show these?
Rejected letter ranges: uneven Picked the stable signup id Kept sharding inside the service Cross-shard count off the request path
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.