Why live order tracking runs on WebSockets
Engineering · 3 min read
A customer who has just paid wants one thing: to know where the order is. On ClickToFood that status travels over WebSockets rather than repeated requests. Here is the reasoning.
Polling asks, a socket tells
With polling, every open app asks the server “anything new?” every few seconds. Most answers are “no”, and the real update can still arrive a full interval late. A WebSocket keeps one connection open, so the server sends the change the moment it happens.
What to plan for
- Connections drop. Phones switch networks all the time. On reconnect, the app asks for the current state instead of trusting what it last saw.
- The database stays the source of truth. The socket delivers updates. It does not store them.
- Send small events. “Status changed” or “rider moved” is enough. Sending the whole order every time wastes data on mobile.
When polling is still fine
If a screen changes a few times a day, like a sales report, a simple refresh is cheaper to build and run. Use sockets where waiting is noticeable.