Skip to content
Middle+0 views

Design a distributed system for managing access to parking facilities with subscriptions, one-time visits, and offline terminals.

Practice

Asked at

AI answer

Architecture

A central service manages parking facilities, spaces, subscriptions, rates, and access rules. Gates and terminals operate through a local controller that connects to the server over a secure channel. PostgreSQL stores accounts and transactions; a broker delivers commands and events; a cache and the controller's local storage enable fast decisions and offline operation.

Passes and visits

A subscription has a validity period, parking facility or zone, restrictions, and a status. A single visit is a separate record with a time window, rate, and entry/exit state. State transitions are performed atomically; repeated requests from a terminal are identified by an idempotency key. Account for concurrent entries and space limits using transactions or locks on the parking facility/pass. Do not treat payments as confirmed based only on a client request—verify confirmation from the provider.

Offline mode and security

If connectivity is lost, the terminal uses a locally stored allowlist, signed and limited by time and volume, along with operator-defined rules—for example, safely deny entry or allow entry with subsequent reconciliation. Every decision and event is recorded in a durable local log with a sequence number; after connectivity is restored, events are synchronized idempotently. Provide for key revocation and conflict handling so that an offline decision does not become a permanent authorization.

Devices authenticate using individual certificates; secrets are protected, traffic is encrypted, and staff access is separated by role. Monitor terminal availability, the share of offline decisions, synchronization latency, and accounting discrepancies. Regularly test database recovery and failover scenarios.