Delivery Tracker
Lead Developer
A real-time delivery-dispatch system that assigns orders to drivers based on distance, current load, and historical performance. PostGIS spatial queries, Socket.IO driver tracking, scoring-based assignment iterated with the dispatch team.
The system
Delivery Tracker is a real-time delivery-dispatch system that assigns incoming orders to drivers based on distance, current load, and historical performance. Each driver runs a mobile client that streams GPS position over Socket.IO. The dispatcher sees a live map. When a new order comes in, a scoring algorithm picks the best driver (closest, currently empty, well-rated) and the order is offered to them. PostGIS handles the spatial queries (within-radius, route distance approximations). Single-tenant, internal-only — built for a dispatch team to coordinate drivers across a city.
Architecture
- API: Fastify (Node 22) + PostgreSQL + PostGIS extension + Drizzle ORM
- Realtime: Socket.IO with separate channels for drivers (position uplink) and dispatchers (live map)
- Spatial layer: PostGIS for within-radius queries and route-distance approximations, indexed for sub-100ms response
- Driver scoring: weighted formula combining straight-line distance, current active load, recent rating, and acceptance rate
- Dispatcher frontend: React 19 + TanStack Query, live map rendered with Mapbox GL
My contribution
I built the system as the sole developer. The architectural decision that mattered most was using PostGIS for spatial queries instead of computing distances in application code. At scale, running haversine math in Node for every driver on every order intake would tank the request path. PostGIS handles within-radius queries at indexed-database speed, sub-100ms even with hundreds of drivers online. The driver scoring formula was iterated with the dispatch team’s actual feedback: the first version weighted distance heavily, but real-world testing showed current load mattered more (a driver one block away with three active orders is worse than one a kilometer away with zero). Iterated to a weighted blend that the dispatch team validated against past runs before going live.
Outcomes
- Live map of all active drivers, position-streamed via Socket.IO
- Sub-100ms assignment decisions on order intake, even with hundreds of drivers online
- PostGIS-backed spatial queries that scale with city size
- Scoring formula iterated with the dispatch team’s actual production feedback
Links
- Internal-only deployment, no public URL.
Related work
- TaskFlow: another realtime multi-tenant system, but task dispatch instead of delivery dispatch
- Multi-tenant Calendar SaaS: another Fastify + Drizzle + Socket.IO stack, but appointment booking instead of GIS-based dispatch