System requirements


Functional:

List functional requirements for the system (Ask interviewer if stuck)...

  1. Allowing drivers to reserve parking spots
  2. Keep track of available parking spots: The system needs to maintain real-time updates on the number of empty spots for different types of vehicles. Sometimes a rough estimation
  3. Record entering time: Capture and store the timestamp when a vehicle enters the parking lot to track duration.
  4. Identify available parking spots: Determine available spots based on the size of the vehicle upon entry.
  5. Handle full parking lot: Provide a message when no parking spot is available, directing the user to exit.
  6. Calculate parking fee: Calculate fees based on the duration a vehicle is parked in the lot.
  7. Accept payment: Allow drivers to make payments using various methods upon exiting the parking lot.


Non-Functional:

List non-functional requirements for the system...

  1. High availability: Ensure the system is operational and accessible at all times to avoid disruptions.
  2. Secure payment system: Implement robust security measures to protect payment transactions and user data.
  3. Data preservation: Store payment and vehicle entry/exit logs securely in a durable and reliable database for auditing and analysis purposes.
  4. Data Consistency: Ensure data consistency when multiple vehicles come in at the same time.


API design

Define what APIs are expected from the system...

enter(license: string, vehicle_size:enum) -> num_of_available_parking_spots, parking_record_id

vehicle_size could be COMPACT, STANDARD or OVERSIZED.


getParkingFee(parking_record_id: string)->fee:float


exit(parking_record_id: string)->leftFee:float


processPayment(parking_record_id: string, payment_id: string, payment_method: enum, card_info: object)

payment_method could be cash, debit or credit


High-level design

You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design...

This system contains following components:

Client - user-facing UI machines at entrances and exits of the Parking lot.

Server - The main business logic lives here.

Database - Holds table to track current number of available parking spots. As well as recent parking record and payment record.

External Payment System - a third party payment system that takes payment (e.g. square)

Cron machine - Running a cron job to obtain old records (probably records older than 1 year and stores them in cold storage), the records could be cleared up in Database.

Cold Storage - Low cost storage to store old record, as they're seldom accessed.



Detailed component design

Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...

Cron machine & cold storage: The past parking records and payment records might be useful for future reference, audition, etc. However, it is not accessed very frequently, therefore, a cron job could be setup to run monthly and pull data that's over 1 year ago and store them in s3.

Server: we have very low traffic so 1 machine could handle all traffics. However, in order to ensure the availability of the service, we introdcue duplication in the server. We can have multiple (3 might be good enough) machines to serve the data. Whenever a client calls the service, it can use a round robin mechanism to choose a server to call.

Database: Similar to server, we are not expecting a huge number of data, and the data can fit in to one machine. However, in order to avoid downtime introduced by machine crashing or maintenence, we should introduce replica of the database. The database could run in master - slave mode, and the master is responsible to copy data over to slaves. In case the master machine is unavailable, a slave machine will then become the new master.



Database design

Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...

PARKING SPOTS TABLE:

  1. id: varchar (PK)
  2. spot_type: varchar (compact, standard, oversized)
  3. total_spots: integer
  4. taken_spots: integer
  5. updated_at: timestamp

VEHICLE PARKING RECORD TABLE:

  1. id: varchar (PK)
  2. license: varchar
  3. enter_at: timeStamp
  4. exit_at: timeStamp

PAYMENT RECORD TABLE:

  1. id: varchar (PK)
  2. vehicle_parking_record_id: varchar (FK)
  3. fee: float
  4. payment_method: varchar (cash, debit or credit)
  5. card_info: object (metadata of the card used in payment)
  6. external_payment_id: varchar
  7. paid_at: timeStamp