| Scale | Number of Floors | Parking Spots | Vehicles Parked Concurrently | Requests per Second (Entry/Exit) |
|---|---|---|---|---|
| 100 users | 1-2 floors | 50-100 spots | 30-50 vehicles | 10-20 requests/sec |
| 10K users | 5-10 floors | 500-1000 spots | 400-700 vehicles | 200-500 requests/sec |
| 1M users | 20-50 floors | 10,000-20,000 spots | 8,000-15,000 vehicles | 5,000-8,000 requests/sec |
| 100M users | 100+ floors (multiple lots) | 1,000,000+ spots | 800,000+ vehicles | 500,000+ requests/sec |
Class identification (ParkingLot, Floor, Spot, Vehicle) in LLD - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small scale, the database is the first bottleneck. It stores data about floors, spots, and vehicles. As users increase, the database struggles to handle many read/write requests for parking spot availability and vehicle entry/exit.
At medium scale, the application server CPU and memory become bottlenecks due to processing many concurrent requests and managing state.
At large scale, network bandwidth and data partitioning become critical to handle massive traffic and data volume.
- Database: Use read replicas to handle read-heavy traffic. Implement connection pooling to manage database connections efficiently.
- Caching: Cache frequently accessed data like available spots per floor to reduce database load.
- Application Servers: Horizontally scale by adding more servers behind a load balancer to distribute traffic.
- Data Partitioning: Shard the database by parking lot or floor to distribute data and reduce contention.
- Network: Use CDNs for static content (e.g., parking rules, maps) and optimize APIs for minimal data transfer.
- At 1M users, expect ~5,000-8,000 requests/sec for entry/exit updates.
- Storage needed: Each vehicle record ~1KB, so 15,000 vehicles = ~15MB active data; historical logs add more.
- Bandwidth: Assuming 1KB per request, 8,000 req/sec = ~8MB/sec (~64Mbps), manageable with standard network setups.
Start by defining system scale and key components (ParkingLot, Floor, Spot, Vehicle). Identify which component handles the most load. Discuss bottlenecks at each scale and propose targeted solutions. Use real numbers to justify your choices. Always mention trade-offs and how to monitor system health.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas and implement caching to reduce direct database load. Also, optimize queries and use connection pooling before considering more complex solutions.
Practice
Solution
Step 1: Understand the role of ParkingLot
The ParkingLot class represents the entire parking area and manages multiple floors within it.Step 2: Compare with other classes
Floor manages spots on a single level, Spot represents a single parking space, and Vehicle represents the car or bike.Final Answer:
ParkingLot -> Option AQuick Check:
ParkingLot manages floors = C [OK]
- Confusing Floor as managing multiple floors
- Thinking Spot manages floors
- Assigning Vehicle to manage floors
Solution
Step 1: Identify the class representing a parking spot
The Spot class should have attributes like spotNumber and isOccupied to represent a parking space.Step 2: Check other classes for correctness
Vehicle represents cars, Floor represents a level, and ParkingLot represents the whole area, so they should not have spotNumber or isOccupied attributes.Final Answer:
class Spot { int spotNumber; boolean isOccupied; } -> Option BQuick Check:
Spot class holds spot info = A [OK]
- Assigning spot attributes to Vehicle
- Putting spotNumber in Floor or ParkingLot
- Confusing class roles in diagram
class Vehicle {
String licensePlate;
Vehicle(String plate) { licensePlate = plate; }
}
class Spot {
Vehicle parkedVehicle;
boolean isOccupied() { return parkedVehicle != null; }
}
Spot spot = new Spot();
System.out.println(spot.isOccupied());Solution
Step 1: Analyze Spot initialization
The Spot object is created but parkedVehicle is not assigned, so it defaults to null.Step 2: Evaluate isOccupied method
isOccupied returns true if parkedVehicle is not null; here it is null, so it returns false.Final Answer:
false -> Option DQuick Check:
parkedVehicle is null, so isOccupied() = false [OK]
- Assuming default boolean is true
- Confusing null with false
- Expecting compilation error due to missing constructor
class Floor {
List<Spot> spots;
void addSpot(Spot s) {
spots.add(s);
}
}Solution
Step 1: Check initialization of spots list
The spots list is declared but not initialized, so calling add on it will cause a runtime error.Step 2: Validate other options
Returning boolean is optional, Spot class can be separate, and Floor should have spots list to manage spots.Final Answer:
spots list is not initialized before adding -> Option CQuick Check:
Uninitialized list causes error = A [OK]
- Ignoring list initialization
- Thinking method return type matters here
- Believing Spot must be nested class
Solution
Step 1: Understand size matching requirement
Both Vehicle and Spot need size attributes to compare and ensure compatibility.Step 2: Evaluate options
Ignoring size in either class prevents proper matching; removing size ignores requirement.Final Answer:
Add a size attribute to both Vehicle and Spot classes and check compatibility before parking -> Option AQuick Check:
Size match needs attributes in both classes = B [OK]
- Adding size to only one class
- Ignoring size and allowing any parking
- Confusing attribute placement
