#69 Scheduled Polling/Change Detection
Flight Price Tracking
Watch millions of saved flight searches and alert travellers when the fare drops, without hammering airline APIs.
What is being asked
Design "track this flight's price". A user saves a route and dates, optionally with a target price, and gets a push or email when the price drops meaningfully.
Requirements
Functional
- Create, list and delete price watches.
- Alert when the price drops below a target or by a set percentage.
- Show a price history chart for the route.
Non-functional
- Millions of watches, but far fewer distinct routes.
- Supplier calls cost money and are rate-limited.
- No alert spam: one meaningful alert, not ten small ones.
Design
- Watches are grouped by route key (origin, destination, date, cabin). Ten thousand people watching Mumbai–Goa on 24 Dec need one fetch, not ten thousand.
- The scheduler decides how often to poll each route: more often as departure nears or when many users watch it.
- Fetchers get the current lowest fare (from the search fare cache when it is fresh, from suppliers otherwise) and append it to price history.
- The change detector compares the new price with each watch's rule and last-alerted price, then queues notifications.
Key decisions and trade-offs
- Group by route, fan out per user. The expensive work (fetching) scales with routes; the cheap work (comparing) scales with users.
- Adaptive polling. Polling every route every 5 minutes is wasteful; prices for flights 6 months out rarely move.
- Hysteresis. Remember the last price you alerted on and require a real drop (e.g. ≥ 5% or ₹500) before alerting again.
- Reuse search traffic. Every real user search produces fresh prices for free; feed them into price history.
Follow-up questions
- How would you predict "prices are likely to rise, book now"?
- What happens when a route is sold out or the flight is cancelled?
- How do you avoid 2 million alerts going out in the same minute?
- How long do you keep price history, and at what granularity?