Documentation Index
Fetch the complete documentation index at: https://mintlify.com/donnemartin/system-design-primer/llms.txt
Use this file to discover all available pages before exploring further.
Problem Statement
Design a call center system that routes incoming calls to available employees based on a hierarchy, with escalation support when employees cannot handle calls.Constraints and Assumptions
- Employee levels: Operator, Supervisor, Director
- Call routing: Operators always get initial calls
- Escalation: If no operator is available or they can’t handle the call, escalate to supervisors, then directors
- Director capability: Directors can handle all calls
- Queuing: Calls are queued if nobody can answer
- No VIP support: All calls have equal priority
- Valid inputs: Assume inputs are valid
Design Overview
The call center system uses several classes implementing a hierarchy pattern:- Rank: Enum defining employee levels
- Employee: Abstract base class for all employee types
- Operator, Supervisor, Director: Concrete employee implementations
- Call: Represents an incoming call
- CallCenter: Orchestrates call routing and queuing
This design uses the Chain of Responsibility pattern, where calls are passed through a hierarchy of handlers (operators → supervisors → directors) until one can handle it.
Implementation
Rank Enumeration
Defines the employee hierarchy:Employee Base Class
Abstract class with common employee functionality:Concrete Employee Classes
Each level implements the escalation logic:Call Classes
Represent call state and properties:CallCenter Class
Orchestrates call routing and management:Key Design Patterns
Chain of Responsibility
Calls cascade through levels until handled:Abstract Factory Pattern
TheEmployee abstract base class defines the interface, with concrete implementations for each rank level.
Observer Pattern
Thenotify_call_completed() and notify_call_escalated() methods allow the call center to react to state changes.
Complexity Analysis
| Operation | Time Complexity | Notes |
|---|---|---|
| dispatch_call() | O(n) | Where n is the number of employees at each level |
| take_call() | O(1) | Direct assignment |
| escalate_call() | O(1) | State update and notification |
Design Considerations
Advantages
- Clear hierarchy: Well-defined escalation path
- Flexible: Easy to add new employee types or ranks
- Separation of concerns: Each class has a single responsibility
- Extensible: Can add features like call priority or specialized routing
Call Flow
- Call arrives → Assigned OPERATOR rank initially
- Dispatch attempt → Try to find available operator
- Escalate if needed → Move up hierarchy
- Queue if all busy → Store in deque for later
- Complete call → Free employee for next call
Potential Improvements
- Priority queue: Support VIP or urgent calls
- Skills-based routing: Route calls based on employee expertise
- Load balancing: Distribute calls evenly among available employees
- Call statistics: Track metrics like wait time, handle time, escalation rate
- Automated callbacks: Call customers back when employee becomes available
- Concurrent handling: Use threading for simultaneous call processing
- Call recording: Log conversations for quality assurance
