you make a poll request, but the server doesn’t respond. client asynchronously does its own thing. server only responds when it’s ready
kafka
kafka only responds when there is an entry (message) in the topic
if there is no msg in the topic, kafka blocks (never replies)
Push model did not work well with kafka. If u have a consumer connected to a topic, every time the topic has data it pushes the data to clients. The consumer sometimes cannot handle the volume of messages.
Long polling
Steps
Client sends a request (e.g., /poll-messages) asynchronously, and server responds immediately with a handle.
Client uses that handle to check for status.
Server holds the connection open (does not respond), and it waits until data is ready (or a timeout occurs, as u can’t poll forever - client/server timeout).
Server sends the response.
Client receives data and immediately sends a new request.
We can disconnect and we are less chatty
Why “long”?
It’s called “Long” because the HTTP request takes a long time to complete
pros
less chatty and backend friendly
client can still disconnect
cons
not real time → client has to make a new poll, the message might be not precisely real time