AngoraTek FR
← Back to Blog
Field Notes 6 min read

The Map Is the Easy Part of Fleet Tracking

Ten thousand vehicles reporting their position every five seconds produce 2,000 position updates per second. During shift changes, when every driver's device checks back in at once, we plan on three to five times that rate for the first minutes of the morning. Every one of those reports has to be validated, persisted, and on a screen before a dispatcher calls a driver.

The map is the easy part. Any vendor can draw a moving truck on a tile. What makes fleet tracking hard, and what decides whether dispatchers trust it, is the pipeline underneath. Millions of position updates an hour flow through it, each one validated, persisted, and served fast enough that the screen never disagrees with reality. Dispatchers catch a lying map exactly once. After that they call drivers directly, and the tracker becomes a very expensive dashboard nobody opens.

The failure you are designing against

Here is what goes wrong when the pipeline is half-built. A vehicle's report arrives ten seconds late, sits in a queue, then gets written against a connection pool that is already saturated. On screen the truck is 300 meters behind where it really is, so the dispatcher sends a driver to an address that truck cleared ten minutes ago. Nothing has crashed. The system is just consistently late, which is worse, because late looks like truth.

Two stores and a tile server

The architecture for this problem is boring, and the boring is the point. Vehicles publish positions over MQTT into an ingestion service. The service writes current positions to Redis and persists every position to PostgreSQL. A tile server reads from Redis and feeds the frontend.

Redis holds the last known position for every vehicle with a 5 minute TTL, so the live view never touches a database. PostgreSQL keeps the complete trip history, which is how you answer questions about last Tuesday instead of only questions about right now.

Four decisions worth arguing about

Everything else in this stack is pluggable. These four decisions are not.

The first is MQTT rather than HTTP. Persistent connections, tiny per-message overhead, and delivery guarantees matter once 10,000 devices share one service. Many fleet telematics devices speak MQTT natively. Raw UDP is faster on paper, but you give up those guarantees, and a map with unexplained holes is harder to debug than a map with slightly higher latency.

The second is batching Redis writes. Accumulate 50 to 100 positions and write them in one round trip. One write per position saturates the connection pool under load, and it does it during morning rush, the worst possible moment. Make this mistake once in a test environment so you recognize the smell at 7:02 a.m.

The third is backpressure from day one. When Redis throughput falls behind the ingestion rate, drop stale positions rather than letting the lag grow without bound. A position from 90 seconds ago is worse than no position at all, because somebody might steer by it.

The fourth is UTC everywhere. A vehicle crossing from CET into EET reports time differently on each side of the border. UTC removes the ambiguity before it turns into a 2 a.m. incident.

// Batch ingestion in Rust
async fn ingest_positions(batch: Vec<PositionReport>, redis: &RedisClient) {
    let mut pipe = redis.pipeline();

    for report in batch {
        let key = format!("vehicle:{}", report.vehicle_id);
        pipe.set_ex(key, serialize(&report), 300); // 5 min TTL
    }

    pipe.exec_async().await?;
}

Let HERE do its actual job

HERE's routing, traffic, and geocoding services are genuinely good at what they do. They are not built for high-frequency position updates. Bending them that way fails the same expensive way every time: the routing endpoints are built for a handful of queries a second, not thousands of writes.

Use it for what it does well. Route calculation gets optimal paths from origin to destination with live traffic. Geocoding turns "the depot on 4th Street" into a coordinate. Reverse geocoding turns the coordinate back into an address for delivery confirmation. For position ingestion and state management, your own Redis and PostgreSQL layers carry it. Every tool works better when it does its actual job. The boundary between a vendor call and your own state is the one drawn in [the one-line map switch is the easy half](/blog/the-swappable-map-provider/).

Draw at eye speed, not at update speed

The frontend has one job: never let 2,000 updates a second reach the render loop. Debounce position updates and render at 60 frames per second at most. Never re-render on every WebSocket message, no matter how tempting it is.

Between two real fixes, linear interpolation makes vehicles glide instead of stutter. Dispatchers read that smoothness as data quality, and in a way it is. The exception is a truck that has stopped moving, and it is covered below.

Then cull outside the viewport. Only draw vehicles inside the current map bounds. Nobody can make sense of 10,000 vehicles at once, and neither can the GPU.

function interpolatePosition(
  prev: Position,
  next: Position,
  progress: number
): Position {
  return {
    lat: prev.lat + (next.lat - prev.lat) * progress,
    lng: prev.lng + (next.lng - prev.lng) * progress,
    heading: prev.heading + (next.heading - prev.heading) * progress,
  };
}

What this design still cannot do

A vehicle in a tunnel, a parking garage, or a mountain valley reports nothing for minutes. Then the 5 minute TTL expires, the marker vanishes from the map, and the dispatcher cannot tell a tunnel from a breakdown. The fix is two-sided. Buffer positions on the device and replay them on reconnect, or trips quietly lose their middle. On the frontend, show "last seen 42s ago" as its own state so age is visible instead of implied.

Interpolation lies in exactly one direction: a stopped truck. If the next fix never arrives, the marker keeps gliding away from the truth. Cut the interpolation when position age passes one reporting interval, or when the last reported speed drops under walking pace.

The smallest limit is GPS drift. A "move" within 5 meters of the last known position is usually noise, not a truck that teleported. Snap-to-road algorithms or a minimum movement threshold solve it with one setting.

Where each component belongs

LayerUseAvoid
HERE APIsRouting, traffic, geocodingReal-time position ingestion
RedisLast-known positions, hot stateLong-term storage, analytics
PostgreSQLTrip history, persistent storageReal-time query serving
Mapbox GL JSInteractive maps, custom stylingServer-side data processing
If your dispatchers call drivers to double-check the map, you are paying for a second map that already exists. Fix the ingestion pipeline first.

Get the pipeline right and the map takes care of itself.

AngoraTek builds fleet tracking systems. If you're scaling location-aware operations, we'd genuinely like to hear what you're working on.

Thanks for reading this far. If this sounds like the problem you're wrestling with, tell us about it. The team reads every message.

Start a conversation