Design a Multi-Provider Flight Price Aggregation System
System DesignModel answerLast updated
Design a scalable service that aggregates, normalizes, and serves cheap flight offers from many providers under strict latency and cost constraints.
Build a Flight Price Aggregation Service
You are designing the backend for a travel search product that lets users find the lowest available fares across many airlines and ticket distributors.
What the system must support
- Search by departure airport, arrival airport, travel dates, cabin class (economy / business / first), maximum number of stops, and passenger count.
- Flexible date queries, such as "show me the cheapest day to fly in April" or "prices for ±3 days around my target date," returned as a per-day price calendar alongside ranked itineraries.
- Results sorted by total price, with filters on stop count, carrier, and departure window.
- A price-confirmation step before the user is handed off to book, so they always see an accurate fare at purchase time.
What to cover in your answer
- Requirements and scale — state your assumptions explicitly: QPS, provider count, data volume, look-to-book ratio.
- API design — request and response shapes for search, calendar, and price confirmation.
- Architecture — how data flows from providers into a searchable store, including ingestion, normalization, deduplication, and write propagation.
- Data model and indexes — schema choices that make price queries fast and price updates cheap.
- Data freshness — how stale results stay useful and how the system keeps hot routes up to date without blowing the provider budget.
- Caching strategy — what gets cached, at which layer, and for how long.
- Provider access — rate limiting, retries, circuit breaking, and quota management.
- Consistency vs. availability — where eventual consistency is fine and where it is not.
- Scalability and cost control — the dominant cost is provider API calls, not compute; show how the design respects that.
- Failure modes and rollout — what breaks first under load, and how you would launch this safely.
You are expected to make and defend trade-offs, not just enumerate options. Numbers and rough sizing carry more weight than vague claims.
Hints
Hint 1
Provider API quota is the most binding constraint in this system, not CPU or memory. Your refresh and caching strategy should be designed around minimizing provider calls, not around minimizing infrastructure cost.
Hint 2
A cache miss on a cold route and a cache miss on a hot route need different handling. Think about what a 'stale but acceptable' result looks like to a user, and design your freshness tiers and TTLs around user behavior rather than uniform expiry.
Hint 3
Deduplication is trickier than it looks: the same physical flight is sold by multiple providers and under codeshare flight numbers. Define your dedup key precisely — which fields uniquely identify an itinerary regardless of who is selling it — before you design the offer schema.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements and Scale
Functional requirements
- One-way and round-trip search by route, date(s), cabin, stops, and passenger count.
- Flexible-date mode returns a price calendar and the cheapest itineraries within a date window.
- A confirm endpoint validates the price live before booking handoff.
Non-functional requirements
- Search p99 latency under 1.5 s. The vast majority of responses come from cache; live fan-out is the slow path.
- High availability for search; strong correctness only at confirmation.
- Provider cost is the binding constraint. Most distributors charge per API call and enforce hard daily quotas. Every architectural decision should reduce unnecessary provider calls.
Scale assumptions (state these aloud in an interview)
- 50 M searches/day ≈ 600 QPS average, ~3,000 QPS at peak.
- Look-to-book ratio ~1,000:1, so hitting providers on every search is not viable.
- ~20 providers, ~40 k active city pairs, 330-day booking horizon, 4 cabins → roughly 50 M (route, date, cabin) cells, each holding 50–500 offers. Offer store: 1–5 B rows total. The hottest 5% of routes drive ~80% of queries.
2. API Design
GET /v1/search
?origin=LHR&dest=CDG&depart=2025-06-01&return=2025-06-08
&flex_days=2&cabin=ECONOMY&max_stops=1&pax=1&sort=price&cursor=...
→ {
search_id, freshness: "cached|partial|live",
calendar: [{ date, min_price }],
offers: [{ offer_id, price, currency, segments[], provider, priced_at }],
next_cursor
}
POST /v1/offers/{offer_id}/confirm
→ 200 { offer_id, confirmed_price, price_changed: bool, expires_at, booking_token }
→ 410 (offer no longer available)
GET /v1/calendar?origin=LHR&dest=CDG&month=2025-06&cabin=ECONOMY
→ { date: min_price } map, served entirely from a precomputed store
Every offer carries priced_at so the UI can display "prices as of X." The search endpoint is cursor-paginated and stateless.
3. Architecture
Client → CDN → API Gateway (auth, rate limiting)
→ Search Service → Redis result cache
│ cache miss └─ Search Index / Offer Store
▼
Refresh Scheduler ←──────────────────────────┐
│ │
▼ │
Provider Gateway (per-provider adapters, Kafka "raw_offers"
token buckets, circuit breakers) │
Normalizer
Deduplicator
│
Kafka "offers"
│
┌──────────────┴──────────────┐
Index Writer Calendar Aggregator
(Offer Store) (Redis sorted sets)
│
Cache invalidation events
Provider adapters translate each supplier's protocol (SOAP/GDS, NDC XML, REST) into a canonical internal format. Normalization standardises IATA codes, UTC times, currency (via a daily FX table), cabin labels, and baggage metadata; unparseable records go to a dead-letter queue for alerting. Deduplication collapses the same physical flight sold by multiple providers using a key of hash(sorted segments of (operating_carrier, flight_no, dep_date_local, origin, dest), cabin, fare_brand). One row per (itinerary_key, provider) is stored; the cheapest is the representative result, with alternatives surfaced as "also available from X."
4. Data Model and Indexes
Offer store (Cassandra / ScyllaDB — write-heavy, TTL-native, wide rows)
Partition key : (origin, dest, depart_date, cabin)
Clustering key: (total_price ASC, itinerary_key, provider)
Columns : stops, duration_min, segments (JSON), carriers,
dep_time_local, currency, base_fare, taxes,
seats_left, priced_at, expires_at ← row TTL
A search on a single (route, date, cabin) cell is a single-partition scan, already sorted by price. Stop and carrier filters apply within the partition, which stays small enough (hundreds of rows) to be fast. Because the clustering key includes price, a price change is a delete of the old row followed by an insert. A side table offer_by_key(itinerary_key, provider) → current_price lets the writer locate the old row without a full scan.
Fare calendar (Redis sorted set or wide row): (origin, dest, cabin, month) → {date: min_price}, with separate fields for min_price_nonstop and min_price_1stop. Flexible-date queries read one calendar row, pick the cheapest N dates, then fetch only those offer-store partitions — avoiding a full date-range scan.
Round trips: store outbound and return legs independently, combine the top-K of each at query time. For hot routes, also ingest provider-quoted round-trip fares keyed by (origin, dest, out_date, ret_date, cabin), since bundled fares are often cheaper than two separate one-ways.
5. Freshness and Update Propagation
TTL tiers by departure proximity:
- Within 7 days: 15–30 minutes
- 8–60 days: ~2 hours
- Beyond 60 days: 12–24 hours
The Refresh Scheduler maintains a priority queue scored by query_rate × staleness × price_volatility. It proactively refreshes hot cells within the provider quota and lets cold cells expire naturally. A cache miss on a cold route triggers an on-demand fan-out with a 1.2 s deadline; if providers are slow, a partial result returns with freshness: partial and the remainder streams in via polling on search_id.
Price changes detected at confirmation (price_changed: true) publish a Kafka event. The index writer updates the affected rows, the calendar aggregator recomputes that day's minimum, and a cache-invalidation event evicts matching Redis keys.
6. Caching Layers
- CDN — calendar responses and popular city-pair queries, 60 s TTL.
- Redis result cache — keyed on the normalised, parameter-sorted query string with airports expanded to IATA. Uses request coalescing (single-flight / mutex pattern) so 1,000 concurrent identical misses produce a single provider fan-out.
- Offer store — effectively a long-lived cache of provider responses, with TTLs set per freshness tier above.
7. Provider Access
- Token buckets per provider in Redis, sized by contractual QPS and daily quota. Budget is split: ~70% for the refresh pool, ~30% for on-demand misses.
- Retries apply only to idempotent search calls: exponential backoff with jitter, max 2 attempts, bounded by the request deadline.
- Circuit breaker per provider: trips on elevated error rate or p95 latency. While open, serve cached data with a
freshness: stalesignal. - Scraper protection at the API gateway via per-user-token rate limits and CAPTCHA challenges for anomalous patterns, since scrapers are the biggest source of wasted provider quota.
8. Consistency vs. Availability
Search favours availability: stale prices with a clear staleness label are better than an error. The one place that requires strong correctness is confirmation — always a live provider call, with the response authoritative. If the confirmed price differs, the UI shows the delta and lets the user decide before booking. This is the only synchronous, un-cached path in the system.
9. Common Mistakes to Avoid
- Hitting providers on every search — the look-to-book ratio makes this economically impossible; cache and pre-fetch are non-negotiable.
- Uniform TTLs — departure proximity and route popularity should drive freshness policy, not a single global TTL.
- Dedup by marketing carrier — codeshares mean the same seat can appear under multiple flight numbers; dedup on operating carrier and flight number.
- Treating round trips as two independent one-ways — combined fares exist and are often cheaper; the data model must account for them on hot routes.
- Ignoring the confirm step — presenting a price without a live re-check at purchase time will cause real user-facing errors and loss of trust.