| Users (People) | Requests per Minute | Elevators Needed | System Complexity | Latency (Wait Time) |
|---|---|---|---|---|
| 100 | 50 | 1 | Simple: Single elevator, direct request handling | Low (seconds) |
| 10,000 | 5,000 | 10-20 | Moderate: Multiple elevators, request queueing, scheduling | Moderate (tens of seconds) |
| 1,000,000 | 500,000 | 100+ | Complex: Distributed control, load balancing, fault tolerance | Variable, optimized by scheduling algorithms |
| 100,000,000 | 50,000,000 | Thousands | Very complex: Multi-building coordination, advanced predictive scheduling | Challenging, requires AI and real-time analytics |
Elevator, Floor, Request classes in LLD - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small scale (100 users), the bottleneck is the elevator's mechanical speed and door operation time.
At medium scale (10,000 users), the bottleneck is the request processing and scheduling logic in the control system, as many requests compete for limited elevators.
At large scale (1 million+ users), the bottleneck shifts to communication and coordination between multiple elevator controllers and the central system, plus data processing delays.
- Horizontal Scaling: Add more elevators to serve more requests concurrently.
- Load Balancing: Distribute requests evenly among elevators to avoid congestion.
- Caching: Cache frequent floor requests or patterns to optimize scheduling.
- Sharding: Divide floors or buildings into zones, each managed by separate controllers.
- Predictive Scheduling: Use historical data to anticipate demand and pre-position elevators.
- Fault Tolerance: Implement fallback mechanisms if an elevator or controller fails.
- Requests per second at 10,000 users: ~83 (5,000 requests/min ÷ 60)
- Each elevator can handle ~5-10 requests per minute depending on speed and stops.
- Storage for request logs: Minimal, a few KB per request, scaling to GBs at large scale.
- Network bandwidth: Low per request, mostly control signals; scales with number of elevators and controllers.
- CPU: Scheduling algorithms run in milliseconds; more elevators increase CPU needs linearly.
Start by defining the scale and key components: elevators, floors, requests.
Discuss how requests flow from users to elevators and how scheduling works.
Identify bottlenecks at each scale and propose targeted solutions.
Use real-world analogies like traffic lights or taxi dispatch to explain scheduling.
Always mention trade-offs: cost vs. latency vs. complexity.
Your elevator control system handles 1000 requests per minute. Traffic grows 10x. What do you do first?
Answer: Add more elevators (horizontal scaling) and improve scheduling algorithms to handle increased requests efficiently.
Practice
Request class in an elevator system?Solution
Step 1: Understand the purpose of Request class
The Request class holds information about where a user wants to go and in which direction.Step 2: Compare roles of other classes
Elevator moves and Floor represents building levels, but Request stores user input details.Final Answer:
To store the floor number and direction of a user's request -> Option AQuick Check:
Request = user floor and direction [OK]
- Confusing Request with Elevator movement
- Thinking Request controls doors
- Mixing Request with Floor class responsibilities
Request class constructor in Python to store floor and direction?Solution
Step 1: Recall Python constructor syntax
Python constructors usedef __init__(self, ...)and assign attributes withself.attribute = value.Step 2: Check each option
def __init__(self, floor, direction): self.floor = floor; self.direction = direction correctly usesselfand assigns floor and direction. Others missselfor parameters.Final Answer:
def __init__(self, floor, direction): self.floor = floor; self.direction = direction -> Option BQuick Check:
Constructor with self and attributes = def __init__(self, floor, direction): self.floor = floor; self.direction = direction [OK]
- Omitting self parameter
- Using class name as constructor
- Not assigning attributes to self
class Request:
def __init__(self, floor, direction):
self.floor = floor
self.direction = direction
r = Request(5, 'up')
print(r.floor, r.direction)Solution
Step 1: Understand object creation and attribute assignment
The Request object r is created with floor=5 and direction='up'. These are stored in attributes.Step 2: Print attributes
Printingr.floorandr.directionoutputs 5 and 'up' respectively.Final Answer:
5 up -> Option CQuick Check:
Attributes print as assigned = 5 up [OK]
- Expecting attribute names instead of values
- Confusing class variables with instance variables
- Assuming error without checking code carefully
class Elevator:
def __init__(self, current_floor):
self.current_floor = current_floor
def move_to(self, floor):
current_floor = floor
Solution
Step 1: Analyze move_to method
The method assignscurrent_floor = floorwithoutself., so it changes a local variable only.Step 2: Understand instance variable update
To update the elevator's floor, it should beself.current_floor = floor.Final Answer:
The move_to method updates a local variable, not the elevator's floor -> Option DQuick Check:
Missing self. means local variable used [OK]
- Forgetting self. prefix
- Thinking return is needed to update state
- Assuming indentation is wrong without checking
Elevator, Floor, and Request classes, which approach best handles multiple simultaneous requests efficiently?Solution
Step 1: Understand multiple request handling
Efficient elevator systems prioritize requests to minimize travel and wait time.Step 2: Evaluate options for request processing
Using a priority queue to pick nearest floors and matching direction optimizes movement. Others cause inefficiency or randomness.Final Answer:
Use a priority queue in Elevator to process requests by nearest floor and direction -> Option AQuick Check:
Priority queue for nearest requests = Use a priority queue in Elevator to process requests by nearest floor and direction [OK]
- Ignoring direction leads to inefficient routes
- Random assignment causes delays
- Processing requests strictly by arrival order wastes time
