Design Amazon Shopping Cart - System Design

A shopping cart sounds like a toy problem. “Store a list of item IDs and quantities for a user, let them add and remove, show it back.” You could do it with a row per user and a JSON blob and be done in an afternoon. Then the interviewer starts adding constraints and every easy answer falls over. The cart has to follow the user from their phone to their laptop to the Alexa in the kitchen, and show the same items on all three within a second. It has to survive the user closing the tab and coming back a week later. It has to stay writable during a Prime Day sale when a hundred million people are hammering “add to cart” on the same few thousand doorbusters at the same instant. And - the hard one - the cart cannot lie about inventory: if the warehouse has 100 units of a limited item, you must not let 500 people put it in their cart, walk to checkout, and each expect it to be there. ...

26 min

Design Migrate 1PB of Data to Cloud - System Design

“Move 1PB to the cloud” sounds like a copy job, and people design it like one: point a script at the source, rsync to an S3 bucket, wait. Then the interviewer drops the two numbers that change everything. The link is 10 Gbps. The files are in active use during the migration. Now do the arithmetic: at 10 Gbps, wire-speed and perfect, 1PB takes about 9.5 days of continuous transfer. Real throughput after overhead and contention with production traffic is half that, so ~20 days. And for those 20 days the source data keeps changing underneath you, so whatever you copied on day one is already stale by day two. ...

25 min

Design Slack (Team Messaging) - System Design

People hear “build Slack” and reach for a chat toy: a messages table, a WebSocket, insert on send, push to whoever is connected. That works for a demo and falls apart the instant you write down the real numbers. The largest org has 100K members. A single busy channel in that org - #general, #incidents, #announcements - can have tens of thousands of people watching it live. When someone posts, who do you deliver to, and how? Do you write a copy of that message into 50,000 inboxes (fan-out on write) and drown on a viral post, or do you store it once and make every reader come find it (fan-out on read) and drown on the read side instead? That single question - how a message gets from one sender to N readers - is the spine of the whole design, and Slack’s answer is different from Twitter’s or Facebook’s because Slack’s unit of delivery is the channel, not the follower graph. ...

28 min

Design Ads Management & Display in Social Feed - System Design

Everyone models an ad server as a lookup: “the user opens the feed, we fetch an ad, we show it, done.” The interviewer lets that sit for a moment and then piles on the constraints that make it a real system. There are not ten ads to choose from, there are millions of live campaigns; the best ad for this user has to be chosen from that pool in under 50 milliseconds while the feed is already rendering; advertisers set budgets and if you overspend theirs you eat the cost, if you underspend it you lose their trust and their business; the spend has to be paced evenly across the day, not blown in the first hour; a large fraction of clicks are bots and you must not charge advertisers for them; and all of this runs at 100 billion impressions a day. An ad server is not a lookup. It is a real-time per-impression auction over a targeted candidate set, constrained by budgets and paced over time, with a fraud filter in the loop - and the ad shown is just its output. ...

31 min

Design Distributed Document Editor (Notion / Wikipedia) - System Design

Almost everyone reaches for Google Docs the moment they hear “document editor,” and almost everyone is answering the wrong question. Google Docs is a real-time collaboration problem: two people typing into the same sentence at the same millisecond, operational transforms, CRDTs, convergence. That is a specific and hard sub-problem, and it is not what Notion or Wikipedia are. Notion and Wikipedia are async document systems: you open a page, you edit it, you save it. Someone else might edit it an hour later, or a minute later, but the design does not live or die on sub-200ms convergence of concurrent keystrokes. It lives or dies on three other things - how you store a document made of structured blocks, how you keep a full version history without exploding storage, and how you search across tens of millions of documents fast. ...

26 min

Design Toll Collection (FASTag) - System Design

A car drives through a toll lane at 30 km/h, an overhead antenna reads its RFID tag, and by the time the nose of the car reaches the barrier the boom has lifted and a rupee amount has left a prepaid wallet. That is the whole product in one sentence, and the interviewer will let you feel good about it for about a minute before pointing at the parts that are actually hard. The barrier has to decide in under half a second while the wallet that funds the toll lives in a different bank’s ledger a network hop away. The same tag gets read three times because the car crawled under the antenna. The plaza in a valley loses connectivity for twenty minutes and cars keep coming. And the one thing that absolutely cannot go wrong - the number in the wallet - has to stay exactly right across 100 million debits a day even though two lanes, a retry, and a settlement job might all touch the same balance at once. ...

27 min

Design Flash Sale (6M Free Burgers in 1 Hour) - System Design

