Design a Routing and Fleet Management System
Understanding the Problem
🚚 What is a fleet management system? A fleet management system helps a company that runs vehicles (delivery vans, trucks, technicians' cars) know where every vehicle is, decide which vehicle visits which stops in which order, and adapt during the day as jobs are added, drivers run late or a van breaks down. Dispatchers watch the fleet on a live map, drivers follow routes on a phone or in-cab device, and customers get an ETA. Products in this space are usually sold as multi-tenant SaaS to many fleets at once.
You'll hear this asked several ways: "design vehicle tracking for a logistics company," "design a route optimization service," "design a dispatch system for field technicians." They're the same problem with the emphasis in different places: tracking (a high-rate stream of GPS points), routing (an expensive optimization problem) and dispatch (fast decisions that change running routes). We'll cover all three.
It's worth contrasting with ride-sharing up front (see /system-design/ride-sharing). A ride-hailing match pairs one rider with one nearby driver, and the trip is a single A-to-B leg. A fleet vehicle carries dozens of stops a day, with time windows and capacity limits, so assignment means fitting work into an existing sequence, not just picking the nearest car.
Functional Requirements
Core Requirements
- Vehicles should report their location continuously, and dispatchers should see the whole fleet live on a map, as well as replay any vehicle's past track.
- Dispatchers should be able to plan a day: given the stops (locations, time windows, service times, package sizes) and the available vehicles, the system should assign stops to vehicles and order them into efficient routes.
- Drivers should receive their route on their device, and dispatchers and customers should see an up-to-date ETA for every stop.
- The system should dispatch new or changed jobs during the day: insert an urgent job into the best vehicle's route, and reassign stops when a vehicle can't finish.
Below the line (out of scope)
- Turn-by-turn navigation and map rendering. We'll use a maps SDK on the device and focus on what stops to drive to, in what order (see /system-design/google-maps for how routing on a road graph works).
- Vehicle diagnostics (engine codes, fuel), driver hours-of-service compliance and payroll.
- The customer-facing ordering system that creates the jobs.
Non-Functional Requirements
Ask about scale. Say we serve 5,000 tenant fleets with 200,000 vehicles on the road at peak. Devices report a location every 5 seconds while moving. A large tenant plans 10,000 stops across 500 vehicles out of one depot each morning, and the whole platform plans around 8 million stops a day.
Core Requirements
- The live map should reflect a vehicle's position within about 5 seconds.
- Location ingestion must be highly available and must not lose points, since tracks are used for disputes and compliance. Keep a year of history.
- Planning a large depot (10,000 stops) should finish within about 10 minutes, with good (not necessarily optimal) routes.
- Inserting an urgent job into a running route should take a few seconds.
- Drivers must be able to keep working through poor or absent connectivity.
Below the line (out of scope)
- Provably optimal routes. Nobody can compute those at this size.
- Cross-tenant optimization (sharing vehicles between companies).
Let's do the math, because the three parts of the system have completely different shapes.
Tracking writes. 200,000 vehicles / 5 s = 40,000 location updates per second. Per day that's 40k × 86,400 ≈ 3.5 billion points. At around 40 bytes per point after compression (vehicle, timestamp, lat, lng, speed, heading, accuracy), that's about 140 GB a day, or roughly 50 TB for a year of history. A steady, write-heavy stream.
Planning compute. A route optimizer needs travel times between every pair of stops. For 10,000 stops, that's 10,000² = 100 million pairs. Stored as 4-byte seconds, the duration matrix alone is about 400 MB, and computing it needs many-to-many shortest paths over a road network. This is a CPU-heavy batch job, bursty around the morning planning window.
Dispatch. Low volume (maybe tens of new urgent jobs per second across all tenants), but each one has to evaluate many candidate vehicles quickly.
These three workloads (a write-heavy stream, a CPU-heavy batch job, and a latency-sensitive decision) want different infrastructure. Saying so early, and splitting them into separate services, is the most important structural decision in the design.