Long Polling Beats WebSockets: A Practical Guide to Scalable Real-time Systems
Inferable's team chose HTTP long polling over WebSockets when building a scalable real-time system using Node.js and TypeScript. Facing challenges of hundreds of worker nodes needing real-time job updates and agents requiring real-time state synchronization, they found long polling surprisingly effective. By keeping HTTP connections open until new data arrives or a timeout is reached, they avoided the complexities of WebSockets, such as authentication, observability, and infrastructure compatibility. The article details their implementation, including database optimization, error handling, and best practices like mandatory TTL, client-configurable TTL, and sensible database polling intervals. The choice stemmed from needing core product control over message delivery, zero external dependencies, and ease of understanding and modification. Alternatives like ElectricSQL are briefly discussed, highlighting scenarios where WebSockets might be preferable.
Read more