2dbi

Design a parking-lot management system

viaLeetCode

Problem Design a management system for parking-lot owners: owners log in and see capacity, utilization, revenue, and other statistics for their lots.

Requirements

  • Owner accounts owning one or more lots; per-lot live capacity (total/occupied/free) and revenue reporting (daily/weekly/monthly).
  • Ingest events from the lots (vehicle entry/exit, payment) that drive the stats.
  • Dashboard queries: current occupancy, revenue over a date range, peak hours.

Core design

  • Model: Owner(id, auth) 1—N ParkingLot(id, name, capacity) 1—N ParkingEvent(lot_id, type=ENTRY/EXIT, vehicle, ts) and Payment(lot_id, amount, ts). Occupancy is derivable from events; keep a cached counter per lot for O(1) reads.
  • Services: AuthService (owner login, lot-level authorization), IngestService (receives events from gate hardware), StatsService (aggregations), ReportAPI backing the dashboard.
  • Pre-aggregate revenue/occupancy into daily rollup rows so date-range queries don't scan raw events.

Discussion points

  • Derived vs stored counters: keeping occupied_count consistent with the event stream (idempotent event handling, reconciliation job).
  • Authorization: an owner must only see their lots — enforce at the service layer, not just the UI.
  • Growth: many lots reporting concurrently → queue the ingest; time-series storage for events; caching dashboards.
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account