Interview: the proposal splits one database into three shards
Shard by customer_id so checkout stays one local transaction. The admin query becomes a scatter, and a cross-shard transaction is not a shortcut.
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: 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 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 proposal splits one database into three shards
One primary holds every order. The plan: three shards (separate databases) and a router. shard key scatter query One orders database is hitting its ceiling Sharding breaks the admin join and has no rebalance plan
Orders primary is the ceiling. The doc says three shards.
Writes and storage grow with customers. One machine is the limit. The doc hashes customer_id into three shards. The admin “all orders today” join has no plan after the split. 3 proposed admin page one SQL join order + payment Has customer_id Checkout: one shard, one local transaction. No customer_id “All orders today”: ask every shard, merge in the app. Restated: sharding splits the data. It is not faster SQL. Name the query that must change.
Four checks, in order
Is one machine actually the limit? Would a replica, archive or index help? Yes, it is real. Writes and storage both climb with customers. Does the key put one customer on one shard? Trace an order and its payment. Yes. Both carry customer_id, so checkout stays on one shard. Which query touches every shard? Find queries without customer_id. “All orders today”. It becomes three queries plus an app-side merge. What happens when a shard fills? Ask how a customer moves. No rebalance plan. Three shards postpone the ceiling, not remove it. Admin page all orders today Query shard 1, 2, 3 Merge in app join by hand Maybe inconsistent shards at different moments What one SQL join turns into after the split.
You keep the transaction on one shard
Both transaction tables land on the same shard. Admin query becomes a scatter, kept off checkout. Demands a rebalance story before calling it a design.
Say these without the model
What does a shard buy that a bigger primary does not? why split Bigger primary Raises the ceiling once. SQL stays simple. Raise it again per shard added. SQL gets harder. Write throughput and storage beyond one machine. Each shard has its own log, memory cache and disk. It won’t make one lookup faster than a good index would. writes and storage another ceiling later not a fix for one slow lookup Why is the shard key the whole design? Query has key One hop, one shard. Query lacks key Every shard. Skewed key One hot shard, others idle. It decides where every row lives, and so which queries stay cheap. customer_id works: an order and its payment share it. Order id would split an order from its payment. A skewed key (one big tenant) makes a hot shard. one hop vs all shards key matches the transaction hot key What happened to the join and the transaction? what you lose Cross-shard joins, transactions and foreign keys all stop working. Joins become scatter-and-merge in the app, possibly inconsistent. Cross-shard writes need a distributed transaction. Design them away. Foreign keys stop at the shard boundary. scatter and merge foreign keys stop How do you add a fourth shard later? rows move, hash mod 3 → mod 4 rows move, consistent hash or directory Move some rows, with a rule for reads and writes mid-move. hash mod 3 → mod 4 moves most rows. Consistent hashing or a customer→shard directory moves far fewer. No move plan means a one-time resize with worse SQL. rows move modulo reshuffles directory or consistent hash
The admin page is the objection in the review
Checkout fits on one shard. The admin page does not. What do you ship? Shard writes by customer_id. Build the admin page from a lagging replica or a daily table. Checkout stays local. The admin question is answered off-path and may be late. Write ceiling Checkout complexity Admin freshness Keep one database and raise the instance size SQL stays simple. Buys a year, then the ceiling returns. Three shards, and a two-phase commit for any query that spans them Glues the shards back together. A coordinator failure stalls checkout.
Have one ready
When would you refuse to shard? The query What becomes a fan-out. The key Does one transaction share it? The alternative Replica, archive or index first.
Did you show these?
Sharding lifts writes and storage Order + payment on one shard Admin query → scatter or offline table No cross-shard transaction on checkout How rows move when adding a shard
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.