System Design: Price Tracker (Walnut Price: Read Budgets, Confirmed Drops, Sorted Alert Targets, the Black Friday Burst)
We design a price tracker and call it Walnut Price.
A person pastes a link to a product at an online store. Then they set a target, such as "tell me when this TV is below $300". Walnut Price watches the price, keeps its history for a chart, and sends an alert when the price crosses the target.
Most system design questions are about serving reads or storing writes. A price tracker is different: it cannot read prices freely. Each store allows only so many reads a second, and the system must decide which prices to read now.
As in any system design interview, the numbers are assumptions for planning. Every number here is our own assumption, and the design is our own.
1. Requirements
1.1 What we are building
Walnut Price does three jobs:
- Know the prices. Read prices from online stores without breaking any store's limits. Spend the reads where a price is close to someone's target.
- Trust a price before acting on it. A browser report or a broken page can show a fake price. A drop is checked with a second read before anyone hears of it.
- Tell the right people, once. When a price crosses a target, alert every person whose target it crossed. Do it quickly, even when 1.4 million alerts fire at once. Never send the same alert twice for one crossing.
The story, from a Tuesday in November to the Sunday after Black Friday:
- Tue 4 Nov, 20:15. In Columbus in Ohio, Emily Carter pastes the link of a Brightwave 65-inch TV at the store Riverline. It costs $499.99. She sets an alert: below $300, by push and email.
- Thu 27 Nov, 21:00. A deal-reselling group called DealBlitz runs 3,000 fake browser installs. They report the same TV at $49.99. One read from Riverline says $499.99. Nobody gets an alert.
- Thu 23:40. The outdoor store Harbor Outfitters changes the layout of its pages. Our Parser, the program that reads prices from store pages, now sees $0.00 on every item. At 23:52 Laura Nguyen, our on-call engineer in Boston, is woken up. Her fix ships at 01:30. Nobody gets an alert.
- Fri 20:00:00. Riverline cuts the TV to $279.99, 44% off. In Atlanta, Marcus Johnson's browser extension sees the new price 4 seconds later.
- 20:00:12. Walnut Price has read the new price twice from Riverline and records the drop. 1.4 million alerts have targets at or above $279.99.
- 20:01:12. Emily's phone shows: "Brightwave 65-inch TV: $279.99 at Riverline, below your $300 target." That is 72 seconds after the price changed.
- 20:03:00. In Phoenix, Sofia Ramirez sets a new alert on the TV, below $290. Her push arrives 2 seconds later.
- 20:04:30. The TV sells out. About 350,000 emails that have not gone out yet are never sent. Ryan Brooks in Austin asked for email only, below $280. He gets the story in his morning summary instead.
- 21:30. The store Northmart cuts the same TV to $259.99. Olivia Bennett in Seattle has an alert for "any store, below $260". At 22:05 she gets a push.
- Sat 29 Nov. In Denver, Jake Miller watches a tent whose seller changes its price between $89.99 and $84.99 all day. Jake gets one push, not thirty.
What happens to each person:
- Emily hears 72 seconds after the change, and buys before the TV sells out at 20:04:30.
- The fake $49.99 reports never reach anyone, and the installs that sent them are no longer trusted.
- The broken Harbor Outfitters pages never fire a $0.00 alert. For two hours, its items show "last checked 23:40".
- Sofia, who set her alert after the drop, hears at once.
- Ryan never gets an email for a TV that is already sold out.
- Olivia hears about the Northmart price, because her alert covers every store.
- Jake gets one push on Saturday, and his alert is armed again on Sunday morning.
The hard part has three pieces:
- Our plan wants about 1,880 price reads a second from stores. The stores allow about 1,200.
- A price we read may be wrong, and one wrong price can alert millions of people.
- One price change can fire 1.4 million alerts at once, while two other big sales start in the same second.
1.2 Words we use
Words used in only one place are explained there. Each word below is used all through the post.
Stores and prices. In this post a store is a company that sells online. Our own databases have names that end in "store", such as the Alert store.
| Word | Meaning here |
|---|---|
| Store | A company that sells online, such as Riverline. Interviewers often say retailer |
| Listing | One item at one store, such as the Brightwave TV at Riverline |
| Product | Our group of listings that are the same item at different stores |
| Price type | Who sells the item and in what state: sold by the store new, new from other sellers on the store's site, or used |
| GTIN | The barcode number printed on the box, one per model and color |
| MPN | The maker's part number, such as BW65Q7 |
| Partner API | A store's interface for programs that we may use under a signed agreement. API stands for application programming interface |
| Feed | A price file a store sends us every hour |
| Crawl | Reading a store's public web pages with a program, slowly and within the store's published rules |
| Extension | Our browser add-on. While its user looks at a store page, it can report the price shown |
Reads and checks.
| Word | Meaning here |
|---|---|
| Read | One request to a store for one listing's price |
| Read budget | How many reads a second a store allows us |
| Check | One read that our scheduler plans |
| Reading | A price we got from any source, before we trust it |
| Hint | A reading from an extension. It says "look here", and never fires an alert by itself |
| Confirm read | An extra read, taken at once, to check a price change before we trust it |
| Price event | A change in a listing's price that we trust. It is the only thing that fires alerts |
| Tier | How often a listing is checked: every minute, every 10 minutes, every hour or every 6 hours |
Alerts.
| Word | Meaning here |
|---|---|
| Alert | One person's rule, such as "the TV at Riverline, below $300" |
| Target | The price in that rule |
| Watcher | A person with at least one alert on a listing |
| Fire | An alert fires when a price event crosses its target |
| Cool-down | After an alert fires, 24 hours in which it does not fire again |
| Re-arm | After its cool-down, an alert fires again only once the price has gone back above its target by 5% |
| Bucket | A range of one listing's targets that holds about 50,000 alerts. A bucket that grows past 60,000 alerts splits in two |
| Fired marker | One row per bucket that records which of its alerts a price event fired |
| Chunk | 1,000 crossed alerts, handed on as one piece of work for the senders |
| Lane | A separate part of a queue. Each big drop gets its own big-drop lane, and all smaller drops share the normal lane |
| Send | One message on one channel: a push to a phone, or an email |
| Digest | One email each morning that lists the alerts a person missed |
The system.
| Word | Meaning here |
|---|---|
| Shard | One slice of a store's data, holding some keys. Each shard has copies in three zones |
| Zone | One building or group of buildings inside a region, with its own power |
| Region | One of our two groups of data centers: US East in Ohio, and US West in Oregon |
| Partition | One slice of a log. Events with the same key stay in order inside one partition |
| Lease | A claim that ends by itself after a set time unless it is renewed |
| Epoch | A number that goes up by one each time a new owner takes over. Writes with an older epoch are refused |
| p99 | The time 99 of every 100 requests finish within |
IDs in this post. Every ID below is made up.
| ID | What it names | Example from the story |
|---|---|---|
| u_10482 | A user ID | Emily Carter |
| lst_rv_88213 | A listing ID | The Brightwave TV at Riverline |
| lst_nm_40517 | A listing ID | The same TV at Northmart |
| lst_rv_51902 | A listing ID | Jake's tent at Riverline |
| prd_5531 | A product ID | The Brightwave 65-inch TV, at every store |
| al_7F3K | An alert ID | Emily's alert, below $300 |
| al_9P1D, al_2C8W, al_8H2N, al_4T6M | An alert ID | The alerts of Sofia, Olivia, Ryan and Jake |
| ext_4410 | An extension install ID | Marcus's browser extension |
| ck_91F0 | A check ID | The first confirm read of the TV's drop |
| pe_7M2Q | A price event ID | The TV's drop to $279.99 |
| pe_7M5X | A price event ID | The TV selling out |
1.3 Every kind of request and change
Walnut Price handles more than the story shows. This table lists every kind. Each part it names is explained where it first appears in the design.
| Kind | What it is | How big or how often | Part that handles it | Outside company that takes part |
|---|---|---|---|---|
| Add an alert | A person pastes a link and sets a target | about 1 million a day | Alert API, Listing resolver, Alert store | The store, for the first price |
| Scheduled check | A read we plan, by tier | about 1,080 a second; 120 more are kept for confirm reads | Scheduler, Quota service, fetchers | Riverline, Voltbay and other stores |
| Feed file | A store's hourly price file | 25% of watched listings | Feed ingester | Northmart and other stores |
| Extension report | A price seen in a person's browser | about 350 a second | Extension intake | none |
| Confirm read | An extra read after a big change | about 120 a second at most, 100 of them at Riverline | Scheduler, fetchers | The same stores |
| Price event | A trusted price change | about 140 a second, about 1,000 on sale days | Validator, Event log | none |
| Alert match | Find the alerts a price event crossed | one per price event | Alert matcher, Alert index | none |
| Send | A push or an email | about 1 million a day, 20 million on Black Friday | Notifiers, Channel senders | A push provider and an email provider |
| Chart view | A person opens a listing's price history | about 230 a second | Chart service, History store | A CDN |
| Product link | Join listings of the same item across stores | new listings each day | Product matcher | none |
| Morning digest | One email with the missed alerts | once a day per person who missed one | Digest job | The email provider |
A CDN is a content delivery network: servers in many cities that keep copies of files near the reader.
1.4 Functional requirements
- Add an alert. From a link, a search result or the extension. An alert has a target price, a price type and its channels: push, email or both.
- Read prices. Keep each watched listing's price fresh, more often when it is close to someone's target, within every store's limits.
- Confirm. Fire alerts only from prices we trust. A big drop is read twice.
- Alert. When a price event crosses a target, send the alert on each chosen channel, once.
- Stop. Do not send an alert about a deal that has ended, and send the digest instead.
- Any store. An alert can cover a product at every store we know.
- History. Show each listing's price history as a chart, for years back.
Out of scope: buying through Walnut Price, coupons, and price predictions. How our affiliate links earn money is out of scope too. An affiliate link is a store link that pays us a small fee when someone buys.
1.5 Non-functional requirements
- Alert speed. For a listing checked every minute, the first sends go out within 90 seconds of the price change. The TV's first sends went out after 14 seconds. Emily's push, in chunk 553 of the TV's alerts, went after 72.
- The big burst. On sale nights, the pushes of one drop with 1.4 million alerts finish within 3 minutes.
- No false alerts. No alert fires from a hint or a single odd reading. A big drop is read twice. A big drop is 30% or more, on a listing with 10,000 or more alerts.
- Once per crossing. One alert sends at most one push per channel per price event. A rare repeat after a crash is merged on the phone.
- Stores' limits. We never send a store more reads than its budget, and we follow its published crawl rules.
- Charts. A chart loads in 300 ms at p99, and history is kept for 10 years.
- Availability. If a region fails, alerts keep firing from the other region within 5 minutes.
1.6 The numbers
These are rough sums, the kind a candidate does at a whiteboard in a few minutes. Every number is our own assumption.
Walnut Price has 20 million registered users and 6 million monthly active. They keep 200 million alerts on 40 million watched listings, which are listings with at least one alert. We plan for Black Friday, which carries about 7 times a normal day's price changes.
| Number | How we get it | Result | What it decides |
|---|---|---|---|
| Reads wanted | 2,000 top listings × 1,440 a day + 98,000 hot × 144 + 2 million warm × 24 + 37.9 million cold × 4 = 217 million a day. Feeds cover 25%, so 75% = 163 million. ÷ 86,400 s | About 1,880 reads a second | We must choose which listing to read now |
| Reads allowed | Riverline's partner API: 1,000 a second = 86.4 million a day. Three public APIs: 3 × 5 million. Crawling: 15 stores × 2 pages a second × 86,400 = 2.6 million. Total 104 million ÷ 86,400 | About 1,200 reads a second | A scheduler spends the budget by closeness to targets; cold listings wait longer |
| Confirm reserve | 10% of each store's budget: 120 of the 1,200. At Riverline, 10% of 1,000 | 100 reads a second at Riverline | Confirm reads never wait behind scheduled checks |
| Price events | About 10% of 104 million reads find a change, plus 1.6 million feed changes = 12 million a day = 140 a second. × 7 on Black Friday | About 1,000 a second on sale days | One ordered log, split into 64 partitions by listing |
| History | Store changes, not reads: 12 million × 24 bytes = 290 MB a day. One row per read would be 104 million × 24 bytes = 2.5 GB a day | About 105 GB a year | Keep one row per change; years of history stay small |
| Alert index | 200 million alerts × 80 bytes | 16 GB | Alerts kept sorted by target per listing, so a change reads only the alerts it crossed |
| The burst | 1.4 million alerts fire. 70% want push = 980,000. On sale night the push provider allows us 1.2 million a minute for 3 big-drop lanes = 400,000 each | 980,000 ÷ 400,000 = about 2.5 minutes | Sends split into chunks, with each big drop in its own big-drop lane |
| Extension reports | 5 million installs; 40% agree to share prices = 2 million; × 15 store pages a day = 30 million ÷ 86,400 | About 350 a second | Hints are cheap to take, and each one costs a confirm read only when it shows a change |
What these numbers tell us. Storage is small and the price events are few. The hard parts are elsewhere:
- we may read only about two thirds of the prices we want, so every read must count;
- a price must be trusted before 1.4 million people hear about it;
- one price event can need 1.4 million sends in under 3 minutes, without a repeat and without sending after the deal ends.