Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ambersariya/792ec5eb273ead7cf313dc7879e8c8b7 to your computer and use it in GitHub Desktop.
Save ambersariya/792ec5eb273ead7cf313dc7879e8c8b7 to your computer and use it in GitHub Desktop.

Flight Availability and Pricing Service

Scenario

Build a service that aggregates flight availability and pricing from multiple airlines and travel agencies. The service allows users to search for flights between two cities, specifying a date range and preferences. It recommends the best flights based on price and availability, considering factors like layovers and travel duration.


Requirements

1. Data Sources

  • AirlineConnect: A major airline providing availability and pricing through a RESTful API.
  • GlobalFlyer: A travel agency offering flight information via a GraphQL endpoint.
  • BudgetWings: A budget airline that uploads a CSV file daily with flight schedules and prices.

2. Features

  • Allow users to specify:
    • Origin and Destination cities.
    • A departure date range (e.g., Jan 10–15).
    • Optional preferences such as shortest travel time or lowest cost.
  • Fetch flight availability and pricing from all sources.
  • Return:
    • The best-priced flight(s) for the selected route and date range.
    • Details like layovers, total travel time, and airline.

3. User Preferences

  • Include filters for:
    • Direct flights only or allow layovers.
    • Maximum layover duration (e.g., no more than 3 hours).
    • Maximum travel time (e.g., no longer than 10 hours total).

4. Performance

  • Fetch data from all providers concurrently.
  • Cache frequently queried routes and date ranges to reduce latency.
  • Use a timeout to handle slow providers.

5. Notifications

  • If a flight matching a user's preferences drops below a certain price threshold, send an alert to their email or a notification service.

Simulation Details

1. AirlineConnect (REST API)

Simulate this provider with an asynchronous function that returns flight data in JSON format after a delay of 200ms.

Example Response:

[
    {
        "flight_number": "AC101",
        "origin": "JFK",
        "destination": "LAX",
        "price": 300,
        "departure": "2025-01-10T08:00:00",
        "arrival": "2025-01-10T11:00:00",
        "layovers": []
    },
    {
        "flight_number": "AC202",
        "origin": "JFK",
        "destination": "LAX",
        "price": 250,
        "departure": "2025-01-10T15:00:00",
        "arrival": "2025-01-10T19:00:00",
        "layovers": ["ORD"]
    }
]

2. GlobalFlyer (GraphQL Endpoint)

Simulate a GraphQL query returning flight data after a 300ms delay.

Example Query:

query {
    flights(origin: "JFK", destination: "LAX", dates: ["2025-01-10", "2025-01-15"]) {
        flightNumber
        price
        departure
        arrival
        layovers
    }
}

3. BudgetWings (CSV File):

flight_number,origin,destination,price,departure,arrival,layovers
BW303,JFK,LAX,200,2025-01-10T22:00:00,2025-01-11T02:00:00,""
BW404,JFK,LAX,180,2025-01-11T05:00:00,2025-01-11T09:00:00,"PHX"

Steps

Step 1: Basic Implementation

  • Fetch flight availability and pricing for a given route and date range from all providers.
  • Aggregate the results and return the best-priced flight(s).

Step 2: Handle Preferences

  • Add filters for:
    • Direct flights only.
    • Maximum layover duration.
    • Maximum travel time.

Step 3: Performance Optimization

  • Fetch data concurrently using asynchronous calls.
  • Add caching for frequently searched routes and date ranges.
  • Implement timeouts for slow providers to avoid delays in the overall response.

Step 4: Notifications

  • Send a notification if a flight below a specific price threshold becomes available.

Step 5: Handle Failures

  • Simulate provider failures (e.g., API down, CSV file missing).
  • Ensure partial results are returned even if some providers fail.

Possible Extensions:

  1. Multi-City Itineraries
  • Allow users to search for multi-city routes (e.g., JFK → LAX → SFO).
  1. Real-Time Updates
  • Implement WebSocket or push notifications for price changes in real-time.
  1. User Accounts
  • Add user-specific preferences and saved searches.
  1. Pricing Trends
  • Include price trends over time for users to identify the best time to book flights.
@ambersariya
Copy link
Author

Note: This kata is AI generated and incorporates regional availability, preferences, and real-time notifications, making it a great way to practice asynchronous programming, filtering logic, and failure handling in the context of a dynamic and complex domain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment