2dbi

Design an Air Traffic Control System

viaLeetCode

Problem Design an air traffic control system using the MEDIATOR pattern: flights never talk to each other directly — the ATC tower mediates all coordination (landing/takeoff slots, runway assignment, position broadcasts).

Requirements

  • Flights register with the tower; request landing/takeoff; receive clearances or hold instructions; the tower tracks runway availability and sequencing; flights get notified of relevant state changes.

Core design

  • Mediator interface: ATCMediator { register(flight), requestLanding(flight), requestTakeoff(flight), notifyRunwayFree() }; concrete TowerControl holds runway state + a waiting queue.
  • Colleague: abstract Flight(id, mediator) with requestLanding() delegating to the mediator and callbacks receiveClearance()/hold(); concrete PassengerFlight/CargoFlight (priority differences exercise sequencing).
  • Runway as a guarded resource inside the mediator (available flag or semaphore for multiple runways); mediator grants in queue/priority order and re-dispatches on notifyRunwayFree().

Discussion points

  • Why mediator: n flights would otherwise need n² peer awareness; centralizing coordination decouples colleagues — contrast with observer (broadcast, no arbitration logic) since interviewers probe the difference.
  • Sync vs async communication: synchronous grant (simple, blocks) vs message/event queue between flights and tower (realistic, needs correlation ids and timeout handling) — walk both, pick async for scale.
  • Concurrency: the mediator is the contention point — synchronize runway state; fairness/starvation (priority + aging), emergency preemption as an extension.
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account