Short polling and Long polling

Post by Lưu Đại at 10-10-2023
Short polling:
1. Client send request to server.
2. Server handle the request in a background job and send job id back to client.
3. After a short period of time the client call api to check background job status (or call api right after receive the response of previous request).
4. Server send back background job status. It can be done or not done. If it done send back the data too.

Long polling:
1 + 2. The same as short polling
3. Client call api to check background job status
4. Server will not response immediately but it'll hold the connection. While holding the connection server will check background job status frequently. 
In case job is not done and the time server hold connection is about exceeds the limit time connection send the status undone back to the client. 
Incase the job done before the limit time connection send status done and the data to client. 

Short polling will hit the server with multiple requests. It uses a lot of resources. 
Both short polling and long polling use http.