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:


  • List the key non-functional requirements (eg low latency, scalability, reliability, etc.)...
  • Horizontal Scalability to support thousands of lots
  • High Availability
  • Low latency i.e Parking spot allocation needs to happen sub second to 2 seconds.
  • Consistency to avoid double booking


API Design

POST /api/v1/reserve


POST /api/v1/pay


PUT /api/v1/departEarly


POST /api/v1/checkin


POST /api/v1/checkout


GET /api/v1/reservations


GET /api/v1/emptyLots



High-Level Design

Database Design

We can go ahead with postgres to store the data.

Schema:

  • LotNo
  • Car No
  • CheckIn
  • CheckOut
  • Reserved
  • EarlyDeparture
  • Payment

We can have an index with (LotNo+CarNo)


Read Path:

Client -> CDN -> API Gateway -> Load Balancer -> services -> Redis -> Database


Write Path:

Client -> CDN -> API Gateway -> Load Balancer -> services -> Kafka Queue -> Redis -> Database


The loadbalancer is integrated into the api gateway api paths through a vpc endpoint. Making it possible for communications.


When ever a request comes to an api it will go through the load balancer from there it will go to the respective service. From there if it is a read operation then it will try to get it from Redis if the cache hit is a miss only then it will go to the postgres DB.


The api gateway routes the traffic based on the api that is getting hit and it also has the capabilities to rate limit the traffic preventing any DDos and Brute force attack.


During Burst Traffic the servers/compute where the services are running scale by using simple scaling.


The load is balanced using load balancer

Even before coming to the Redis most of it is taken care off by the CDN.


For write it will go through api gateway and load balancer from there to the respective service which would push it to kafka queue from there the write happens to Redis and Postgres.


This keeps the Cache up to date and stale free.


We have a cleanup service which cleans up the cache in redis and invalidate cdn after ttl expiry.


The user starts at cdn from there when he tries to reserve a lot it will go to the api gateway from there it will go to reservation service where the user can make reservation. After confirming the lot he will pay the money which payment service takes care. Now these events are sent to kafka queue from there to redis and postgres. When the user checks in the check in/out service takes care of it.


Detailed Component Design

CDN - We host our frontend in this. I will be able to handle millions of request and is available on edge. It even acts as the first layer of cache where most of the read requests are taken care off.


API Gateway routes the traffic based on the api that is getting hit. This also helps in rate limiting/throttling of requests which prevents any DDoS and Brute force attacks.


Load Balancer this is configured with API gateway and is used to distribute the load across the servers hosting our services. Keeping the traffic uniform and capable of handling the spike in traffic.


CheckIn/Out service - Handles the Check in and Check out of vehicles from the lots. Even can handle early check outs.


Payment Service - specifically made to handle payment related tasks like payment after selecting a lot to park in.


Reservation Service - Handles the reserving the lots for vehicles and gets you all the reservations that are currently made.


When a user selects a lot to reserve it. It will block the row until he pays. If the user fails to pay and the lot is selected by other user it will be blocked for the new user.


Kafka Queue - Takes in the events that the services create and pushes the data into the DB and Redis.


Cleanup Service - Service used to keep the redis cluster clean by removing the rows after ttl expiry. Can also invalidate the cache in CDN.


Database - we are using postgres for our database as mentioned in the High level design.


Redis - Is used to cache the data for better read request delivery.