Admin login page
user login page
lot availabilty , timing , vehicle entry and exit , parking allocation , payment system , reservation slots with timing and date ,
easy scalibility , highly availabity, consitency ,durabiltiy, security , low latency
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
Authentication Api for both admin and user , check slot api , book slot api , set entry and exit time api , payments api ,
- Client (mobile / web) + Lot Gate Devices (barrier controller, plate/ticket reader) - API Gateway — auth (driver vs. lot operator), per-user and per-lot rate limiting, routing - Reservation Service — availability search, spot hold, confirmation, gate validation - Transaction Service — payment intents, capture, refunds, PSP webhooks - Redis — advisory cache: free-spot counts per lot, pricing, ~30s TTL - Postgres — source of truth: lots, spots (with vehicle size), reservations, payments partitioned by lot_id - Payment Provider (Stripe) — card tokenization, charges, sends confirmation webhooks - Background jobs — hold expiry, no-show release, nightly reconciliation RESERVE JOURNEY 1. Driver searches lots -> availability lookup served from Redis free-spot counts 2. Reservation Service writes a PENDING hold in Postgres inside a transaction with a unique constraint on (spot_id, time_window) -> this is what prevents double-booking 3. Transaction Service creates a payment intent with the PSP 4. Driver pays; PSP webhook flips the reservation to CONFIRMED 5. Hold not paid within N minutes -> expiry job releases the spot automatically GATE JOURNEY 1. Gate reads plate/ticket -> API Gateway -> Reservation Service 2. If a CONFIRMED reservation covers "now", open the barrier and record entry_time 3. No reservation -> open in ad-hoc mode, record entry, charge on exit 4. On exit: compute duration, charge balance, record exit_time, free the spot KEY DECISIONS - Cache is advisory, commit is authoritative. Redis makes search fast, but the double-booking guarantee comes from the DB unique constraint. A stale cache causes a failed hold, never two reservations on one spot. - All traffic enters through the API Gateway, which rate-limits and retries idempotently, so a hot lot on a Saturday morning or a gate flapping on a bad network cannot overwhelm the reservation service. - Postgres partitioned by lot_id keeps writes local to a lot and lets you move a large operator's lots to their own shard later without a rewrite.
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
SPOT ALLOCATION Mechanism: Postgres EXCLUDE USING gist (spot_id WITH =, tstzrange(start_time,end_time) WITH &&) WHERE status IN ('PENDING','CONFIRMED'). Two drivers, same spot+window: the second INSERT blocks on the first's in-flight tuple, then fails with 23P01 -> 409 "just taken". The INSERT is the source of truth, not the availability check, so no check-then-commit race can double-book. Stale Redis means a 409, never two bookings. Idempotency: unique index on (user_id, idempotency_key) — a retried reserve returns the same hold ID. Holds get expires_at = now+10min; a 60s sweeper flips expired rows, and the WHERE clause means expired holds stop blocking the slot immediately. Intervals are half-open [start,end): a 6-8pm exit and an 8-10pm entry do NOT conflict. Hot lot: conflicting writers get an immediate 409, client retries with jitter, Gateway caps per-lot rate so the DB sees bounded concurrency. GATE CONTROLLER Plate lookup for a CONFIRMED reservation covering now -> open barrier, record entry_time, mark ACTIVE. No match -> ad-hoc ticket, charge on exit. Exit: duration = exit - entry, charge via Transaction Service, mark COMPLETED, free the slot. Budget <500ms p99 (cars queue at the barrier), so this path never touches the availability cache. Cloud unreachable -> barrier controller keeps a local allow-list of CONFIRMED reservations plus a local ticket log, opens offline, replays entry records idempotently by event ID on reconnect.