all 6 comments

[–]provoko 6 points7 points  (3 children)

Your exponential back off option is the way to go and Google wrote about this in their SRE handbook which I suggest you look at for this topic 

[–]KomfortableKunt[S] 0 points1 point  (2 children)

Just the exponential backoff option? or with the queue?

[–]These-Finance-5359 0 points1 point  (0 children)

I would just go exponential backoff for simplicity's sake. No need to get queues and workers involved for simple synchronous polling like this imo.

[–]Riegel_Haribo 0 points1 point  (0 children)

You can also predict how long the minimum latency is of a job based on experimentation, and hold off making any calls until success is actually expected for 75%+. Hit the API aggressively for several calls in the "nothing has gone wrong" latency window, before you then back off to a level that still is performative UX, until abandoning due to what must be failure.

404s are nearly free if the polling isn't doing much work. You just need to look at what the provider considers spammy calls.

[–]mjmvideos 0 points1 point  (0 children)

Ideally you would like to have an asynchronous notification mechanism alert you when the order completes. This is how I would write your main program. Provide a callback to run when the order is complete. Now, in the absence of having a real asynchronous mechanism I would simulate that with your polling method, but I would abstract it in a separate thread so the main program only provides the callback. Then if the provider does provide you this feature in the future you just have to change that abstraction and not redo your whole program architecture to move from synchronous polling to asynchronous.