Estimate the scale of the system you are going to design...
vehicle_enter(parking_lot_id, vehicle_type); return a number that can be a ticket_id
vehicle_exit(parking_lot_id, ticket_id, vehicle_type);
check whether the ticket has been paid or not: if not paid, return false, otherwise, return true.
pay(parking_lot_id, ticket_id): return a receipt number.
show_capacity(parking_lot_id): return the current capacity.
parking_lot:
parking_lot_id,
lot_capacity_id,
status
lot_capacity:
lot_capacity_id,
spot_type (Compact, Large, Handicapped, Motorcycle, etc. ),
spot_capacity,
spot_used_number
user_record:
ticket_id,
parking_lot_id,
start_time,
end_time,
receipt_number,
status (using, leave)
transaction:
receipt_id,
ticket_id,
payment_method,
payment_time,
status(paid, confirmed)
Payment service might have a high possibility of shutdown, so it may need to design concisely when users are paying for fee. When the user has submit the payment request to the parking service, parking_service will not only just send a request to MQ, but also generate a receipt number to the user, which will be also stored into the transaction table. During the downtime of payment service, when users can exit the parking lot, parking_service will check the receipt_id exists or not, if the receipt exists, the user will be allow to leave. After the payment service back online, it will return the payment status to the parking_service and parking_service will update the receipt that are in paid status to confirmed status. This approach actually implements a local payment record to keep track of the user parking status.
The biggest decision point was the database. For this service, I chose Relational Database over NoSQL Database. Because RDB provides strong consistency, which is beneficial for a payment service. Users can not leave util they pay for their parking fee, which is need to be 100% sure in this situation.
NoSQL database, for example MongoDB, would provide a better horizontal scalability than RDB. But for this service, I decided the benefit of RDB outweighs that of NoSQL DB.