API Implementations – Handling Slow External APIs in Web Applications

apiimplementations

So I have got an application that during various steps during a user's process will transmit and receive data from external API's.

Currently the way this is handled is fairly rudimentary. There will be a POST, DELETE, or PUT to the app. The application will then make the necessary updates in the DB and submit any information to the API's we are using. After we get responses from the DB and API we respond to the user's request.

When I started with the application the external services we were using were small, however after working on it for a few years, the number has been growing. After working with a particularly painful API that has slow response times, I'm finding that this response to the user's request is starting to feel slow and painful.

How does one handle interacting with slow external services?

Now on a higher level, I know that one solution would be to implement a queue-like system for these API's where the calls are pushed into a queue and a separate process / service processes them. Update the DB, fire off the API updates to the micro-service and call it a day. Are there any other approaches for handling this sort of situation?

Best Answer

Calling the external API asynchronously is the best bet.

When it is part of a user's process, it is best to show feedback that the call is underway and some indication whether the call finished and succeeded or failed once you get response. If possible, let the user give other input while waiting for feedback on the external API, this negates the "slow and painful" feeling.

Related Topic