What is Short Polling and what are its drawbacks?
Topic: microservices, Real-Time Communication. Level: Basic.
Answer
Short polling is the client repeatedly sending requests at a fixed interval (e.g. every 3s) asking "any new data?". The server responds immediately with data or an empty result. It's trivial to implement over plain HTTP and needs no special server support. Drawbacks: most requests return nothing (wasted bandwidth/CPU), there's inherent latency up to the polling interval, and it scales poorly (N clients × frequency = constant load even when idle). Use it only for low-frequency, latency-tolerant updates.
```js
// Client asks on a fixed interval regardless of whether data changed
setInterval(async () => {
const res = await fetch('/api/notifications')
const data = await res.json()
if (data.length) render(data) // most polls return [] -> wasted calls
}, 3000) // latency up to 3s, constant load
```