Requirements


Functional Requirements:


  • Allow reservation of a parking spot.
  • Process payment for the reservation.
  • Enable parking of a car in the reserved spot.
  • Support early departure before reservation time expires.
  • Gate check-in/out.
  • Handle no show.



Non-Functional Requirements:


  • The service should be highly available, allowing users to reserve parking spots at any time.
  • The service should be reliable and consistent and should not overbook or double book parking spots.
  • Gate check-in/out should be fast and complete under 10 millisecond.
  • Booking can take some time and should complete in under 10 seconds.
  • Giving customers leeway of 10 minutes before marking them as no show and canceling the booking.
  • Send reminder notifications before reservation end time and start processing fine for delayed checkouts


API Design

Our system will have the following endpoints:


  1. viewAvailableParkingSpots: Alows users to see a list of available parking spots based on the selected location
  2. reserveSpot: allows users to reserve a parking spot for a given amount of time.
  3. checkIn: allows users to check-in at the gate
  4. checkOut: allows users to check-out of the parking lot


High-Level Design


We will use an event driven architecture for this application. This allows us to easily accommodate things like bookings, check-in/outs, no shows and update the state of our application quickly.


We will also need a database with tables for users, parking spots, bookings and checkin-checkout. We can us a relational database like Postgres to store our data. We will perform joins to get the time slots where a parking lot is booked and update checkin-checkout tables when users come in and go.


We will use Stripe to process payments for parking space. We will use Kafka to handle our events and create producers like the reserveSpot, checkIn endpoints and consumers like sending confirmation email and update database services.


Application components:

  • Website and UI allowing users to view and book parking spots.
  • Server running our application logic
  • Database to store data


Request flow:

  • User views and selects a parking spot
  • We begin a 5 minute timer and block the selected parking spot
  • We wait for user to complete payment and receive appropriate even from Stripe
  • If the payment fails we unblock the parking spot
  • After payment completion, we send confirmation email and update the database
  • When user checks-in we create an event to mark them as present and update database
  • When user checks-out on or before booking end time we create an event and update database
  • If user hasn't checked-out by booking end-time we start a timer and fine them for overstay.


On average we can assume that we will get 100 requests/minute for viewing available spots, 10 requests/minute for booking and less check-in/out. To improve performance of viewAvailableParkingSpots, we will cache booking data. We can also use read replicas of the database to improve performance.


All of our endpoints are stateless so we can containerize each service and use container orchestration to scale up and down depending on traffic.


Detailed Component Design


viewAvailableParkingSpot -

Assuming 100 requests per minute, we use the cached bookings data to show the available parking spots to users. When a user clicks on a parking spot we start a 5 minute timer and mark this spot as unavailable. After time expires we unblock the spot if user did not complete payment. This let's us avoid double booking cases.


reserveSpot -

We take details like user name, email and booking start/end times then hand off the payment processing to Stripe. Once we get the payment completed event from stripe we update the database and send confirmation email to the user. Kafka will be used to manage the event queue. Before allowing reservation, check that previous dues have been paid.


checkIn -

At the gate, take booking confirmation number, validate it and allow entry up to 5 minutes before

and 10 minutes after the booking time. Update database and mark the user as present.


checkout -

Similarly at the gate take booking confirmation number and update database.


lateCheckout -

Take the confirmation number, calculate fine and accept point of sale transaction. If user is unable to pay add balance to their account.