Short Polling and Long Polling
Short Polling
Short polling is a technique where the client repeatedly sends HTTP requests at fixed intervals, and the server responds immediately whether or not new data is available. It doesn't wait for the results, and the result can be generated between any iteration of request response. The waiting time of request and response were assigned by the client or server.
Request data:
Client--------->Server
Client<---------Server (No Data)
Client--------->Server
Client<---------Server (No Data)
Iteration continuous until data is available
Client--------->Server
Client<---------Server (Sent Data)
Long Polling
Long polling is a type of HTTP request where the request is sent by the client to the server, and the connection is open until the result is generated. Only when the proper result generates, the server sent the response to client.
Request data:
Client---------->Server
Wait until data is available....
Client<----------Server (Sent data)
Event Stream
Event Stream
Also known as Server-Sent Events (SSE). Example of Event Stream is "ChatGPT". The server sent the response to the client continuously as the result generation is in progress and during that the time the connection between client and server is active. This prevents the client to wait for a huge amount of time until it completes a large process and sent the result. A limitation of Event Stream is that browsers may restrict the number of simultaneous connections per domain.
Example: Opening many ChatGPT tabs may slow your browser or consume more network resources, but this is not a limitation of Event Streams themselves.
Request data:
Client---------->Server
Client<--------Server (Data until completed-Ex:10% completed data)
Client<--------Server (Data until completed-30%)
Client<--------Server (Data until completed-80%)
Client<--------Server (Data until completed-100%)
Connection closes
Top comments (0)