Engineering · FleetOS
How We Built a Real-Time Fleet Tracking System for 2,000 Vehicles
Sub-second tracking across India, without over-spending on infrastructure.
When we started work on FleetOS, the requirement sounded simple: “We'd like to see all our trucks on a map, in real time.” In practice, that meant ingesting position updates from more than 2,000 GPS devices across patchy cellular networks, and making sure dispatchers could trust what they saw.
Why WebSockets (and Not Just Polling)
Our first prototype used a straightforward polling model: each browser tab hit an API every 5–10 seconds to fetch the latest locations. It worked for a dozen vehicles, but quickly fell apart as we scaled:
- Network usage grew linearly with the number of tabs open.
- Vehicles that hadn't moved still generated the same amount of traffic.
- Dispatchers complained about the lag — 10 seconds is long when a truck is about to miss an unloading window.
We switched to a WebSocket-based fan-out model. The backend maintains a single connection per browser tab; as fresh GPS data arrives, we push only the changed vehicles down to connected clients. That let us keep perceived latency well under a second for most users.
Geospatial Indexing That Stays Fast
Storing positions as plain latitude/longitude pairs works until you want fast queries like “all vehicles within 5km of this warehouse” or “everything along this corridor.” For FleetOS we leaned on PostGIS with a few simple rules:
- Every position update is stored as a geometry with a spatial index, letting us answer proximity queries in milliseconds.
- We keep a compact “current state” table per vehicle and a historical table partitioned by month, so dashboards stay fast while history is still accessible.
Making Tradeoffs Explicit
We intentionally traded a tiny amount of precision for lower cost and simpler operations. For example:
- We down-sample updates from vehicles that are stationary at a warehouse to once every few minutes.
- We snap points to a road network when rendering the map, which hides GPS jitter without changing the underlying raw data.
The result is a system that feels immediate to dispatchers and scales to thousands of vehicles without an exotic infrastructure bill.