0
0
LLDsystem_design~25 mins

Availability checking in LLD - System Design Exercise

Choose your learning style9 modes available
Design: Availability Checking System
Design covers availability checking, booking, cancellation, and notification. Out of scope: payment processing, user authentication, and detailed UI design.
Functional Requirements
FR1: Allow users to check availability of resources (e.g., rooms, equipment, or services) for specific time slots
FR2: Support concurrent availability queries from up to 10,000 users
FR3: Allow users to book available resources and update availability in real-time
FR4: Provide notifications if requested resource is unavailable
FR5: Support cancellation and modification of bookings
FR6: Ensure data consistency to prevent double bookings
Non-Functional Requirements
NFR1: System must respond to availability queries within 200ms (p99 latency)
NFR2: System should have 99.9% uptime (less than 8.77 hours downtime per year)
NFR3: Handle up to 1,000 bookings per minute
NFR4: Support eventual consistency for availability updates with strong consistency for booking confirmation
NFR5: Scale horizontally to handle increasing load
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
API Gateway or Load Balancer
Availability Service
Booking Service
Database (Relational or NoSQL)
Cache Layer (e.g., Redis) for fast availability queries
Message Queue for asynchronous notifications
Notification Service
Design Patterns
Cache-Aside pattern for availability data
Eventual consistency with strong consistency for booking confirmation
CQRS (Command Query Responsibility Segregation) to separate read and write models
Optimistic locking or transactions to prevent double booking
Publish-Subscribe pattern for notifications
Reference Architecture
          +-------------+          +----------------+
          |   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            |
                                                      +-------------------+
Components
API Gateway / Load Balancer
Nginx or AWS ALB
Distributes incoming client requests to backend services and handles SSL termination
Availability Service
Custom microservice in chosen language
Handles availability queries using cache and database to provide fast responses
Booking Service
Custom microservice
Processes booking requests, ensures no double booking, updates database and cache
Cache (Redis)
Redis
Stores availability data for fast read access to reduce database load
Database
PostgreSQL or MongoDB
Stores persistent booking and availability data with transactional support
Message Queue
RabbitMQ or Kafka
Queues notification events asynchronously to decouple booking from notification
Notification Service
Custom microservice or third-party service
Sends notifications to users about booking status or availability
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
Scaling Discussion
Bottlenecks
Cache becoming a single point of failure or bottleneck under heavy read load
Database write contention when many bookings happen simultaneously for the same resource
Message queue overload if notification volume spikes
API Gateway limits under very high concurrent connections
Solutions
Use Redis clustering and replication to scale cache and improve availability
Implement sharding or partitioning in database by resource or time to reduce contention
Use multiple message queue partitions and consumers to handle high notification throughput
Deploy multiple API Gateway instances behind a load balancer and use autoscaling
Interview Tips
Time: Spend 10 minutes clarifying requirements and constraints, 20 minutes designing architecture and data flow, 10 minutes discussing scaling and trade-offs, 5 minutes summarizing.
Clarify resource types and booking rules before designing
Explain caching strategy to meet latency requirements
Discuss consistency models and how to prevent double booking
Highlight asynchronous notifications to improve user experience
Address scaling challenges and solutions realistically