“Design a flash sale” sounds like a shopping-cart problem until you write down the actual numbers: Burger King runs a promo, the app has 50 million people who will all tap the same button in the same minute, and there are exactly 6,000,000 free-burger coupons to give away. Not 6,000,001. Not 5,999,998. Exactly six million, then the button says “sold out” and everyone else goes home. The interviewer is not testing whether you can serve a page. They are testing whether you can run a single shared counter down from 6M to 0 under a 50-million-user stampede without ever letting it go negative, without handing one person two coupons, and without the whole app falling over. ...

28 min

Design IRCTC Train Booking (Tatkal) - System Design

“Book a train ticket” sounds like inserting a row. Then you look at Tatkal. At 10:00:00 sharp, a few days’ worth of demand for a scarce quota lands in a single second. Two or three million people press “Book” against a train that has maybe eighty Tatkal seats. The seats sell out in ten to twenty seconds. Every one of those millions must get a truthful answer - a confirmed seat with a berth number, a waitlist position, or a clean rejection - and no seat may ever be sold twice, because a double-booked berth is two paying passengers standing in the same coach at midnight. This is not a CRUD service with a form in front. It is a scarce-inventory contention problem where the read load is enormous, the write load is fierce and concentrated, and correctness on the write path is absolute. ...

35 min

Design MakeMyTrip Travel Search - System Design

“Design MakeMyTrip” sounds like a shopping app: a user types two cities and a date, a list of flights comes back, they pick one and pay. The interviewer lets that run for a minute, then asks the question the toy version cannot answer. A user in Bangalore types “BLR to DEL, 12 August, 1 adult” and expects, in under two seconds, a ranked list of every way to make that trip - direct flights and connections - across 50-plus airlines, each with a real bookable price, layover, and total duration. MakeMyTrip does not own a single seat. The inventory lives behind dozens of airline APIs and Global Distribution Systems, each slow, rate-limited, priced per query, and disagreeing about what a fare costs from one second to the next. ...

30 min

Design an Authentication & Login System - System Design

“Let users log in” is the request that hides an entire distributed system. You need to store a password without ever storing the password, verify it in a way that is slow for attackers but fast enough at 100K logins a second, hand out a credential the user carries around, revoke that credential the instant an account is compromised, survive a leaked database dump, layer on a second factor, and let people sign in with Google without you ever seeing their Google password. Every one of those is a place the system breaks, and most of them are places where breaking means a breach, not a slow page. ...

33 min

Design Facebook Marketplace - System Design

Facebook Marketplace looks like “Craigslist with photos,” and if you design it that way you will fail the interview. The naive read is a CRUD app: a listings table, a search box, a chat window. But every one of those three has a scale trap hiding in it. The listing store is easy until you remember that “500M active listings” means half a billion rows that are constantly created, edited, marked sold, and expired, each with several photos that dwarf the metadata. The search box is easy until you realize the query is not “find listings matching iphone” but “find listings matching iphone, priced under 30000, in category Electronics, within 10km of where I am standing, sorted by relevance and recency” - a keyword search and a geospatial search and a set of filters, all at once, over 500M documents, at ~150k queries a second. And the chat window is easy until you count the fraud: Marketplace is one of the most heavily-abused surfaces on the internet, so a scammer posting a fake listing and a stolen-goods reshipping scheme are not edge cases, they are the main event. ...

28 min

Design Live Stock Prices Worldwide (Bloomberg) - System Design

“Show live prices for every stock on every exchange to millions of people at once” reads like a websocket that pushes a number. Then you look at what is actually flowing. Global exchanges emit millions of price ticks per second across hundreds of thousands of symbols. You have millions of users connected, each watching a different handful of symbols, each expecting the number to move within a blink of it moving on the exchange floor. The problem is not “get a price,” it is fan-out: one tick for a hot symbol must reach potentially a million users’ screens in under 100ms, and you cannot afford to send every tick to every user or run a query per user per tick. ...

29 min

Design Cluster Health Monitoring - System Design

“Monitor the health of the cluster” sounds like a cron job that pings every box and pages someone when one goes quiet. Then you put 50,000 nodes behind it and ask for sub-second detection, and every easy choice breaks. Poll 50K nodes from one monitor and you cannot finish a sweep in a second. Trust a single missed heartbeat and every GC pause or 200ms network blip pages you at 3am. Auto-restart on the first miss and a flaky switch takes down a rack, then your remediation logic restarts all of it in a storm and you have turned a blip into an outage. The whole problem is doing three hard things at once: detect a real failure in under a second across 50K nodes, be sure it is real and not a false alarm, and act on it without making things worse. ...

