Bird
0
0
LLDsystem_design~25 mins

Emergency handling in LLD - System Design Exercise

Choose your learning style9 modes available
Design: Emergency Handling System
Includes alert intake, classification, dispatch, status updates, and tracking. Excludes physical responder operations and external communication networks.
Functional Requirements
FR1: Receive emergency alerts from users via multiple channels (phone, app, SMS).
FR2: Automatically detect emergency type (fire, medical, police) and location.
FR3: Dispatch appropriate emergency responders quickly.
FR4: Allow responders to update status and communicate with control center.
FR5: Provide real-time tracking of emergency response progress.
FR6: Store all emergency events and actions for audit and analysis.
Non-Functional Requirements
NFR1: Handle up to 10,000 concurrent emergency alerts.
NFR2: API response time for alert receipt must be under 200ms (p99).
NFR3: System availability must be 99.9% uptime (max 8.77 hours downtime/year).
NFR4: Data consistency for emergency status updates must be strong.
NFR5: Secure sensitive user and location data with encryption.
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
❓ Question 6
Key Components
API Gateway for receiving alerts
Alert Classification Service
Dispatch Service
Responder Communication Module
Real-time Tracking Service
Database for storing events and statuses
Authentication and Authorization Service
Notification Service
Design Patterns
Event-driven architecture for alert processing
CQRS for separating read and write workloads
Circuit breaker for external service calls
Retry and fallback mechanisms
Geo-location indexing for quick location queries
Reference Architecture
                +---------------------+
                |  User Devices       |
                | (Phone, App, SMS)   |
                +----------+----------+
                           |
                           v
                +---------------------+
                |    API Gateway      |
                +----------+----------+
                           |
           +---------------+---------------+
           |                               |
           v                               v
+---------------------+         +---------------------+
| Alert Classification |         | Authentication &    |
| Service             |         | Authorization       |
+----------+----------+         +----------+----------+
           |                               |
           v                               v
+---------------------+         +---------------------+
| Dispatch Service     |         | Notification Service|
+----------+----------+         +----------+----------+
           |                               |
           v                               v
+---------------------+         +---------------------+
| Responder Comm.     |         | Real-time Tracking   |
| Module              |         | Service             |
+----------+----------+         +----------+----------+
           |                               |
           +---------------+---------------+
                           |
                           v
                  +---------------------+
                  |    Database          |
                  +---------------------+
Components
API Gateway
RESTful API with HTTPS
Receive emergency alerts from users securely and route to classification.
Alert Classification Service
Microservice with ML-based classifier
Identify emergency type and extract location from alert data.
Dispatch Service
Microservice with rules engine
Assign appropriate responders based on emergency type and location.
Responder Communication Module
WebSocket and push notifications
Enable two-way communication and status updates with responders.
Real-time Tracking Service
Streaming data processor
Track responder locations and emergency progress live.
Database
Relational DB (PostgreSQL) with spatial extensions
Store emergency events, user data, responder status, and audit logs.
Authentication & Authorization Service
OAuth 2.0 / JWT
Secure access for users and responders.
Notification Service
Push notification system (e.g., Firebase, SMS gateway)
Send alerts and updates to users and responders.
Request Flow
1. User sends emergency alert via phone, app, or SMS to API Gateway.
2. API Gateway authenticates request and forwards alert to Alert Classification Service.
3. Classification Service determines emergency type and extracts location.
4. Dispatch Service receives classified alert and assigns responders based on rules.
5. Responder Communication Module notifies responders and enables status updates.
6. Responders update status and location, sent to Real-time Tracking Service.
7. Tracking Service updates emergency progress visible to control center.
8. All events and updates are stored in the Database for audit and analysis.
Database Schema
Entities: - User (user_id PK, name, contact_info, encrypted_data) - EmergencyAlert (alert_id PK, user_id FK, type, location, timestamp, status) - Responder (responder_id PK, name, role, contact_info, status) - DispatchRecord (dispatch_id PK, alert_id FK, responder_id FK, assigned_time, status) - StatusUpdate (update_id PK, dispatch_id FK, timestamp, location, status_detail) Relationships: - User 1:N EmergencyAlert - EmergencyAlert 1:N DispatchRecord - DispatchRecord 1:N StatusUpdate - Responder 1:N DispatchRecord
Scaling Discussion
Bottlenecks
API Gateway overload with high concurrent alert volume.
Classification Service latency under heavy load.
Database write contention for status updates.
Real-time tracking data processing bottleneck.
Notification Service delays during peak times.
Solutions
Use load balancers and auto-scaling groups for API Gateway.
Implement asynchronous processing and batch classification with message queues.
Use database sharding and optimized indexing for writes.
Adopt stream processing platforms (e.g., Apache Kafka, Flink) for tracking data.
Use multiple notification providers and rate limiting to handle spikes.
Interview Tips
Time: Spend 10 minutes understanding requirements and clarifying scope, 20 minutes designing components and data flow, 10 minutes discussing scaling and trade-offs, 5 minutes summarizing.
Clarify emergency types and user channels early.
Explain choice of event-driven architecture for responsiveness.
Discuss data consistency needs for status updates.
Highlight security and privacy considerations.
Address scaling challenges with concrete solutions.
Show understanding of real-time communication and tracking.