Giter VIP home page Giter VIP logo

Comments (4)

RobWin avatar RobWin commented on June 12, 2024

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.

andreas-wirth avatar andreas-wirth commented on June 12, 2024

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.

RobWin avatar RobWin commented on June 12, 2024

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.

andreas-wirth avatar andreas-wirth commented on June 12, 2024

Thank you for the support 👍 I decided to set the aspect order accordingly, good hint 😃

from resilience4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.