System requirements
Functional:
- Enter gate:-> Scan the vehicle details, get available spot in the system and create parking ticket and assign spot on the basis of vehicle type.
- Exit Gate:-> Scan ticket, do the ticket processing.
- Do ticket calculation on the base of duration with different type of vehicle.
- We should have different type of user also like normal, premier and VIP.
- Support multiple payment mode.
- We ned to check also unauthorize parking spot which violating the spot occupied policy then we will notify the user,
- Proper assignment of vehicle with weight and size of the vehicle in the parking spot
- If parking lot is full then suggest near by parking spot to the user
Non-Functional:
- Availability of the system with horizontal scaling.
- Consistency of the system using any sql or nonspl database. Best option is using sql database like mysql
- Less latency to assign the spot and processing the ticket for calculation. We can use redis cache to reduce latency.
- We can use kafka queue for inter communication between different microservices like entry service, exit service, payment service and neareast calculation service.
- We can add monitoring, looging and alerting in the system for worst case scenario
- Add security to admin services with authenication service
- Security for payment processing
- Fault tolerant and recover from disaster: We can use failover system and geographical server.
Capacity estimation
1000000 vehicle per day in one region
Schema contains vehicle number, allocation spot, some more details like entered date and updated at and exit date
2000 byte to store for single vehicle details with all the metadata
2000*10000000*365= 73000000000 bytes = 73 GB to store this info in one region
if we dd payment detail and audit details also= you can multiple 3= 250GB per year we want in the database storage.
Average vehicle enter into system per sec:->
10000000/ (24*60*60)= 100 per sec
Let say in peak time :-> 1000 per sec
we can distribute with horizontal server
API design
/api/v1/parkinglot/service/scanVehicle
/api/v1/parkinglot/service/getAvailableSpot/vehicleType/{vehicleType}
/api/v1/parkingLot/service/assignSpot/vehicle/{vehicle_number}
/api/v1/parkingLot/service/generateTicket/vehicle/{vehicle_number}
/api/v1/parkingLot/service/exitCalculation/vehicle/{vehicle_number}
/api/v1/parkingLot/service/payment/vehicle/{vehicle_number}
Database design
User Table
id, Name, Address, Mobile number, user type
Usertype enum like Admin, guest, Operator
Vehicle Table
id, RC number, Type
ParkingLot
id, name, location, total_gate
ParkingSpot
id, status, SpotType, parkinlot
Ticket
id, vehicle_id, spot_id, enter_time, exit_time, fee, user_id
High-level design
Request flows
Vehicle enter into system, system scan vehicle details and system get avaialble spot in the parkinglot spots and assign available spot for specific type of vehicle.
Exit gate-> User ask to fee calculation for specific spot type and user type
Redis cache used for fast retrieval of spot details for checking available spot and do the calculation with less latency.
Database used for storing the information of spot and vehicle detail.
Payment service will process the payment to release the spot and exit to the system.
Detailed component design
Parkinglot Service
Assign available spot :-> We can use dijkstra's algorithm to find nearest available spot in the system or we can use geospatical database to do this processing.
We can use multiple strategies for fee calculation on the basis of days and seasons.
Redis
It is used for caching the data for fast retrieval and it will give less latency
Payment Service
We can use multiple payment mode for supporting the payment strategies
Trade offs/Tech choices
Load Balancer: ->
Advantage:
It distribute the load evenly, so that single server won't get into overwhelemed state.
Disadvantage:
It is hard to manage many server for deployment and disaster faults
Database SQL:->
Advantage:-> Using sql database ensure consistency into the system and it follow ACID properties.
Disadvantage:->
Making partition tolerant will be hard because we are making system available and consistent
Failure scenarios/bottlenecks
Database can be bottlenecks, if let say all the db instance goes down then all call will block, we need to have multi region database instance or failover database to handle that.
Payment Service also should be bottleneck, if we don't support multiple payment mode in their
Future improvements
- We can add feature like user can book in the advance.
- They can check availablity of the particular parking spot as per vehicle type or user perference for normal, and VIP
- Credit card payment we can add also payment service.
- Add data analysis to generate report about the system.
- Multi floor PARKING Spot also we can support.
- Improve user experience with advance payment for exit process