Bird
0
0
LLDsystem_design~25 mins

Entry and exit flow in LLD - System Design Exercise

Choose your learning style9 modes available
Design: Entry and Exit Flow System
Design covers the flow of users entering and exiting a facility with tracking and control. Out of scope are physical hardware details like gates or sensors.
Functional Requirements
FR1: Allow users to enter through a controlled entry point
FR2: Allow users to exit through a controlled exit point
FR3: Track entry and exit times for each user
FR4: Prevent unauthorized entry or exit
FR5: Support up to 1000 concurrent users entering or exiting
FR6: Provide real-time status of current users inside
Non-Functional Requirements
NFR1: System must respond to entry or exit requests within 200ms
NFR2: Availability target of 99.9% uptime
NFR3: Support peak load of 1000 concurrent entry/exit requests
NFR4: Ensure data consistency for entry and exit records
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
Authentication service for user verification
Entry and exit controllers managing gate access
Database to store entry and exit logs
Real-time dashboard for monitoring current users inside
Notification system for alerts on unauthorized access
Design Patterns
Event-driven architecture for entry and exit events
State machine pattern to track user status (inside/outside)
Circuit breaker for gate control to handle failures
Caching for quick access to current user status
Reference Architecture
User --> Entry Controller --> Auth Service --> Database
       |                 |               |
       v                 v               v
    Exit Controller --> Auth Service --> Database
       |
       v
    Monitoring Dashboard
Components
Entry Controller
Lightweight REST API service
Handles user entry requests, verifies identity, and controls gate access
Exit Controller
Lightweight REST API service
Handles user exit requests, verifies identity, and controls gate access
Authentication Service
OAuth 2.0 or custom auth service
Verifies user identity before allowing entry or exit
Database
Relational DB (e.g., PostgreSQL)
Stores entry and exit logs with timestamps and user status
Monitoring Dashboard
Web dashboard with WebSocket updates
Displays real-time count and list of users currently inside
Request Flow
1. User requests entry at Entry Controller
2. Entry Controller calls Authentication Service to verify user
3. If verified, Entry Controller records entry time in Database
4. Entry Controller signals gate to open for user entry
5. User enters facility
6. User requests exit at Exit Controller
7. Exit Controller calls Authentication Service to verify user
8. If verified and user is inside, Exit Controller records exit time in Database
9. Exit Controller signals gate to open for user exit
10. Monitoring Dashboard queries Database or listens to events to update current users inside
Database Schema
Entities: - User: user_id (PK), name, credentials - EntryExitLog: log_id (PK), user_id (FK), entry_time, exit_time Relationships: - One User can have many EntryExitLog records - EntryExitLog tracks paired entry and exit times per user
Scaling Discussion
Bottlenecks
Authentication Service becoming slow under high concurrent requests
Database write contention for entry and exit logs
Real-time dashboard lagging with many users inside
Gate control communication delays
Solutions
Use caching or token-based authentication to reduce auth service load
Partition database by user or time to reduce write contention
Use event streaming (e.g., Kafka) to push updates to dashboard efficiently
Implement retries and circuit breakers for gate control communication
Interview Tips
Time: Spend 10 minutes clarifying requirements and constraints, 20 minutes designing components and data flow, 10 minutes discussing scaling and trade-offs, 5 minutes summarizing.
Clarify user verification and security needs
Explain separation of entry and exit controllers for clarity
Describe database schema supporting tracking of user presence
Discuss real-time monitoring importance
Address scaling challenges and solutions clearly