Long-lived RESTful interactions

We are currently discussing my team and I will be interested in other views. Suppose we have a RESTful web service, the role of which is to annotate documents using various algorithms and analysis services. The main interaction is clear: we have a resource, which is a collection of documents; the client sends a new document to the collection, returns the URI of the new document, then can GET to docURIreturn the document or GET {docURI}/metadatato see the general metadata,{docURI}/nefor named objects, etc. The problem is that some analyzes can take a lot of time. Suppose the client GETS the metadata URI before the analysis is completed, as he wants to show partial or additional results in the user interface. Repeating the GET in the future may give more results.

The solutions we discussed include:

  • maintaining an HTTP connection until all analyzes are done (which does not seem scalable)
  • using content-lengthand accept-range headers to get incremental content (but we donโ€™t know in advance how long the final content will be)
  • providing Atom for each resource, so the client subscribes to update events, and not just a getting resource (it seems too complicated and, possibly, resource hunger if there are many active documents)
  • only returning GET is all that is available at that time (but it still leaves the client problem knowing when we will finally finish) [edited to remove the link to idempotency after comments].

Any opinions or suggestions on alternative ways to handle long-lived or asynchronous interactions in a RESTful architecture?

Jan

+3
source share
7 answers

I would execute it as follows:

1)
2) ( ), NotReady
3) , ( )
4) ( ..)
5) 1

. , , 4)

+3

Atom , , ( , , , )

SUP?

, ? ?

, ?

+3
  • idempotency GET , ( , ).

GET, , , ? :

"idempotence" , ( ) N > 0 ,

, GET , .

, , REST GET , , :

  • , GET {docURI}/metadata :
    • Expires, .
    • no ETag.
  • , :
    • no Expires.
    • a ETag. ETag 304 Not Modified.

NB , , Expires.

"" RESTful - , - , .

+2

", GET , " . , , , . .

, ", " GET. . 1, . 1, 2.

. . " " GET . " " .

, , TCP/IP. , . , 200- .

" , ", . , , .

, "" - , , - . . . " x ", x .

Unix, , , X .

- , . , URI, POST , .

Atom . Atom - - - Atom ( " " ) , , ( " " ), . , .

" " GET .

+1

, , , "AnnotationRequests". ( ) AnnotationRequests (, http://example.org/AnnotationRequest/2042), . , "AnnotationRequest" .

You can make GET in AnnotationRequests a good side effect of this, so check out the documents that are currently being processed. It's up to you how long you want to keep AnnotationRequests. It might be useful to keep a complete history of when they were asked who they were doing and for how long, or they could periodically drop them.

+1
source

You can check out the Udi Dahan nServiceBus .

+1
source

Source: https://habr.com/ru/post/1697372/


All Articles