I’m a frontend developer (iOS), been using an (external) API (that uses apigee) for about a year. Today, we received a warning from the owners that we need to stop cancelling our requests.
The query in question is a text search, where we (on frontend) use a debouncer to throttle our queries to prevent performing a query for each character written. The timer is set to 0.2 seconds.
Let’s say the user writes “Washingto”, and then uses 0.250 seconds to type the last “n”. In this case we perform the search for “Washingto” after 0.200 seconds, and then when they 0.050 seconds later type the letter “n”, then we immediately cancel the first outgoing query, and wait another 0.200 seconds to perform the query for “Washington” (unless they write more). etc.
And we cancel by using standard local api’s, like iOS URLSessionTask.cancel.
We cancel because the respons for “Washingto” is utterly useless for us, as we already know that the user actually want to search for “Washington”. By cancelling, we don’t have to wait for a response, saving us both data usage(mobile), processor(parsing data), and thus battery usage.
The external api-team gets thousands of status code 499 in their logs every hour because of this, and they say that “apigee claims that it’s bad practice for clients to cancel connections. That may be discussed, and we see your reasoning for doing so, but apigee are leading on the subject, so this shouldn’t be ‘standard practice’”.
They want us to stop cancelling the requests, and just receive the response.
My gut (and my research) tells me we have used the best practice by cancelling our useless outgoing requests. Is it really discouraged to cancel requests from clients when using apigee?