+-------------+ +----------------+
| Clients | <------> | API Gateway / |
+-------------+ | Load Balancer |
+-------+--------+
|
+----------------------+--------------------+
| |
+---------v---------+ +---------v---------+
| Availability | | Booking Service |
| Service (Cache + | | (Handles booking, |
| DB) | | cancellation) |
+---------+---------+ +---------+---------+
| |
| |
+---------v---------+ +---------v---------+
| Cache (Redis) | | Database (SQL or |
| for fast reads | | NoSQL with strong |
+-------------------+ | consistency) |
+---------+---------+
|
+---------v---------+
| Message Queue |
| (Notifications) |
+---------+---------+
|
+---------v---------+
| Notification |
| Service |
+-------------------+Request Flow
1. 1. Client sends availability query to API Gateway.
2. 2. API Gateway forwards request to Availability Service.
3. 3. Availability Service checks Redis cache for requested resource and time slot.
4. 4. If cache miss, Availability Service queries database and updates cache.
5. 5. Availability Service returns availability status to client.
6. 6. Client sends booking request to API Gateway.
7. 7. API Gateway forwards booking request to Booking Service.
8. 8. Booking Service checks availability (cache and database) to prevent double booking.
9. 9. Booking Service uses transaction or optimistic locking to reserve resource in database.
10. 10. Booking Service updates cache to reflect new availability.
11. 11. Booking Service publishes booking event to Message Queue.
12. 12. Notification Service consumes event and sends confirmation or failure notification to client.
13. 13. Client can send cancellation or modification requests handled similarly by Booking Service.
Database Schema
Entities:
- Resource: id (PK), name, type, description
- Booking: id (PK), resource_id (FK), user_id, start_time, end_time, status
- User: id (PK), name, contact_info
Relationships:
- Resource 1:N Booking (one resource can have many bookings)
- User 1:N Booking (one user can have many bookings)
Constraints:
- Booking time ranges must not overlap for the same resource
- Status indicates active, cancelled, or completed bookings