Circle Backend System Design Interview: Build a Reservation API with Ticket Hold & 3rd-Party Booking Integration

13 Views
No Comments

Flight Booking (Python)

This exercise provides a basic Python HTTP server used to track flight tickets and their prices.
Your interviewer will explain the question; the README only contains usage hints.
The main libraries include Flask (HTTP server) and psycopg2 (PostgreSQL client).


Getting Started

To start the database:

$ bin/start_db.sh

Then, in another terminal:

$ source bin/install_deps.sh
$ ./migrate.py
$ ./app.py

If psycopg2-binary fails to install, ensure SSL libraries are available:

export LDFLAGS="-L/usr/local/opt/openssl/lib"

The server will start at:

localhost:8080

To test the server:

$ curl localhost:8080/ping
$ curl localhost:8080/flights/1

To get a PostgreSQL shell:

$ bin/attach_db.sh

Migrations

Migrations are created using yoyo.
Place SQL migration files into /migrations directory using the format:

number.name.sql

Run migrations:

./migrate.py

Core Code Structure

Ping Endpoint

@app.route('/ping')
def ping():
    return {'message': 'pong'}

Single Flight Endpoint

@app.route('/flights/<int:id>')
def getFlight(id):
    flight = None
    try:
        flight = flights.getFlight(db, id)
    except Exception:
        return {'message': 'Unknown error'}, 500
    
    if flight is None:
        return {'message': 'Unable to find the requested flight'}, 404
    
    return {'data': flight.__dict__}

This endpoint fetches a single flight record from the database and returns it as JSON.

Problem Summary

Design the backend API for a ticket-reservation system (e.g., movie or concert tickets).
The system must allow users to hold tickets for 10 minutes before completing payment.
You may also need to integrate multiple third-party flight booking APIs to automatically book the cheapest available option.


Key Requirements

  1. Users can request to hold one or more tickets.
  2. A ticket hold should last 10 minutes, after which the ticket is automatically released.
  3. Users can complete booking before the hold expires.
  4. The system must prevent double booking or overselling.
  5. For the flight-booking version, the service should:
    • Query multiple external APIs
    • Compare prices
    • Book the lowest-cost flight
    • Handle failures and retries gracefully

High-Level Design Summary

  • Use a Reservation Service to manage holds and bookings.
  • Store active holds in a database + distributed cache (Redis).
  • Use TTL-based locks (Redis SETNX with expiration) to prevent double booking.
  • A Background Expiration Worker automatically releases expired holds.
  • For third-party APIs:
    • Implement a Flight Aggregator Service
    • Add retries, timeouts, and circuit breakers
    • Normalize responses into a unified internal format

Critical Considerations

  • Ensure idempotency for hold + booking endpoints.
  • Prevent oversell through atomic locking or DB transactions.
  • Handle race conditions with optimistic or pessimistic concurrency control.
  • Make the system fault-tolerant when calling third-party APIs.
  • Ensure observability with logs, metrics, tracing.

The VOprep team has long accompanied candidates through various major company OAs and VOs, including Meta, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.

END
 0