What is advantage of circuit breaker design pattern in API architecture?

后端 未结 3 1682
醉酒成梦
醉酒成梦 2021-02-10 17:37

So sorry if this question is not fit for SO.

But I tried looking lot for answer.

I was studying Circuit Breaker design pattern, As I understand its used for maki

3条回答
  •  被撕碎了的回忆
    2021-02-10 17:41

    The goal of this design pattern is to encapsulate the logic for handling unexpected, repeated errors.

    The wikipedia page for this pattern has helpful sections explaining the types of situations where you would want to implement this logic to avoid making request that you expect to fail.

    What is the advantage of this pattern

    This pattern is advantageous when you run into a situation where you know a service will be unavailable, and you want custom behavior until the service comes back online. For example, during a database migration, it would make sense to circuit break requests into a queue until the migration has finished.

    What is difference between catch block and circuit breaker

    I think this difference is the difference between concept and implementation. Detecting the presence of a situation where you want to "open the circuit" might mean detecting errors in a catch block and counting them, as in your example. The handling is not limited to just errors, however.

    In my example, the backend might inform the frontend that a migration is about to occur, causing an "open circuit" on the frontend until it receives a migration finished message.

提交回复
热议问题