DEV Community

Discussion on: How to handle API downtime with 2 lines of code

Collapse
 
okbrown profile image
Orlando Brown

Is that really a monitoring problem?

Sounds like a infrastructure problem, which can be solved assisted by monitoring to give appropriate alerts to trigger adding more resources to help with peak loads.

Collapse
 
tonymet profile image
Tony Metzidis

It's more of a supply/demand problem, and when there's an issue on the supply side (target server), the demand will go up 3x.

A better solution is to cache the call to the target, and revalidate it in a separate thread.

One easy way to do this is to use a reverse proxy with stale-while-revalidate

Thread Thread
 
frenchcooc profile image
Corentin

Retry is one simple feature to handle an API downtime, but it's surely not the only thing that will help your app to stay up.

  • Caching is a very good solution as well, while you might need some data validation at some point.
  • Using a circuit breaker is also great. It adds some more logic to a retry-mechanism and avoids tripling the bandwidth as you mentioned.

There's a great article on Dev.to on the main mechanisms to improve reslience on your app. At Bearer, we're starting with retry, but we are planning to add them all to our Agent.