Design a Price Tracker
How a price tracker chooses which product pages to fetch, verifies crowd-reported prices, stores price history and sends each alert once.
On this page
A price tracker lets a user paste a link to a product, set a target price, and receive a notification when the price drops to that target. It also shows a chart of every price the product has had. The service has no price feed from the shop, so it has to read prices from the shop's product pages.
The difficulty is that the shop has about 500 million product pages and allows only a few hundred fetches a second. The design has to decide which pages to fetch and when, decide how far to trust prices reported by users, and make sure that a false price never produces an alert and that a real drop produces exactly one. The steps follow A Framework for Any Design.
Clarify the problem
Design a price tracker for a large e-commerce site.
Where do the prices come from, an official API or the product pages, and how fast are we allowed to fetch?
There is no price API. You fetch the pages, and you must stay under 500 requests a second.
How many products exist, and how many of them do our users track?
There are about 500 million products. 10 million users have 50 million alerts on about 20 million distinct products. A browser extension with 2 million installs can report the prices its users see.
Then we cannot watch every product often. I will spend fetches on the products whose alerts are close to firing and use the extension to fill the gaps. I will treat a false alert as worse than a late one. How quickly must an alert follow a price drop?
Within a couple of hours is fine for popular products.
The functional requirements are these.
- A user can track a product from its link.
- A user can be alerted at a target price or at a percentage drop.
- A user can see a price-history chart.
- The service accepts price reports from the extension.
The non-functional requirements are these.
- The crawler stays under 500 fetches a second.
- Popular products are checked every 2 hours and every tracked product daily.
- An unverified price never triggers an alert, and each drop produces one alert.
- A chart loads in under 200 ms.
Other shops, price prediction, search and user accounts are out of scope.
Estimate the scale
The fetch budget is 500 fetches a second × 86,400 seconds, which is 43.2 million fetches a day. Add about 30 million extension reports and the system receives roughly 73 million price observations a day. If one observation in ten shows a new price, that is about 7.3 million price changes a day, or 85 a second, which is a small load for the alert pipeline.
Spending the whole fetch budget on every product page in turn, how long does one full pass take?
- 500 million product pages
- At most 500 fetches a second
Show the working
- 500 × 86,400 = 43.2 million fetches a day
- 500,000,000 ÷ 43,200,000 ≈ 11.6 days, about 12
Estimate 12 days (anything from 4 days to 40 days is a good answer)
A product checked only every 12 days would miss most sales, so spreading the budget evenly fails and the fetches have to be prioritised.
Write the calls for creating an alert, reading a price chart and receiving a report from the extension. What should the report call tell the extension?
Compare with a model answer
Alerts and history are plain REST calls. The report call returns 202 and nothing else, so the extension never learns whether a report was accepted.
Define the API Optional
Optional in the interview. Sketch the API only if the interviewer asks, if an API choice shapes the design, or if time permits. Otherwise say "I'll skip the detailed API unless you want it" and go to the data model.
POST /alerts
body: { "product_url": "https://shop.example/p/B0077", "target_cents": 6500 }
or { "product_url": "...", "drop_percent": 15 }
201 { "alert_id": "a-31", "product_id": "P-77",
"current_cents": 7999, "last_checked": "2026-11-14T08:10Z" }
404 not a product page we recognise
DELETE /alerts/{id}
GET /products/{id}/history?range=1y
200 { "resolution": "day", "low_cents": 5999, "last_checked": "...",
"segments": [ { "from": "2026-01-03", "to": "2026-02-11", "cents": 7999 }, ... ] }
POST /observations from the extension, signed install token
body: { "product_id": "P-77", "cents": 6499, "currency": "USD",
"seller": "store", "condition": "new", "seen_at": "..." }
202 Accepted always, whatever is decided later
429 too many reports from this installThe observation endpoint always returns 202 because a report is checked later. If the response said which reports passed, someone submitting fake prices could use it to tune the next attempt.
A percentage alert is converted into an absolute target when it is created, so the matcher only ever compares one price with one target.
Sketch the price-history and alert records. How can the chart tell "the price did not change for a month" from "nobody looked for a month"?
Compare with a model answer
Store history as segments, each with a price, the time it was first seen and the time it was last confirmed. A gap between one segment's last confirmation and the next segment's start is time when nobody looked. Alerts are rows indexed by product and target price.
Model the data
price_segments -- one row per run of the same price
product_id VARCHAR(16)
first_seen TIMESTAMP
last_seen TIMESTAMP -- moved forward by each matching observation
cents INT
source VARCHAR(8) -- crawl | crowd (verified)
PRIMARY KEY (product_id, first_seen)
alerts
alert_id VARCHAR(16) PRIMARY KEY
user_id BIGINT
product_id VARCHAR(16)
target_cents INT
state VARCHAR(8) -- armed | fired
fired_change VARCHAR(16) NULL
INDEX (product_id, state, target_cents)
crawl_state
product_id VARCHAR(16) PRIMARY KEY
next_due TIMESTAMP
priority REAL
last_verified_cents INTHistory is read as one product over one time range, which fits a wide-column or time-series store keyed by (product_id, first_seen), where a chart is a single range scan. Alerts are queried as "armed alerts on P-77 with a target at or above $64.99", a range scan on an index in a relational database. Crawl state is a priority queue that lives inside the crawler.
Sketch how prices arrive, where they are checked and stored, and how a price change becomes a notification.
Compare with a model answer
Fetches and crowd reports both feed one price service, which writes history and emits an event only when a verified price changes. An alert matcher turns each event into notifications.
High-level design
request and replyasynchronous message
Not drawn: the API servers write alerts to the alerts database, and the crawler reads alert counts from it. Both arrows into the price service pass through a log partitioned by product_id, so one instance handles each product's observations in order and two copies of the same drop cannot both emit an event.
- P-77 last verified
- $79.99
- budget
- 500/s
1P-77 has 3,400 trackers and alerts close to its price, so it is checked every 2 hours. It is due, so the crawler fetches it.
- P-77 last verified
- $64.99
- change id
- c-501
2The parser reads $64.99 instead of the last verified $79.99, so the price service closes the old segment and starts a new one.
- change id
- c-501
- alerts matched
- 3
3The price service emits change c-501. The matcher finds the armed alerts on P-77 with a target of $64.99 or more, which are $70, $67.99 and $65.
- change id
- c-501
- alerts sent
- 3
4The matcher sends 3 notifications keyed by
alert id + c-501and marks the alerts as fired. A $60 target is not reached, so that user is not notified.- change id
- c-501
- alerts delivered
- 3
5If the matcher crashes before marking the alerts, the log redelivers c-501 and the matcher sends again with the same keys. The notification system drops all 3 as duplicates.
- P-77 last verified
- $64.99
- events
- 0
- fetches saved
- 1
6An extension user reports P-77 at the known $64.99. Only
last_seenmoves, no event is emitted, and the next fetch is pushed back by 2 hours.- P-90 last verified
- $89.99
- P-90 report
- $9.99
7One install reports P-90 at $9.99, an 89% drop from the verified $89.99. The report is held as unverified, so there is no history entry and no event.
- P-90 last verified
- $89.99
- false alerts
- 0
8A priority fetch of P-90 reads $89.99, so the report is discarded and that install's trust score drops.
- target
- $65
- re-arm above
- $68.25
- alerts sent
- 0
9Later P-77 rises to $66 and falls back to $64.99. The $65 alert re-arms only above $65 × 1.05 = $68.25, so it stays fired and sends nothing.
Deep dives
Spending the fetch budget
The budget is 500 fetches a second, and the question is which pages get them. The crawler is the one from Design a Web Crawler, with a token bucket holding the fleet to 500 fetches a second. What changes is the order in which it visits pages, and there are three ways to choose it.
The first is to visit every page in turn. A full pass takes about 12 days, so a weekend sale would be missed, and most fetches would go to products nobody tracks.
The second is to fetch tracked products on a fixed schedule, for example once a day. This ignores what the alerts say. A product whose nearest alert is 40% below the current price is unlikely to fire soon but gets the same fetches as a product whose alert is 1% away, and a product with 3,400 trackers is checked no more often than one with a single tracker.
The third is to give each product a priority and keep the pages in a queue ordered by next_due. Priority rises with the number of trackers, with how close the nearest alert is to the price, with how often the price changes, and with the time since the last check. The crawler takes whatever is due next. A simple version uses tiers, and this is the plan to describe in an interview.
The hot tier holds about 1 million products with the most trackers or an alert within 5% of the price, checked every 2 hours, which costs 12 million fetches a day. The tracked tier holds the other 19 million products with an alert, checked daily, which costs 19 million. The remaining 12.2 million fetches go to the 480 million untracked products, about one visit each every 40 days, so that a new alert starts with a recent price.
Trusting crowd reports
Extension reports cost nothing, but they come from strangers. Some are wrong by accident, because the extension saw a member-only price, a coupon price, a used offer or a misparsed page. Some are wrong on purpose. The rule to state is that a crowd report can confirm a price or ask for a check, and it cannot make a large change alone. There are three ways to apply it.
The first option is to trust every report. This is fastest, but one script posting $9.99 for a popular product would send thousands of false alerts within minutes, and a sent notification cannot be taken back.
The second option is to use reports only to schedule fetches. A report that disagrees with the known price moves the product to the front of the queue, and the crawler reads the price itself, so no crowd price enters the history. Every change still needs a fetch, so little is saved, but it suits a new extension with no trust scores yet.
The third option is to verify by the size of the change. A report that matches the known price extends it. A change of up to 10% from an install with a good record is accepted. A larger change, or any change from a new install, is held until a second install on a different network reports the same price within an hour, or until a priority fetch confirms it. Trust goes up when an install's reports later agree with fetches and down when they do not, and each install is rate limited. A real large drop waits for confirmation, but most of the savings remain.
| Option | Good at | Bad at | Pick it when |
|---|---|---|---|
| Trust every report | It gives the most coverage and the fastest alerts. | One script posting a fake price sends thousands of false alerts in minutes. | Do not use it for anything that triggers alerts. |
| Use reports only to schedule fetches | No crowd price enters the history, and a reported change jumps the queue. | Every change still costs a fetch, so the savings are small. | Use it for a new extension that has no trust scores yet, or while the extension is being heavily abused. |
| Verify by size of change Usual default | Small changes from trusted installs are accepted and large ones need confirmation. | Trust scores and thresholds must be built and tuned, and a large real drop waits for confirmation. | Use it once the extension has many reporters. This is the choice here. |
An interviewer will often ask whether this delays a real flash sale. It does, by one priority fetch, which takes seconds, and that is acceptable because a late alert is better than a false one. The extension also reports only the public price of new items, so member prices, coupon prices and used offers never reach the service.
Storing and charting history
A product's price is flat for most of the time, so there are two ways to store it. The first is to store every observation as a row, which is simple but writes about 855 GB a year (73.2 million × 32 bytes × 365) and makes a chart read many identical rows. The second is to store segments. A segment has a price, the time it was first seen and the time it was last confirmed, and a new row is written only when the price changes. An observation that matches the current price only moves last_seen. With one change in ten observations this is about 85 GB a year, and it keeps the chart honest: if the last confirmation of one segment is 10 days before the start of the next, the chart shows a gap instead of a flat line that nobody checked.
A one-year chart for a product that changes price daily reads 365 segments in one range scan. The chart is drawn as steps, because a sloped line between two prices suggests prices such as $72 that never existed.
Alerting once per drop
Duplicates come from three places, and each needs its own fix.
The first source is that the fetch and an extension report can both see the same drop. Only a change from the last verified price emits an event, so the second observation of the same price emits nothing.
The second source is redelivery. The log delivers events at least once, so after a crash the matcher can process the same event again. Each notification carries the key alert_id + change_id, and the notification system drops any key it has already sent.
The third source is a price that flaps around the target. A price that goes from $64.99 to $65.01 and back to $64.99 falls to the $65 target twice, but the user should not be told twice. A fired alert is therefore re-armed only when the price climbs 5% above the target, or when the user asks for it.
One more problem is a popular product that matches 200,000 alerts at once. The matcher reads the (product_id, state, target_cents) index in batches. At 2,000 notifications a second the last user is told 100 seconds after the first.
Bottlenecks and failures
At 10 times the users the fetch budget does not grow, because the shop sets it. Check intervals get longer and the extension, which grows with users, matters more. History grows by less than 10 times because prices do not change more often, and even 850 GB a year is easy to shard by product_id.
| Component that fails | What happens | What you do |
|---|---|---|
| The shop starts blocking fetches | Fetch errors increase and prices become stale. | Lower the token bucket rate at once, rely more on verified reports, and show the "last checked" time. |
| The shop changes its page layout | The parser returns nothing, or returns a wrong number. | Reject parses that fail sanity checks, alert the team when failures jump, and emit no events from a parser that suddenly disagrees with history. |
| The price service | Fetches and reports pile up. | They wait in the log, and the service catches up from its last committed offset when it restarts. |
| The alert matcher | Alerts are late but not lost. | Events wait in the log, and the matcher resumes from its last committed offset. |
| The notification system | Matched alerts cannot be sent. | Keep the alerts armed until sending succeeds. The idempotency key makes the retries safe. |
What a strong answer sounds like
Interviewers look first for the fetch budget as the central constraint, then for how the candidate treats untrusted data.
| Level | What the answer does |
|---|---|
| Junior | Fetches every tracked product on a cron job, stores every price and compares each with every alert. |
| Mid-level | Sees that the budget cannot cover the catalogue, prioritises tracked products, keys history by product and time, and sends alerts through a queue. |
| Senior | Treats the fetch budget as the design, prioritises by how close alerts are to firing, never lets the extension fire alerts alone, stores segments that show gaps, and fixes each source of duplicates. |
How do you use the extension's reports?
Mostly to save fetches. A report that matches the known price confirms it and lets me push the next fetch back. A large change needs a second independent reporter or our own fetch, because only verified changes may fire alerts.
Doesn't that delay real flash sales?
By one priority fetch, which takes a few seconds. I think a slightly late alert is better than a false one, because a sent notification cannot be taken back.
Follow-up questions
How would you support many stores?
Each store gets its own budget, token bucket, parser and queue of due products. The rest of the pipeline does not care where a price came from.
How do you know that two links point to the same product?
Normalise each link before using it: strip tracking parameters, resolve redirects, and take the shop's own product identifier from the page or the URL. Key everything by that identifier. Variants such as colour or size that have different prices should be separate products, because one target price cannot apply to both.
How do you detect fake drops, where the price is raised before a sale?
The history shows it. Compare the sale price with the median of the last 90 days instead of the day before, because a price raised just before the sale makes the discount look larger than it is.
After your attempt, tick what you really did. Be strict: "I thought about it" is not "I said it out loud".