Design a Flight Search Engine
Understanding the Problem
✈️ What is a flight search engine? A flight search engine takes "New York to Mumbai, March 10, back March 24, one adult" and returns a ranked list of itineraries (direct and connecting) with prices, usually from many airlines and online travel agencies at once. Skyscanner and Kayak are metasearch sites: they don't sell tickets, they find offers and send you to the airline or agency to book. Google Flights works the same way from the user's side, with more of the itinerary building and pricing done in-house.
Whether the interviewer says Skyscanner, Kayak or Google Flights, it's the same problem: build itineraries (including connections), get prices for them from systems that are slow, rate-limited and often charge per query, and show good results quickly. The main difference is how much each product computes itself versus asks its partners. We'll design a metasearch engine that builds connections itself and gets prices from providers, and cover deal alerts as their own requirement.
Functional Requirements
Core Requirements
- Users should be able to search one-way or round-trip flights between airports (or cities) on given dates for a number of passengers and a cabin, including connecting itineraries.
- Users should be able to sort and filter results (price, duration, stops, airlines, departure time).
- Users should be able to select an offer, see a confirmed current price, and be sent to the airline or travel agency to book.
- Users should be able to set price alerts for a route and dates (or flexible dates) and get notified when the price drops.
Below the line (out of scope)
- Booking and ticketing ourselves (we hand off to the provider).
- Complex multi-city trips with more than two legs.
- Hotels, cars and packages.
- Seat maps and ancillary fees (bags, seats).
Non-Functional Requirements
Ask about scale and, more importantly here, about our providers. For our design: 50 million searches a day, about 20 providers per search (airline APIs, online travel agencies and a GDS), and providers that take 1-10 seconds to answer and often charge per query or restrict how many searches you can make per booking.
Core Requirements
- The first results should appear within about a second, and the full result set within a few seconds.
- Prices shown in results can be somewhat stale (minutes to hours depending on how far out the flight is), but the price at click-out must be confirmed live.
- The system should keep provider query costs under control: most searches should not trigger a live query to every provider.
- Search should be highly available. One slow or failing provider should degrade results, not fail them.
- Price alerts should fire within an hour or so of a qualifying price drop.
Below the line (out of scope)
- Our own fare filing and ticketing (we're not an airline).
- Fraud and bot detection beyond rate limiting.
Back-of-the-envelope:
- Searches: 50M a day is about 580 per second, with peaks around 3,000.
- Live fan-out: if every search queried 20 providers, peak load would be 60,000 provider calls per second. Providers would rate-limit us long before that, and at per-query fees it would cost more than the bookings earn. This is the number that drives the design: the cache is the product, and live queries are a scarce resource we spend carefully.
- Schedules: there are on the order of 100,000 scheduled commercial flights a day worldwide. A year of flight instances is around 36 million; at about 100 bytes each, that's under 4 GB. The whole world's schedule fits in memory on one machine.
- Search space: a few thousand airports with scheduled service give millions of possible airport pairs, multiplied by about 330 bookable days, by return dates for round trips. We can't precompute prices for everything; we have to cache what people actually search and prefetch what's popular.
Metasearch businesses are shaped by the look-to-book ratio: thousands of searches for every booking. Providers pay for bookings, while searches cost us. Saying that out loud explains why caching, request coalescing and smart refresh matter more here than raw throughput.