Comments (4)
Hi,
what kind of exceptions are you facing in a high load scenario? Network issues, timeouts?
What are you trying to achieve with a circuit breaker? While the circuit breaker pattern is beneficial, it's essential to consider the specific context of your application. For example, not all database operations may be suitable for circuit breaker protection, and some may require different resilience strategies. For read-heavy operations, strategies like exponential backoff (retrying with increasing delays between attempts) may be more suitable. In scenarios where data consistency is paramount, a strategy such as transactional retries or a more sophisticated retry mechanism with compensation actions might be preferred over a circuit breaker. This ensures that the critical write operation eventually succeeds.
If you just want to prevent further queries when the Server is overladed, you would need to carefully configure which exceptions should open the circuitbreaker. You could start to attach the CircuitBreaker to all read-only methods since they are not critical.
@CircuitBreaker(name = "entityService")
public List<Entity> getEntity(String entityId) {
return entityRepository.findByEntityId(entityId);
}
from resilience4j.
Thanks for the detailed response!
I am doing retries in case of writes (only on certain failures, e.g. deadlock).
In high load scenarios (e.g. long running selects) requests result in timeout exceptions. The main idea was to record these exceptions with the circuit breaker and block additional requests to help the DBMS to recover.
My (simplified) setup looks like this:
EntityWeb
@CircuitBreaker(name = "CB")
public ResponseEntity<Entity> getEntity(String entityId) {
return ResponseEntity.ok(entityService.getEntity(entityId);
}
EntityService
@Transactional(readOnly = true)
public List<Entity> getEntity(String entityId) {
return entityRepository.findByEntityId(entityId);
}
@Transactional
@Retry
public void saveEntity(Entity entity) {
entityRepository.save(entity)
}
EntityRepository
public List<Entity> getEntity(String entityId) {
return entityRepository.findByEntityId(entityId);
}
As you can see I placed the circuit breaker on the web layer, wrapping the retry and transaction. I was wondering if this is the correct way to use it in this combination, or if I should put it on repository layer, that it is wrapped inside the transaction.
Do you have any opinions / recommendations on this?
from resilience4j.
Hi,
usually I would say put the CircuitBreaker close to the unit of work (method) you want to protect.
But in your case you can put it on the Service layer. You can also use the Aspect Order in Spring Boot to control which of the Annotations/Proxies should come first. If you set the Aspect Order of the CircuitBreaker before the Transactional Proxy you can ensure that the CircuitBreaker does not affect transaction handling.
from resilience4j.
Thank you for the support 👍 I decided to set the aspect order accordingly, good hint 😃
from resilience4j.
Related Issues (20)
- datadog metrics integration HOT 2
- default spring boot configuration? HOT 2
- Spring boot doc bug? HOT 4
- ignoreexceptions in circuitbreaker config not working HOT 1
- Which fallback method will be called after the CB opened with Spring Boot2?
- When adding onRetry event into method itself, retry log reprints ALL previous retries that are already retried. HOT 3
- Retry with OpenFeign Add-On not working HOT 8
- TimeLimiter with deadline support HOT 2
- Circuit breaker stuck in OPEN state HOT 1
- TimeLimiter: Stack overflow error while tryAcquirePermission HOT 7
- Spring Circuitbreaker fallback not working with JDK (interface based) proxies HOT 4
- Cannot set exponential backoff to false in one instance if set to true for default config.
- executeSuspendFunction() ignores retryOnResults predicate HOT 1
- (Retry) documentation out of date HOT 1
- ThreadPoolBulkhead with TimeLimiter, seeing TimeoutExceptions
- How to set exceptionPredicate via API
- Update IntervalFunction to allow full randomization
- check randomization factor in all root level constructors
- RestTemplate.exchange giving response body as null
- feign.RetryableException: Invalid HTTP method: PATCH executing PATCH HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resilience4j.