Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High Scale REST API

Tags:

rest

One of our REST APIs will cause a long-running process to execute. Rather than have the client wait for a long time, we would prefer to return an immediate response.

So, let's consider this use case: An applicant submits an application, for which there will be an eventual result. Since this is a very high-scale platform, we cannot persist the application to storage, but must place it onto a queue for processing.

In this situation, is it acceptable practice to return the URI where the application will eventually live, such as http://example.com/application/abc123?

Similarly, would it be acceptable practice to return the URI of the result document, which represents the decision regarding the application, as part of the representation of the application resource? The result document will not be created for some minutes, and an HTTP GET to its URI (or the URI of the application for that matter) will result in a 404 until they are persisted.

What is the best practice in this kind of situation? Is it acceptable to hand out "future" URIs for resources?

like image 505
Pittsburgh DBA Avatar asked Oct 07 '12 18:10

Pittsburgh DBA


People also ask

What is scalable REST API?

Scalability: Development teams can scale the product without much difficulty because there is a separation between the client and the server. Flexibility: REST-style APIs make data migration from one server to another easy. They also help with rolling out changes to a database.

What are the 3 types of APIs?

There are also three common types of API architectures: REST, a collection of guidelines for lightweight, scalable web APIs. SOAP, a stricter protocol for more secure APIs. RPC, a protocol for invoking processes that can be written with XML (XML-RPC) or JSON (JSON-RPC).

What is Level 3 REST API?

Level 3 REST provides clear guidelines on how to make HTTP's specifications work for a state-oriented API. These guidelines take the form of Profiles and Patterns, which are client-oriented expectations of how to interact with the resources in an API.


1 Answers

I don't see anything wrong with such design, but have a closer look at the list of HTTP status codes for better responses. IMHO the first request should return 202 Accepted:

The request has been accepted for processing, but the processing has not been completed.

while requests to the URL where the result will eventually be should in the meantime return 204 No Content (?):

The server successfully processed the request, but is not returning any content

And of course it should eventually return 200 OK when processing finishes.

like image 151
Tomasz Nurkiewicz Avatar answered Sep 28 '22 07:09

Tomasz Nurkiewicz