Would it be smarter to split this into 2 separate ...
# ktor
z
Would it be smarter to split this into 2 separate requests? Currently, my client reaches out to my server to verify something and gets an
Accepted/Error
response. If accepted, Id like a sync to happen (all on the server) and for the client to know when the sync has started, and finished. My thinking is that I could solve this by splitting verify and sync into 2 separate requests, once the accepted/ok response arrives, Ill know that the work is finished in both cases. Are there any other, perhaps better ways to approach this or is my thinking correct?
s
Technically you could combine them into a single request, and return a status
100
to indicate that the sync has started, followed by a
200
code when the sync completes. I don’t know how you’d do that in Ktor, though 😄.
A better approach might be to have the verify return a
201 created
response with a URL that the client can use to retrieve the status of the sync
z
Ideally thats what Id like to do: just do everything in one request and responding with different codes - but I also dont know how to do that unless I involve SSE (and things just seem to get far too complicated). I like your idea with an URL included in the response, but isnt that kind of the same thing as having 2 separate requests? I guess the server can start the sync instantaneously after the first request, removing some latency?
s
Yeah, responding with a URL is similar to having two separate requests. The advantage is it lets you make the validate + sync be atomic, in case there are race conditions that could arise.
SSE is a good idea too. It’s actually not too complicated either, I think I have implemented it with Ktor before.
z
Thanks Sam, I think Ill go with the double requests for now (there are no race conditions). Ill keep an eye on latency as well, I think the URL response could help solve that portion if it actually becomes a problem! 😃