System Design (High-Level Design) Module 26 – Case studies: booking, commerce and contention
Design a price tracker: collecting prices
Design the collection side of a price tracker: sources each shop allows, safe link checks, a fetch budget per site, polite fetching and parsing.
What you will learn
- Estimate fetches, per-site budgets and bandwidth for a price tracker
- Choose price sources that each site's terms and APIs allow
- Resolve pasted links to one product, seller and region without fetching internal addresses
- Plan each site's fetch budget so that watchers see current prices
- Design fetchers and parsers that respect limits and catch wrong prices
Before you start
What you’ll learn · Before you start
What you will learn
- Estimate fetches, per-site budgets and bandwidth for a price tracker
- Choose price sources that each site's terms and APIs allow
- Resolve pasted links to one product, seller and region without fetching internal addresses
- Plan each site's fetch budget so that watchers see current prices
- Design fetchers and parsers that respect limits and catch wrong prices
Before you start
On this page
The collection side of a price tracker turns the links people paste into tracked products and keeps each product’s price current, within what every shop allows, though one shop may allow only 5 requests a second. Each shop’s terms decide the sources: an official feed or API first, data from an affiliate programme only where its policies allow tracking, and pages only where robots rules and terms allow, never by getting around a block.
A pasted link is checked so that the server never fetches an internal address, then keyed by product, seller and region, because prices differ by seller and by delivery area. Each site gets a fetch budget, and a scheduler spends it where watchers will notice a change. Fetchers make conditional requests and slow down when a site asks, parsers prefer structured data, and a change detector emits an event only when a price or the stock has changed.
Not affiliated
Based on public information about Amazon and Flipkart. MySmartCoPilot is not affiliated with Amazon and Flipkart, and Amazon and Flipkart’s real policies and systems may differ from what this lesson describes.
Every shop’s allowance is a budget, and the first design spends it
What makes collecting prices different
The data belongs to someone else. Shops publish terms, feeds and robots rules, and the tracker’s design starts from what they allow. Every site’s capacity is a budget, so freshness cannot simply be bought with more fetchers. The input is hostile: a pasted link can point anywhere, including at the tracker’s own network. And parsing is fragile, because one template change can turn every price on a site into a wrong number overnight.
| What is different | What the design does |
|---|---|
| The data belongs to the shops | A source rule for each site, from its terms |
| Each site’s capacity is a budget | A scheduler that spends a fixed number of fetches |
| A pasted link can point anywhere | Address checks before any fetch |
| One template change breaks every price | Checks before a price is published |
Requirements
People paste a product link or search for a product, and the tracker follows it on the sites it supports. It records the price and stock of each product, seller and region, keeps watched products as current as the site’s allowance lets it, and hands every change to the history and the alerts. The qualities: no fetch beyond what a site allows; no request to a private or internal address; a wrong price is caught before anyone is alerted; and every shown price says when it was checked.
Estimates
Assume 2 million tracked items checked 4 times a day, 30 % of them on the largest site, one site that allows 5 requests a second for its 600,000 items, and pages of 120 KB. Work each figure out, then check yourself.
Checkpoint
Check the estimate
| Quantity | Working | Result |
|---|---|---|
| Fetches for 4 checks a day | 2 million items × 4 ÷ 86,400 s | about 93 a second |
| The largest site, 30 % of items | 93 × 0.30 | about 28 a second |
| One site allowing 5 a second | 432,000 a day ÷ 600,000 items | 0.72 checks per item a day |
| Pages downloaded | 93 a second × 120 KB | about 89 Mbit/s |
The total is modest; one site’s allowance is the binding limit.
The first design
The first design of a price tracker's collection side
Text description of the diagram
The diagram shows how a price is collected, from top to bottom.
- Users paste a link or search. Link intake checks the addresses the link leads to and turns it into a product key.
- Tracked items are kept as a product, a seller and a region.
- The refresh scheduler reads the tracked items and the source rules of each site (a feed, an API or the pages that may be fetched) and spends a fetch budget per site.
- Fetches wait in per-site queues with token buckets, and fetchers send conditional requests and back off when a site tells them to.
- Parsers read structured data first, and a change detector checks whether the price or the stock changed.
- Changes become price events for the history and the alerts. A dashed arrow takes the observed change rates back to the scheduler.
Link intake checks where a pasted link leads and turns it into a tracked item. The scheduler reads every item and each site’s source rules, and decides what to fetch next within the site’s budget. Fetches wait in per-site queues, the fetchers make them, the parsers read the price and stock, and the change detector passes on only what changed, with change rates going back to the scheduler.
Step through one pasted link, from the paste to a price event:
The drawing shows the whole scene; its 7 steps are listed below.
Every step as text
- A link is pasted. A user pastes a product link. Link intake checks where it leads, so the server never fetches an internal address, and turns it into one key for the product.
- One tracked item. The tracked item is the product, the seller and the region, because one product can have several sellers and prices can depend on the delivery area.
- The site's rules. The scheduler reads every tracked item and the site's source rule, which says whether a feed, an API or the pages may be used.
- Spent from the budget. The site's allowance is a budget, so the scheduler decides what to fetch next within it, where watchers will notice a change.
- Fetched politely. A fetcher takes the next fetch from the site's queue, sends a conditional request and slows down when the site asks it to.
- Read the price. The parser reads the price and the stock, from the page's structured data first.
- Only changes go on. The change detector passes on an event only when the price or the stock changed, to the history and the alerts, and tells the scheduler how often this item changes.
Checkpoint
Check the first design
The deep-dive questions
- Which sources may a tracker use for each site, and what do their terms require?
- How does a pasted link become one product, seller and region without the server fetching internal addresses?
- How is a site’s fetch budget spent so that watchers see current prices?
- How do fetchers stay within each site’s limits and back off when asked?
- How are prices parsed reliably, and how are wrong prices caught before anyone sees them?
- What changes ahead of an announced sale?
- What breaks at 10× and 100×, and which designs are rejected?
Each site’s terms choose the source, in an order of preference Pro: opens with a Pro, Premium or Ultimate pass
In this part:
- A pasted link is checked at every address and every redirect
- A site’s budget goes where watchers look, measured
- Each site has one polite gate: a bucket, conditional requests and back-off
- A parsed price is only a candidate until it passes two alarms
- At 10× each site’s budget gives way, and at 100× link intake
- Failure drills: five faults, each with a safe way out
- Options considered and rejected
- What each level covers, and a 45-minute self-mock
- What each level is expected to cover
- A 45-minute self-mock
- Practise: the polite gate in code, then the whole design
- Keep fetches within a site's limits and back off when told
- Interview questions
- Your tracker follows 600,000 products on one shop that allows 5 requests a second. Users say sale prices show up hours late, yet most fetches find nothing changed. The scheduler refreshes products in proportion to how often their prices change. What is wrong, and how do you decide what to fetch next?
- Users paste product links and your server fetches them to identify the product. A security test shows that a pasted short link made the server fetch an internal admin page. How did that happen, and what does the server check before and during every fetch?
- Overnight your tracker recorded a 90 % price drop on 3,000 products of one shop, and alerts went out. The shop had changed its page template, and the parser read a different number. How do you stop wrong prices from reaching users, and how do you clean up?
- Key takeaways
4 diagrams · 3 runnable examples (Python) · 1 exercise with sample tests · 3 interview answers · about 47 minutes
Opening this part with your pass…
This part opens with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so this part can’t be opened at the moment. The free part above stands on its own. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
Read a complete sample first: Design movie seat booking like BookMyShow
References
- Product Feed API reference (delta feeds) (Flipkart)
- Associates Program Policies (Amazon)
- RFC 9309: Robots Exclusion Protocol (IETF)
- Chrome Web Store program policies: Limited Use (Google)
- Server-Side Request Forgery Prevention Cheat Sheet (OWASP Foundation)
- Effective page refresh policies for Web crawlers (ACM Transactions on Database Systems) (Association for Computing Machinery)
- RFC 6585: Additional HTTP Status Codes (429 Too Many Requests) (IETF)
- RFC 9110: HTTP Semantics (Retry-After, 304 Not Modified) (IETF)
- Offer (schema.org type) (Schema.org)
Related tools
Report a problem with this lesson
Kept only in this browser. Your Learn progress