I need to consume an external API to update or create data, I need to handle service down cases and don't lose the data if the service went down for more than expected, what is the best approach to do this... thanks in advance.
CodePudding user response:
I think you can have some kind of internal database, maybe NoSQL
database that stores all of the failed requests you tried to send.
So when you send a request and it fails for any reason, then you will insert the failed request to that database.
And you will make a recurring task that pulls all the data from that internal db, and retries to send the requests again. If the request is succeeded, then remove it from the internal db.
CodePudding user response:
If downtimes are happening a lot and you have also high traffic taking an asynchronous microservice approach could be best.
Using a message queuing system like RabbitMQ you can store all requests with their data as a message on a Queue.
Then another microservice which consumes those messages from the Queue can reach the external service and do the operation. If the external service is up, the operation is completed and the messages is removed from the Queue. If not RabbitMQ has dozens of configs for Retrying (reque after x secs etc)