Asynchronous HTTP API
Explore how to build asynchronous HTTP APIs that improve scalability and responsiveness by offloading lengthy operations to background processes. Learn to use HTTP status codes, thread-safe queues, and polling mechanisms to manage and retrieve results without blocking clients.
We'll cover the following...
It is pretty common when writing HTTP API to return a 200 OK status code to the caller to indicate that the request succeeded. While easy and convenient, it is possible that the action triggered by the caller takes a lot of time. If the call requires a long delay to be executed, it blocks the caller as it has to wait for the reply, and this increases the risk of failure.
Indeed, if the connection lasts for too long (let’s say, a few seconds) and the network is having issues, the connection can be interrupted. In such a case, the caller has to retry the request. If that problem happens thousands of times with flaky clients, it means that tons of CPU time and network bandwidth are spent for nothing.
An obvious way to avoid those problems is to make lengthy operations asynchronous. This can be done easily by ...