28 min

Design On-Call Escalation (PagerDuty) - System Design

Everyone thinks PagerDuty is a glorified SMS sender. “A monitoring tool posts an alert, you look up who is on call, and you text them. If they do not reply, you text the next person.” Then the interviewer starts asking the questions that turn it into a real system: how do you know who is on call right now when the schedule is a weekly rotation with a holiday override layered on top and the engineer is in a different timezone? When you say “escalate if not acknowledged within 5 minutes,” where does that 5-minute timer live so that it still fires if the machine holding it crashes? If the same outage trips 400 alerts in ten seconds, how do you page one human once instead of 400 times? And the thing that actually matters: the entire product is a promise that when production breaks at 3am, exactly one awake human gets woken up and, if they do not answer, the timer does not silently die - it escalates. A dropped page is the one bug this system is not allowed to have. ...

33 min

Design P2P File Transfer (BitTorrent) - System Design

The whole point of a file-transfer service sounds like a solved problem: put the file on a server, hand out a URL, let people download. That works until the file is 10GB and a million people want it in the same hour. Now do the arithmetic the interviewer is waiting for: 10GB times 1,000,000 downloads is 10 petabytes of egress, and if half of them show up in the first hour you need roughly 10 PB / 3600s ≈ 2.9 TB/sec of outbound bandwidth from your origin. No single origin, no CDN tier you would willingly pay for, serves 2.9 TB/sec for one file. The server-centric model does not scale sub-linearly with popularity - it scales linearly, and popularity is exactly when it collapses. ...

28 min

Design Facebook Likes with Live Updates (Including Celebrities) - System Design

Tapping “Like” is the smallest interaction Facebook has. It is one bit: you either like a post or you do not. It looks like a toggle on a boolean. It is not. Behind that single tap sits a counter that must be accurate (a user liking twice counts once, an unlike must decrement, the number cannot drift over a billion taps), durable (unlike a live viewer count, a like is a real fact the user expects to persist forever), and live (the number should tick up on every viewer’s screen as others tap, without a refresh). And then there is the part that actually breaks systems: a celebrity or a viral post can take 100,000 likes per second, all landing on the count of a single post. One row. One key. A firehose. ...

29 min

Design Live Comments on Facebook - System Design

Live comments look like a solved problem until you put a number on it. A celebrity goes live, a million people are watching, and comments are pouring in at ten thousand a second. Every one of those million viewers is supposed to see new comments appear the instant they are posted. Do the multiplication and the system dies on the spot: 10,000 comments/sec times 1,000,000 viewers is 10 billion messages per second if you naively push every comment to every viewer. No fleet on earth moves 10 billion messages a second for a single post. ...

24 min

Design Live Page Viewer Count (Booking.com) - System Design

“23 people are looking at this hotel right now.” It is one line of text, a soft nudge that the room might not be here tomorrow. It looks trivial. It is not. To render that number you have to answer, for every one of a million product pages, a question that is genuinely hard at scale: how many distinct humans are looking at this page right now, updated live, refreshed as people arrive and leave, across a global fleet. ...

25 min

Design a Wire Transfer API - System Design

A wire transfer looks like the wallet transfer’s twin, and interviewers love it because it is not. In a wallet, “move 500 from Alice to Bob” is one UPDATE inside one ACID transaction because both accounts live in your database. A wire moves money between two different banks. The debit lives in your ledger; the credit lives in a bank you cannot see, reach transactionally, or roll back. There is no shared transaction. There is an external rail (Fedwire, RTGS, SWIFT, ACH) that is slow, at-least-once, and - once it settles - irreversible. You cannot ROLLBACK a wire. You can only send a second, compensating wire and hope. ...

30 min

Design Distributed Tracing (Jaeger / Dapper) - System Design

One request hits your API gateway, which calls auth, which calls the user service, which calls three downstream services, two of which hit a cache and a database, one of which enqueues a job that a worker picks up 40ms later. That single user-facing click fanned out into 30 service calls across 12 machines, and it was slow - 1.2 seconds when it should be 200ms. Which hop ate the second? Logs won’t tell you: they are 30 disconnected lines in 12 different files with no thread that ties them together. Metrics won’t tell you: they say “p99 latency is up” but not which call in which request. The thing that ties them together - the single most valuable artifact in a microservice debugging session - is the trace: the full call tree of one request, every span timed and parented, so you can see exactly where the 1.2 seconds went. ...

31 min