How we cut the apps' route requests per delivery from 151 to 1
Live tracking in Pakka has two parts. The driver's position streams to the customer over Socket.IO, which costs nothing per update. The road line on the map comes from Google's Directions API through our backend, which caches routes in Redis. Every Directions call is billed.
The bug
The route hook in both apps re-ran whenever the driver moved more than 11 metres, throttled to once every 10 seconds. The server's cache key rounded coordinates to about 1.1 metres, so a moving vehicle missed the cache every time: one billable call every ten seconds per open map, or ₹2.58 a minute. The driver's trip screen is the navigation view and stays open for the whole delivery, so a 30-minute trip billed roughly ₹77 on the driver's phone alone, whether or not a customer was watching. Both call sites carried a comment saying "one fetch per leg". It was not true.
The fix
- Driver movement alone never fetches a route while a road line is on the map.
- A route is fetched when the leg changes (pickup to drop) or when the driver is more than 150 m off the drawn line, at most once every 30 seconds so GPS noise at the edge cannot thrash.
- The ETA is recomputed on the phone from the distance left along the line, and the line is trimmed to the road ahead.
Distance to the line is measured to the nearest segment, not the nearest point. Server polylines are sparse: a driver halfway along a straight stretch can be 500 m from both ends while sitting on the road. A nearest-point check would call that a deviation and bring the cost straight back.
One gap remains, found in October 2026 while capturing the apps against a local backend with no Google key: when Google returns no route at all, the map stays empty, so every position update fetches again and the booking preview retries until the rate limiter answers 429. Failed fetches need the same back-off as successful ones.
How we proved it
The decision logic is one pure function shared by both apps, so the test replays a simulated 25-minute drive and counts calls: 151 position updates, one fetch. A second test makes sure a driver who really leaves the route does trigger a refetch, so "fetches once" cannot pass by never fetching again.



































