0
0
Node.jsframework~3 mins

Why Long polling as fallback in Node.js? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

Discover how to make your app feel instantly alive without crashing your server!

The Scenario

Imagine building a chat app where the browser asks the server every second if there are new messages by sending repeated requests.

The Problem

This constant asking floods the server with requests, wastes bandwidth, and makes the app slow and unreliable when many users connect.

The Solution

Long polling lets the server hold the request open until new data is ready, so the client gets updates instantly without asking repeatedly.

Before vs After
Before
setInterval(() => fetch('/messages'), 1000);
After
function longPoll() { fetch('/messages').then(() => longPoll()); } longPoll();
What It Enables

This approach enables real-time updates with fewer requests, saving resources and improving user experience.

Real Life Example

In a live sports score app, long polling lets users see score changes immediately without refreshing or spamming the server.

Key Takeaways

Manual repeated requests overload servers and slow apps.

Long polling waits for new data before responding.

It creates efficient, real-time communication as a fallback.