Search code examples
spring-cloudribbonnetflix-eurekaspring-cloud-feignfeign

Manage Fault Tolerance with Feign, Ribbon and Eureka


I want to implement a resilient microservices architecture using Feign Client,Ribbon and Eureka so I encountered an issue. When a microservices target is down I want to redirect to another instance of microservices without the user seeing it. For example, I have 4 instances of microservices B and one instance A :

The Browser client call A then A call B1 but B1 is down => A redirect automatically to B2, B2 is KO then A call B3 and B3 is up then it returns a response to A. A returns response to the browser client.

How I could implement it, please. Thanks in advance.


Solution

  • Basically, Ribbon should already find instances that are alive for you - firstly, Eureka stores and updates information on which instances are alive and, secondly, Ribbon runs health-check requests to the instances. If that is not working correctly for you, you can try customising the polling intervals for Ribbon. If you want a failed request to be repeated against a different instance, you can use Spring Cloud Netflix Ribbon with Spring Retry (see documentation).

    Having said that, since Spring Cloud Ribbon is now in maintenance mode and will not be making it into the 2020.0.0 release train, I would definitely not encourage adding it at this point. The available alternative is Spring Cloud LoadBalancer. It supports retrieving the instances that are alive from Service Discovery (either with or without caching and health-checks. It does not support retries at this point, but there's an issue for it in the project backlog.