Member-only story
Exploring Short Polling, Long Polling, Server-Sent Events, and WebSockets
In this article, we will try to summarize the real-time communication techniques between clients and servers.
What is Short Polling?

Short polling is a technique where the client sends requests to the server for updates at regular, short intervals, such as every few seconds.
const endpointUrl = 'https://example.com/api/updates';
const pollingInterval = 5000; // 5 secs
async function pollServer() {
try {
const response = await fetch(endpointUrl);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log('Update received:', data);
} catch (error) {
console.error('Error fetching updates:', error);
}
}
// Set up the interval to poll the server
setInterval(pollServer, pollingInterval);
pollServer();
In this short polling example, HTTP requests are sent every 5 seconds to the specified endpoint.
Useful for periodic data updates, system health checks, or feed systems.