Design a Cab Service for Office Employees

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-05-14

Problem Statement

Design a Cab Service System for Office Employees that allows employees of an organization to book cabs for office commute (home-to-office and office-to-home) while optimizing routes, costs, and utilization.


The system should efficiently manage ride scheduling, cab allocation, route optimization, and employee safety, while ensuring punctual pickups and real-time tracking.


🎯 Core Requirements


Functional Requirements

1.
2.Employee Registration & Management
•Employees register with their employee ID, home location, and office shift timing.
•Admin can manage employee profiles and route preferences.
3.
4.Cab Booking
•Employees can schedule daily office rides or book ad-hoc rides (if supported).
•System should automatically assign cabs based on proximity, shift time, and route overlap.
5.
6.Cab Assignment & Routing
•Optimize cab allocation to minimize travel distance and maximize seat utilization.
•Generate an optimal pickup route considering multiple employees in the same area.
7.
8.Real-time Tracking
•Allow employees and admins to track cab location and ETA in real-time.
9.
10.Shift-based Scheduling
•System should handle different office shifts (morning, evening, night).
•Automatically schedule rides based on shift start and end times.
11.
12.Notifications & Alerts
•Notify employees of cab assignment, driver details, pickup time, and delays.
•Send emergency alerts or SOS signals if needed.
13.
14.Admin Dashboard
•Monitor all rides, cab status, and route efficiency.
•View analytics on utilization, delay reports, and cost optimization.
15.
16.Driver Management
•Register drivers and vehicles.
•Manage cab capacity, availability, and route assignment.


⚙️ Non-Functional Requirements


Attribute with Goal


Scalability

Handle 10,000+ employees across multiple offices


Latency

Real-time cab tracking with <100ms updates


Availability

99.9% uptime


Reliability

Ensure accurate and timely cab assignment


Security

Secure employee and location data


Cost Optimization

Optimize routes to minimize fleet cost


🧩 Core Components


Component with Description


User Service


Manages employee profiles, preferences, and authentication


Cab & Driver Service


Manages cabs, drivers, and capacity


Ride Management Service


Core logic for booking, scheduling, and routing


Routing/Optimization Engine


Calculates optimal routes using mapping APIs


Notification Service


Sends SMS/Email/App notifications


Tracking Service


Tracks real-time cab GPS data


Admin Dashboard


Allows administrators to monitor and manage operations


Database Layer


Stores user, ride, route, and vehicle data


Analytics Service


Provides insights on performance, costs, and utilization


🧱 High-Level Architecture

1 2 +-------------------------+ 3 | Employee Portal | 4 +-----------+-------------+ 5 | 6 +-----------v-------------+ 7 | API Gateway | 8 +-----------+-------------+ 9 | 10 +---------------------------------------------------+ 11 | Application Layer | 12 +---------------------------------------------------+ 13 | User Svc | Ride Svc | Cab Svc | Tracking Svc| 14 +---------------------------------------------------+ 15 | 16 +-----------v-------------+ 17 | Routing/Optimization | 18 | Engine (Maps API) | 19 +-----------+-------------+ 20 | 21 +---------------------------------------------------+ 22 | Data Layer | 23 +---------------------------------------------------+ 24 | Employee DB | Ride DB | Vehicle DB | Route Cache | 25 | (SQL/NoSQL) | (NoSQL) | (SQL) | (Redis) | 26 +---------------------------------------------------+ 27 | 28 +-----------v-------------+ 29 | Notification / Alert Svc| 30 +-----------+-------------+ 31 | 32 +-----------v-------------+ 33 | Admin Dashboard / Ops | 34 +-------------------------+


🧠 Key Flows


🕗 1. Ride Scheduling Flow


1.Employees set home & office address, and shift timing.
2.System automatically schedules rides before shift start.
3.Optimization engine clusters employees with similar locations.
4.Ride Service assigns drivers & cabs accordingly.
5.Notifications are sent with cab details and pickup time.


🚖 2. Real-time Tracking Flow


1.Each cab has a GPS device or app sending coordinates to the Tracking Service.
2.Tracking Service updates Redis with cab location every few seconds.
3.Employee and Admin UI pull real-time updates from Redis.


⚙️ 3. Route Optimization Flow


•Routing Engine uses APIs (e.g., Google Maps, OpenStreetMap) to:
•Compute shortest path.
•Merge pickup points efficiently.
•Update ETA dynamically based on traffic.


🧱 Data Model (Simplified)


Employee

1 2{ 3 "employee_id": "E1234", 4 "name": "Sahil Batra", 5 "home_location": "12.93,77.59", 6 "office_location": "12.97,77.64", 7 "shift_time": "09:00 AM", 8 "preferred_pickup_time": "08:15 AM" 9}


Cab

1 2{ 3 "cab_id": "C101", 4 "driver_id": "D45", 5 "capacity": 4, 6 "current_location": "12.95,77.61", 7 "status": "AVAILABLE" 8}


Ride

1 2{ 3 "ride_id": "R567", 4 "cab_id": "C101", 5 "employee_ids": ["E1234", "E5678"], 6 "pickup_points": ["12.93,77.59", "12.94,77.60"], 7 "status": "SCHEDULED", 8 "route": "List of coordinates" 9}


⚡ Scalability Considerations


| Feature | Design Choice |

| ----------------- | ------------------------------------------------- |

| **Routing** | Use distributed job workers for route computation |

| **Tracking** | Use Redis or Kafka for real-time location stream |

| **Scheduling** | Batch scheduling jobs per shift |

| **Data Storage** | SQL for users, NoSQL for rides |

| **Load Handling** | Horizontal scaling via microservices |

| **Async Updates** | Event-driven using Kafka or RabbitMQ |


🔒 Security & Safety


•JWT-based authentication for employees and drivers.
•Encrypt location data in transit (TLS).
•Role-based access (Employee, Admin, Driver).
•SOS feature with admin notification in case of emergency.
•Location anonymization for privacy.


📊 Admin Dashboard Features


•Real-time cab and employee tracking.
•Reports on ride utilization, delays, and cancellations.
•Route optimization analytics and cost summaries.
•Driver performance and feedback management.


🧩 Tech Stack (Example)


| Layer | Technology |

| ----------------- | ---------------------------------- |

| **Frontend** | React / Angular |

| **Backend** | Node.js / Java Spring Boot / Go |

| **Database** | PostgreSQL + MongoDB + Redis |

| **Message Queue** | Kafka / RabbitMQ |

| **Tracking** | WebSocket + GPS device integration |

| **Maps API** | Google Maps / OpenStreetMap |

| **Deployment** | Kubernetes + Docker + Azure/AWS |


🚀 Key Challenges

Challenge with Solution


Route Optimization (NP-hard)

Use clustering (K-Means) + heuristics


Concurrent Shift Scheduling

Partition jobs by shift and zone


Location Accuracy

GPS smoothing + caching


Cab Utilization vs. Employee Comfort

Weighted algorithm for optimal grouping


Scalability during Shift Peaks

Autoscaling + async job queues


✅ Goal:

Design a secure, reliable, and cost-optimized cab service system that provides timely office commute, real-time tracking, and smart route optimization for thousands of employees.

Solution

Comments