how to use circuit breaker and caching in microservice - spring

I'm working on a micro service where I have to aggregate data from multiple apis and expose them as a single api output.I'm using spring boot and I want to use circuit breaker like Resilience4j and Redis caching. is it possible to use them together ? if yes then what should be the approach ? an example would be great.

Related

Rate limit web client

I am building a microservice using spring webflux and netty. Internally I use web client to make rest api calls. How can I control rate at which I can call rest api via webclient? I guess backnpressure is only for a single request/reply and does not work across multiple request to my microservice. Amy pointers will be appreciated.Thanks.
Resilience4j has support for non-blocking rate limiting with Reactor.
See: https://resilience4j.readme.io/docs/examples-1#decorate-mono-or-flux-with-a-ratelimiter

load balancer and Circuit Breaker

I search to use spring boot, spring-cloud-gateway, netflix eureka.
Is there anything to do to have a load balancer and circuit breaker for micro-service instance?
I found few information ex ribbon when spring gateway is used instead of zuul.
Actually I have an application for the gateway, another for eureka, another for thymeleaf client
security is not yet choose, probabley jwt
With Spring Cloud Gateway, you can currently use the Hystrix Gateway Filter.
Consider using Hystrix. It is extremely good for microservices and aligns well with Spring cloud stack. Also, take a look at Feign, due to its simplistic approach to communication between microservices and integration with hystrix and ribbon.

Spring netflix eureka, zuul vs Spring cloud data flow

I am new to the microservice world. Would like to know when to use Spring eureka, zuul vs spring data flow.
I am building a service which in turns will consume multiple granular services(aka micro service), aggregate all the data and returns aggregated data to the consumer. All the services will run in local intranet within company infrastructure. Also, I would like to load balance individual microservices.
What should be the choice of technology for microservices deployment?
I am using Spring 4.3, Spring boot, Rest, Spring data.
I suggest this architecture:
Netflix Eureka : for Service discovery
Consul or Config Server : for saving configurations in environment base on 12 factors
Zuul : for Intelligent and programmable routing
Netflix Ribbon : for Client-Side Load Balancing
Zipkin : for tracing
Turbine : for metrics aggregation
Netflix Feign : for Declarative REST API implementation
Hysterix : for circuit breaker (one of the EIP patterns)
RabbitMQ (Spring-AMQP) or Kafka (Spring-Kafka and Kafka Stream) for having asynchronous communication style
Grafana + Prometheus + Prometheus-jmx-exporter for monitoring system
Docker : for virtualization and container base architecure
Docker Swarm or Kubernetes : for scalability, automation and Container Management
note : Prometheus is a time-series database (including monitoring features) you can also use InfluxDb or Graphite instead of it.
I think the best place to start with is to read through the overview of all these projects here to get a better understanding of the objectives each of these projects achieve.

how to use hystrix to monitoring all microservices

I'm new on microservices and I have seen a tutorial(from udemy) where shows technologies like eureka, feign,spring cloud config,hystrix and zuul, but after make some examples I don't understand very well how hystrix monitor and zuul works, In the examples I noticed that hystrix is used by a main application that it access to microservices and in that way I can monitoring my microservices, but with zuul I noticed that it works like a proxy but this is calling the same microservices like the other application, so my question is how can I monitoring the microservices with hystrix if are called by zuul and by the another application, am I need two hystrix monitor or can I have one general?
Thanks in advance.
After read some examples I noticed that zuul is always the start for applications so I can add hystrix monitor to zuul and call the microservices, but I still have doubt about the circuit breaker in use with zuul so I will keep searching.

Circuit Breaker in a Microservices Architecture

What is the best way to add a Circuit Breaker pattern in a Microservices Architecture. Should it be on the microservice side (inside each microservice), inside an ELB or insider the Api Gateway? What would be the best design pattern?
I think is not use in each microservice, but in your BFF (backend for frontend) who use microservice. You can find a good implementation and exemple in this book https://pragprog.com/book/mnee/release-it. Solution with API Gateway is good, see Kong https://getkong.org/ for that.
There are at least 3 options (illustrated below). In the general case, the circuit breaker "protects" calls to an http service. If we think this service is the microservice, the circuit breaker is never in the microservice itself.
API Gateway
In this case, you use an API gateway product that has circuit breaking support. Ambassador and Axway are examples. An alternative would be to provide circuit breaking in a BFF service that gets the calls to your backend service.
Service mesh
In this case, you use a service mesh product that has support for circuit breaking. Istio with Envoy are an example. In this example, the insurance quote service calls the customer history service. The proxy sidecar container does the circuit breaking.
Circuit breaker lib
Here you use a library that provides circuit breaker support. Resilience4J is the one we use at work (in some Spring Boot apps that call http services).
Your design
Which is best? It depends on your application requirements and infrastructure constraints. Things to remember:
Not all service interactions require circuit breaking.
See if a fallback mechanism (e.g., default response) can be used when the circuit is open.
Log/monitor circuit changes to detect problematic connections and services.
I would suggest you to delegate the circuit breaking concerns to a external library like Hystrix , rather than implementing it yourself.
Hystrix exposes a lot of properties that give you full control in tuning the circuit breaking capabilities.

Resources