What is polling?
Polling involves a client repeatedly sending requests to a server at regular to check for new updates or new data.
It operates on the standard HTTP request-response model.
Types of polling?
Short Polling
Long Polling
What is Short Polling?
Short polling: In Short polling it means the client sends request to the server at fixed intervals, regarding whether data has changed.
How Short polling works?
Client send http request
Server immediately responds with current data.
Client waits for a fixewd time (e.g 5 seconds).
Cycle repeat endlessly.
Use Cases of Short Polling?
Simple dashboard.
Periodic status checks.
Low-priority data refresh.
Legacy system.
Backup/fallback mechanism.
Drawbacks of Short Polling
Requests even when nothing changes.
High server and network load and request.
Delayed updates.
Battery drain on mobile.
Poor scalability with many clients.
What is Long Polling?
The server holds the client's request open until new data is available or timeout is reached.
Once data is sent, the connection closes, and the client immediately send a new request.
How Long polling works?
Client sends an HTTP req.
Server does not respond immediately.
Server waits for new data or timeout.
When data changes ---> server reponds.
Then Client send new request.
Use Cases of Long Polling?
Notification systems (older)
Chat apps (older)
Real-time feed(legacy)
Environment where web socket is blocked.
Drawbacks of Long Polling?
Holds server connection open.
More complex server logic.
Still not true real time.
Difficult to scale.
Can overload.