How One Developer Hardened His App Against API Failures

APIs are often prone to failure. That’s no surprise. But if your app is dependent on an API that goes down like there’s no tomorrow, what do you do? Thomas Roca, a stats researcher at the French Development Agency explains how he overcame the API developer’s dilemma.

As part of his work, Thomas uses the World Bank API on a regular basis. He feeds this data into charts that are presented on the Agency’s website. Whenever there’s an update to the API, he either has to constantly check the API to make sure it’s still working or he has to automate everything, which is prone to failure. As a result, Thomas can never enjoy his holidays because he’s always worrying that the API went down.

The question for him was: how you can automate the handling of API updates so you can provide a continuous service even when you’re on vacation? The answer: have a local backup data source. Just like a hospital has a local generator in case of a blackout, Thomas suggests downloading periodically JSON data from the API, which can be accessed via a local url. Create a switching mechanism where the API call fails so that the app will try the local url in case of API failure. 

Thomas did this so that his charts will always present data even when the WorldBank API is not available. To keep users aware of what’s happening, he added a font awesome icon in the form of a plug that will turn red in cases where the data is fetched locally. 

In this way, you can ensure a continuous service for your users and resolve the API problem manually when you can. Now Thomas can enjoy his holiday without worrying about his charts failing to present data. 

Be sure to read the next API Design article: How APIs Helped TomTom Grow its Webfleet Platform to 45,000 Users

Original Article

Way to react to API failure