Skip to main content

Asynchronous Request Processing Setup Guide

In this article, you will learn how asynchronous API requests work with API hosted and optimized on Resilis technology. If you are looking for an explainer of what Resilis is and does, you should check this intro first. If you want to know how to optimize your API using Resilis, you can check our Postman collection guide or the OpenAPI guide.

This guide will walk you through what the asynchronous request feature does, its implications for your API requests, and how it can help boost your API performance to save cost and reduce latency.

Prerequisites

To follow through with this guide, you will need the following:

  • A Resils account. Sign up here.
  • A basic knowledge of APIs.
  • Already deployed Resilis API. Check the guides above to learn how to deploy one.

Asynchronous Request Processing in REST APIs

In the context of asynchronous request processing in RESTful APIs, when the server receives a complex write request, it immediately returns a 202 Accepted status code to the client. This response indicates that the request has been accepted for processing, but the processing has not yet been completed. By sending a 202 Accepted response, the server effectively allows the client to continue with other tasks without waiting for the final outcome of the requested operation.

Resilis leverages this approach to benefit origin servers, especially in handling complex write requests that are idempotent.

Resilis's asynchronous request processing, equipped with a queuing system and an adaptive forwarding strategy, offers significant advantages to the client's origin server:

  • Resilis queues incoming write requests, such as POST and PUT.
  • Resilis adjusts its request forwarding based on the origin server performance to ensure faster response times and reduced strain during high-demand periods.
  • Resilis's adaptive approach is crucial in peak traffic times for helping the origin server sustain efficient performance and quick responses.

Setting up Asynchronous Request in Resilis

This guide assumes you have imported your API service to the Resilis platform either using the Postman collection or the OpenAPI method.

The first thing to do is to head over to your Endpoints tab from the Dashboard home where the list of all your endpoints is. You will see a trigger for more options per row for each endpoint. On clicking it, you will have the option to optimize your API fully with Resilis

info

When you import an API service to Resilis, by default, it does not have the system-wide optimization activated. Features like asynchronous request, caching, and mutation-based invalidation of cache are not activated on it. This has to be configured on the dashboard. The default settings only capture security, errors, logs, metrics, and edge-distributed services for your API.

For this guide, you will be focusing on the asynchronous request feature. Filter the endpoints by POST HTTP method, toggle them to Resilis Managed and you will get a new status for your endpoint with information on which optimization works on them.

note

Resilis does not only optimize POST endpoints, it works for all HTTP methods. This guide uses the POST endpoints for the performance test we will be showing later in the guide where we simulate multiple POST requests by multiple users to show how asynchronous request works.

To set asynchronous requests on any endpoint, click the more icon at the end of the row, click Edit, and toggle Asynchronous Request on. It is that easy, simple, and concise. Now any request coming to this endpoint will be handled asynchronously with respect to the API server.

warning

Asynchronous requests are ideal for queueing and request retries, but avoid non-idempotent operations, or where transactions aren't utilized. In designing your API, ensure that operations, especially POST, PUT, and DELETE, are idempotent. This will help maintain the integrity and consistency of your system's state, providing a more reliable and robust service for your users. Remember, idempotency is not just a best practice but a cornerstone of effective API design in asynchronous and high-traffic environments.

The status of the endpoint changes when you toggle the asynchronous request on and it should look like this:

To gain more insight into what the Asynchronous request feature on Resilis does, kindly check the well-detailed explanatory content in our documentation here.