Skip to main content
Back to Blog
Development

Real-Time Delivery Tracking with NestJS, Socket.IO, and PostGIS

NT

NeoCodeHub Team

February 15, 2026

Errandoo is a hyperlocal delivery platform where customers need to see their rider's live location. This requires a real-time architecture that handles thousands of concurrent connections reliably.

Why WebSockets Over SSE

Server-Sent Events are simpler but uni-directional. Our use case requires bi-directional communication — riders send location updates, customers receive them, and both exchange chat messages and status updates within the same connection.

Room-Based Architecture

Each active task gets its own Socket.IO room. When a rider accepts a task, both rider and customer join the same room. Location updates, chat messages, and status changes broadcast only to participants of that task — not to everyone.

PostGIS for Spatial Queries

Finding the nearest available rider uses PostgreSQL with the PostGIS extension. The ST_DWithin function with geography casting calculates accurate earth-surface distances. Combined with a GIST index on the location column, nearest-rider queries complete in under 5ms even with thousands of riders.

Background Job Processing

Async operations like OTP delivery via Fast2SMS, push notifications via Firebase Cloud Messaging, and payment verification via Cashfree are processed through BullMQ backed by Valkey (Redis-compatible). This keeps API response times consistently under 200ms.

Production Monitoring

The production stack includes Grafana dashboards for real-time metrics, Loki for log aggregation, Sentry for error tracking, and Uptime Kuma for health checks. A Telegram bot sends critical alerts when services degrade.

Related Posts