← All workCase Study

Live Vehicle Tracking System

A set of Go microservices that turn driver GPS updates into a live map, a road-following ETA and automatic reroutes for customers.

RoleSenior Backend Engineer & Tech Lead
CompanyDrivado
StackGo, Kafka, Redis, WebSocket, SSE, Kubernetes
Architecture overview of the live vehicle tracking system: small services connected by an event stream.

The problem

Customers waiting for a chauffeur had no live view of the car. They needed to watch it move, see an ETA they could trust and see the route redrawn when the driver took a different road. All of this had to keep up with many trips at once without asking a maps API for a new route on every GPS update, which would be too slow and too expensive. The ETA was also hard to get right. Straight-line distance made it jump whenever the car turned a corner. Matching the car to the nearest piece of road made it jump when the route passed close to itself, at U-turns, flyovers and parallel roads.

The approach

The system is split into a few small Go services that talk to each other through Kafka. One receives location updates from the driver app, one works out the ETA and route, one streams live updates to customers, and one sends trip notifications. Updates for the same trip are always handled in order. My focus was the ETA and routing logic. Asking the maps provider for a fresh route on every location update would be slow and expensive, so the service asks only at key moments and estimates in between by measuring how much of the planned road is left. It follows the car forward along the route, so roads that loop back near themselves don't confuse it. When a driver really leaves the route, it fetches a new one, but only after a consistent signal, so a single bad GPS reading doesn't cause a reroute. To keep up as the number of live trips grew, I made event processing run in parallel while keeping each trip's updates in order, and made sure a restart never loses an update. I also built a simulator that drives many virtual cars at once with realistic GPS noise and detours, so changes could be tested before they reached real drivers.

The result

Customers now watch the car move, the ETA count down and the route update live. The ETA follows the real road instead of jumping at corners and loops. Processing used to fall behind as more trips ran at once. With parallel processing it keeps up, never skips an update and keeps each trip's updates in order.

Live
Car position, ETA and route
0
Updates skipped on restart
Dozens
Virtual drivers in testing

Deep dive

How a trip flows through the system

The system is a handful of small Go services connected by an event stream. Each one has a single job, and every event carries the trip it belongs to, so updates for one trip are always handled in order.

Architecture overview: the driver app sends location updates to a location service and status changes to a realtime service. Both publish to a shared event stream. An ETA and routing service reads location and status, talks to a maps API and a cache, and publishes ETA and route updates. The realtime service streams them to the customer app, and a notification service sends messages on trip changes.
The services and how events move between them.
  1. The driver starts the trip, and the app reports the status change.
  2. The routing service fetches a route from the driver to the pickup and publishes it. The customer gets a "driver is on the way" message.
  3. While driving, the app sends its location every few seconds over a live connection.
  4. Each location update becomes a new ETA and distance, plus a check on whether the driver is still on the route.
  5. The customer's screen receives every update live: the car moves, the ETA counts down and the route line changes when needed.
  6. After pickup, the same flow repeats for the second part of the trip, to the drop-off.

Keeping several services in agreement

When several services pass the same data around, most bugs come from two sides disagreeing about what a message means. A few shared rules prevented that:

  • Ordered per trip: events are grouped by trip, so they never arrive out of order.
  • One unit everywhere: time and distance use the same units in every service.
  • Separate legs: driver to pickup and pickup to drop-off are tracked separately, each with its own route.
  • Atomic status changes: checking the current status and writing the new one happen in one step, so two requests can't race.

ETA without a map lookup on every update

Asking a maps API for a fresh route every few seconds for every car would be slow and expensive. Instead, the service asks only at key moments, such as the start of a trip, after a reroute and close to the destination, and estimates in between.

The estimate measures how much of the planned road is left and scales the last answer by that share. If 40% of the road is left, the ETA is about 40% of the last estimate. Because it follows the road and not a straight line, the ETA no longer jumps when the car turns a corner.

Diagram of a route that runs out, makes a U-turn and comes back on a parallel road. A GPS reading between the two roads is matched forward onto the road the car is on, not onto the nearer return road.
Searching ahead of the last known position keeps the car on the right road where a route passes close to itself.

The tricky case is a route that passes close to itself, such as U-turns, flyovers and parallel roads. Matching the car to the nearest piece of road anywhere can put it on a later part of the route, and the ETA suddenly drops. Remembering where the car was and only searching ahead of that point fixes it.

Rerouting without reacting to GPS noise

Phone GPS is noisy. One bad reading can place the car well off the road. Rerouting on every off-route reading would waste map lookups and make the route line flicker on the customer's screen.

Timeline of GPS readings. A single off-route reading is ignored. Several off-route readings in a row trigger a reroute, followed by a cooldown in which off-route readings do not trigger another one.
A single bad reading is ignored. Only a confirmed detour triggers a reroute, followed by a cooldown.
  • Confirm first: reroute only after several off-route readings in a row.
  • Cool down: after a reroute, wait a short while before allowing another.
  • Use it straight away: the new route is used immediately, and the customer's map redraws it.
  • Ignore jitter: very small movements are dropped before any of this runs.

Keeping up as trips grow

Processing updates one at a time worked for a few trips, but as more trips ran at once the backlog grew and the ETA started lagging behind the car.

Diagram of incoming events from three trips being sent to three different workers by trip, each processing its own trip's events in order. Below, progress is saved only up to the last point where every earlier event is done.
Different trips run in parallel, and each trip stays in order. Progress is saved only when nothing earlier is unfinished.

The fix was to process different trips in parallel while keeping each trip's updates in order: every trip always goes to the same worker. Progress is saved only when every earlier update has been handled, so a restart picks up where it left off and never skips an update.

Testing with simulated drivers

Real drives are slow to test with, and real phones rarely misbehave on cue. A simulator drives virtual cars along real routes and sends updates the way the driver app does, adding GPS noise, sudden jumps, dropped updates and detours. Running dozens of virtual drivers at once made it easy to test both accuracy and load before changes reached real drivers.

Lessons

  • Fail loudly. A service that is running but quietly not working is worse than one that crashes, because nothing alerts you.
  • Keep environments apart. Two copies of a service writing the same data produce confusing bugs that look like logic errors.
  • Refresh estimates near the end. Small errors in an old estimate matter most in the last few minutes, when customers watch the ETA most closely.