Assuming 1 out of 7 person owns a 4-Wheeler. 1/10th of these would use our service daily: 100 million people.
Data required to store single transaction ~ 100 B
Number of records inserted daily: 100 million * 100 B = 10 GB.
For 1 year = 3TB
Estimating for 10 Years = 30TB
As all of these entries will be modifying db, these cannot be Get calls
-- Table [ParkingTransactions] --
UniqueId ( uuid )
VehicleNumber ( 20 chars )
InTime ( dateTime )
OutTime ( dateTime )
ElectricConsumption ( number )
SlotAlotted (FK: string)
TransactionId ( FK )
ParkingBuildingId ( FK )
-- Table [ParkingSpace] --
MarkingNumber ( string )
BuildingDeatails
BuildingAdderss
MetaInfo (string)
State ( Enum )
-- Table [Transaction] --
UUID
Details
-- Table [PreBooking] --
CustomerId (FK)
RequestedStartTime ( DateTime )
Transaction ()
-- Table [Customer] --
CustomerId ( PK )
CustomerMetadata
Table ParkingTransactions can be sharded based on ParkingBuildingId.
Services:
Each component is horizontal scalable.
Every micro-service has its own database, and no sharing of DB is allowed.
On Entering the building, vehicle is scanned to number plate and type. Post request is sent to "ParkService".
A distributed transaction is executed between SlotFinder and ParkService to block required slot and make a transaction entry.
Communication between microservice: gRPC
Communication between client and LB: REST
As we are not generating lot of data, SQL DB would be a fine choice.
Cache: Redis can be used.
ParkService fails: Multiple instance will be running and pointing to same DB.
ParkService DB fails: A db replica is kept in sync in case of failover is required.
similar strategy for each service can be followed.
Natural calamity causing hardware failure: DataCenteres are kept in different geographical locations to avoid hardware failure in one continent
Any service fails to respond: exponential backoff while reissuing request.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?