Skip to main content

Short Polling

What It Is

Short polling is a communication technique where the client repeatedly asks the server for new data after a fixed time interval.

The server responds immediately every time, even if there is no new data available.

Short Polling = Client keeps asking the server again and again for updates

Simple Example

Think of messaging your friend and asking again and again:

Did you reply?
Did you reply now?
What about now?

That is how short polling works.

The server does not automatically send updates.

The client keeps checking repeatedly.


How It Works

Short polling follows a simple repeating cycle.

1. Client sends a request to the server
2. Server sends back current data
3. Client waits for a short time
4. Client sends another request
5. This keeps repeating

Example interval:

Every 2 seconds
Every 5 seconds
Every 10 seconds

The interval depends on how frequently the application needs updated data.


Request Flow

Without any automatic server push, the browser keeps making normal HTTP requests.

Client -> Server
Client -> Server
Client -> Server
Client -> Server

Each request asks the same basic question:

Do you have any new data for me?

If new data exists, the server sends it.

If no new data exists, the server still responds.


Flow Diagram

Client                         Server
| |
| ---- Request: /getData ----> |
| |
| <---- Response: data ------- |
| |
| Wait |
| |
| ---- Request: /getData ----> |
| |
| <---- Response: data ------- |
| |
| Repeat... |

When to Use

Short polling is useful when real-time updates are helpful but not extremely critical.

Common use cases:

  • showing notifications
  • checking order status
  • refreshing dashboard data
  • basic chat updates
  • stock updates at intervals
  • weather updates at intervals
Use short polling when simple periodic refresh is enough.

Advantages

Short polling is popular because it is simple.

AdvantageMeaning
Easy to understandThe client keeps asking for new data
Easy to implementWorks with normal HTTP requests
Works almost everywhereSupported by most browsers and backend systems
Good for small projectsUseful when real-time speed is not very critical

Disadvantages

Short polling can become inefficient when used too frequently or at large scale.

DisadvantageProblem
Wastes requestsClient sends requests even when nothing changed
Increases server loadMany repeated requests put pressure on the server
Not truly real-timeUpdate arrives only on the next polling request
Inefficient for large appsMany users polling frequently can hurt performance
More users + frequent polling = more unnecessary server traffic

Frontend Code

This example calls /getData repeatedly and updates the page with the latest server data.

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>Short Polling Example</title>
</head>

<body>
<h1>Short Polling Example</h1>

<div id="data-container"></div>

<script>
async function getData() {
try {
const response = await fetch("/getData");
const result = await response.json();

document.getElementById("data-container").innerHTML = result.data;
} catch (error) {
console.log(error);
}
}

function shortPolling() {
setInterval(() => {
getData();
}, 500);
}

shortPolling();
</script>
</body>
</html>

Backend Code

This example uses Express.

The /getData route returns the current data.

The /updateData route updates the data for demonstration.

const express = require("express");

const app = express();

let data = "Our initial data here";

app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});

// Get the data from the server
app.get("/getData", (req, res) => {
res.send({
data,
});
});

// We can use PUT / POST to update data.
// This GET route is only for showcasing the idea.
app.get("/updateData", (req, res) => {
data = "Updated data";

res.send({
data,
});
});

app.listen(5000, () => {
console.log("App running on port 5000");
});

What Happens in the Code

The frontend starts polling automatically.

shortPolling();

Then setInterval calls getData() every 500ms.

setInterval(() => {
getData();
}, 500);

Each time getData() runs, it sends a request to the backend.

const response = await fetch("/getData");

The backend returns the latest value of data.

res.send({
data,
});

The frontend updates the UI.

document.getElementById("data-container").innerHTML = result.data;

How to Test

Run the Express server.

node index.js

Open the browser.

http://localhost:5000

Open the Network tab.

You will see repeated requests to:

/getData

Then visit:

/updateData

The server data changes, and the next polling request updates the UI.


Short Polling Table

AreaExplanation
Who starts communication?Client
Connection typeRepeated HTTP requests
Server behaviorResponds immediately
Real-time qualityDelayed until next request
Implementation difficultySimple
EfficiencyLow for frequent polling
Best fitSimple apps and small projects

Basic Checklist

Choose a fixed interval
Call the server repeatedly
Keep the API response small
Avoid very short intervals unless needed
Watch server load in large apps
Use only when true real-time is not critical
Use normal HTTP requests with fetch or axios
Update UI after each response

Interview Style Answer

Short polling is a communication technique where the client repeatedly sends requests to the server at fixed intervals to check whether new data is available. The server responds immediately every time, even if nothing has changed. It is easy to understand and implement because it uses normal HTTP requests with fetch or axios, and it works in most browsers and backend systems. However, it can waste requests, increase server load, and is not truly real-time because updates are received only on the next polling cycle. Short polling is suitable for simple apps like order status checks, basic notifications, dashboard refreshes, and interval-based stock or weather updates where real-time speed is not critical.


One-Line Summary

Short Polling = The client repeatedly asks the server for updates at fixed intervals.

Final Mental Model

Client asks
Server answers
Client waits
Client asks again

Simple, but repeated requests can become expensive.