Circle 后端系统设计真题:设计可支持 10 分钟锁票与第三方航班预订的 Reservation API – 一亩三分地

31次阅读
没有评论

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.


1️⃣ 这个题本质是考察:后端 CRUD + DB migration + API error handling。
你要展示自己能理解一个服务如何启动、连接数据库、跑 migration、暴露 HTTP endpoint。

2️⃣ ping endpoint 是健康检查,重点不在逻辑,而在于你能解释为什么服务都需要 health check。

3️⃣ getFlight 的核心点有三个:

  • 能从 DB 取数据
  • 能正确区分:正常返回 / 找不到(404)/ 代码异常(500)
  • 返回结构化 JSON(__dict__

4️⃣ Migration 机制考察你是否理解生产环境数据库变更流程。

5️⃣ 这道题可扩展讨论:

  • 如何增加缓存(如 Redis)避免 DB 重复查询
  • 如何添加批量航班查询 API
  • 如何加入价格变化 tracking 或推送机制
  • 如何实现 pagination、filter(by date, price range)等真实业务需求

VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 Meta、Google、Amazon 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Stripe 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。

正文完
 0