List the key functional requirements for the system (Ask the AI for hints if stuck)...
List the key non-functional requirements (performance, scalability, reliability, etc.)...
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
Lets say the lot has 500 lots.
Each lot can maybe see 1-2 cars a day.
overall capacity is 1000 transactions at most a day.
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
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...
The parking_spots Table
This represents the physical layout of the lot.
CREATE TABLE parking_spots (
id SERIAL PRIMARY KEY,
lot_id INT NOT NULL,
floor_number INT NOT NULL,
spot_number VARCHAR(10) NOT NULL,
spot_type VARCHAR(20) NOT NULL, -- e.g., 'COMPACT', 'LARGE', 'EV', 'MOTORCYCLE'
is_active BOOLEAN DEFAULT TRUE, -- For maintenance closures
UNIQUE(lot_id, floor_number, spot_number)
);
```
CREATE TABLE reservations (
id SERIAL PRIMARY KEY,
user_id INT NOT NULL,
spot_id INT REFERENCES parking_spots(id),
start_time TIMESTAMP WITH TIME ZONE NOT NULL,
end_time TIMESTAMP WITH TIME ZONE NOT NULL,
status VARCHAR(20) NOT NULL, -- 'PENDING_HOLD', 'CONFIRMED', 'ACTIVE', 'COMPLETED', 'CANCELLED'
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
-- Ensure end_time is always after start_time
CONSTRAINT chk_reservation_times CHECK (end_time > start_time)
);
```
alternative solution instead of reservasion is
CREATE TABLE spot_hourly_inventory (
spot_id INT NOT NULL,
slot_date DATE NOT NULL,
hour_block INT NOT NULL, -- 0 to 23
reservation_id INT DEFAULT NULL, -- NULL means free
PRIMARY KEY (spot_id, slot_date, hour_block)
);
0(1) query to get spor avail.
SELECT spot_id
FROM spot_hourly_inventory i
JOIN parking_spots s ON i.spot_id = s.id
WHERE s.spot_type = 'LARGE'
AND i.slot_date = '2026-09-04'
AND i.hour_block IN (14, 15)
GROUP BY spot_id
HAVING COUNT(CASE WHEN reservation_id IS NULL THEN 1 END) = 2;
-- Ensures the spot is free for BOTH hours
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Reservation system
for reserved parking spaces, there are allocated lots by id and size. user can reserve based on the lot's availability which will be stored per lot and per time slot, bookings are by the hour. buckets are populated by workers on the daily, we may want to keep reservations only up to a 3 days ahead, daily worker will always populate the 3rd day ahead. reservation system can be sharded by lot id in the future.
serves reservation availability view, on user reserve, hit the ticketing service
for the non reserved buckets, the buckets will be decremented and incremented accordingly in a transactional where we need to check if still available.
Ticketing system: