Improving Performance with OData V4 Asynch Request

When working with APIs that handle complex or time-consuming operations, waiting for the full response can cause delays or even timeouts.

To make these interactions more efficient, OData V4 introduces a handy header option:

Prefer: respond-async, wait=10

This header tells the OData service that the client is willing to receive an asynchronous response if the operation takes longer than a specified number of seconds (in this case, 10 seconds).

Here’s how it works:

1 . The client sends a request with the header
Prefer: respond-async, wait=10
2. If the server completes the operation within 10 seconds, it returns a normal synchronous response (e.g., 200 OK).

3. If it takes longer than 10 seconds, the server responds immediately with a 202 Accepted status and a Location header pointing to a URL where the client can check the operation’s status or result later.
HTTP/1.1 202 Accepted
Location: /odata/Operations/12345

The client can later call /odata/Operations/12345 to retrieve the final result once processing is complete.

Why This Helps

The Prefer: respond-async option helps:

  • Prevent client timeouts for long-running operations (like report generation, data analysis, or bulk updates).
  • Improve user experience by letting clients continue other work instead of waiting.
  • Balance server load by handling requests asynchronously.

The optional wait=10 parameter gives the server a short grace period to complete the operation synchronously if it’s quick enough — a smart hybrid approach between performance and responsiveness.

Leave a Reply