Designing a Freight Logistics Platform (Uber Freight)
Difficulty: Advanced Topics: Geo Matching, Real-Time Tracking, Route Optimization, Allocation, WebSocket Asked at: Uber Freight, Rivigo, BlackBuck, Delhivery, Amazon Logistics · Prerequisites: Geospatial Indexing, WebSockets, Message Queues, and Caching
1. Understanding the Problem
A freight logistics platform connects shippers (companies with cargo) to carriers (truck owners/drivers). A shipper posts a shipment request with source, destination, weight, and pickup window. The system finds the best available truck considering proximity, route alignment, and capacity, assigns it, and then provides real-time tracking with accurate ETA to the shipper throughout transit. Unlike ride-sharing (seconds-scale matching), freight operates on minutes-to-hours timescales, but the tracking and ETA requirements are equally real-time.
2. Naive First Cut
flowchart LR
Shipper["Shipper App"]
API["API Server"]
DB["Postgres DB"]
Truck["Truck GPS"]
Shipper --> API
Truck --> API
API --> DB
New components:
- API Server: One process taking the shipper’s booking, receiving every truck’s GPS ping, and answering tracking queries.
- Postgres DB: Trucks, shipments and each truck’s last known position in one database.
- Truck GPS: The device bolted into each truck, reporting where it is every few seconds. It is drawn as a client because it is a traffic source in its own right, and in this design it is by far the heaviest one.
How this breaks:
- Querying nearest available truck in Postgres with lat/lng requires scanning all trucks with distance calculation – O(N) full table scan
💡 O(N) means the work grows in step with the number of trucks, because the only way to find the closest one is to measure the distance to all of them. Doubling the fleet doubles the cost of every booking. - Single API server cannot handle 300K+ GPS pings per second from active fleet
- No way to push live location updates to shippers – polling is wasteful and adds latency
- If two shippers request similar routes simultaneously and the same truck is best for both – double-assignment
- ETA is static – computed once at booking, never updated as truck encounters traffic or delays
- No route-awareness – system might assign a truck 200km away when another truck is on the same highway heading toward the pickup
The rest of the doc evolves this into a production-grade allocation and tracking system.
3. Prior Art We’re Drawing From
- Uber Freight Marketplace – Real-time load matching platform connecting shippers with carriers. Uses scoring algorithms that weight price, carrier reliability, proximity, and route alignment. (Uber Freight Engineering)
- Convoy Dead-Head Optimization – Minimizes empty miles by matching trucks to loads near their current route terminus. Uses graph-based route planning to batch multiple shipments on a single truck. (Convoy Engineering)
💡 Dead-head miles are miles driven with an empty trailer - the truck is burning fuel and the driver is on the clock, and nobody is paying for the load. Cutting them is the main thing a freight marketplace sells to carriers. - Uber H3 Hexagonal Grid – Used for geospatial partitioning of supply and demand. Each hexagon represents a region for allocation scoring and demand prediction. (Uber H3)
💡 H3 tiles the world in fixed hexagons, each with a short id. Because every neighbouring hexagon is the same distance away, “the cells around this one” is a cheap lookup rather than a distance calculation - which is how a two-dimensional question becomes a key lookup. - Google Maps ETA Engine – Real-time traffic-aware routing using live GPS probe data. Historical patterns + live anomalies predict segment-level travel times. Google published this as part of their DeepMind collaboration on traffic prediction.
- Rivigo Relay Model – Indian freight company that uses relay points every 300km so drivers can be swapped. System must track truck AND driver separately, recompute ETA at each relay. Shows the importance of event-driven state machines for shipment lifecycle.
4. Functional Requirements
Core (Top 3)
- Shipper books a truck – specify source, destination, weight, goods type, pickup window. System allocates the best available truck.
- Real-time tracking – shipper sees live truck position on a map throughout transit with updated ETA.
- Smart allocation – system assigns trucks maximizing utilization (minimize deadhead miles) considering proximity, route alignment, capacity, and carrier rating.
Discussion
Newest first