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

后端 未结 3 952
别跟我提以往
别跟我提以往 2021-02-10 17:18

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:40

    It is true that a great use of Circuit breaker is used to make an API fault tolerant.

    Like what is difference between catch block and circuit breaker.

    The major difference between a catch block and circuit breaker is the handling of the failure case. Suppose we are calling an api of an external system. Lets say, the api call failed.

    1. If we use catch block, we will catch the Exception and call a fallback method. Next time we will call the same api and the external system is still down. So again this same cycle of events will occur. This will unnecessary bombard the suffering external system, consume system resources and also increase your api response time.

    2. If we use circuit breaker pattern, then our first call fails and then we open the circuit. Next time we won't even call the external system, and directly follow the fallback pattern. Voila everything is handled!

    And what can we do in fall back method? How can this help?

    One good example for a fallback method is as follows. We have a payments system which routes payments to different payment gateways. Lets say we get an error from a particular payment gateway, then in the fallback method we can route it to different payment gateway.

    You can also go through this article to understand more about this topic : https://martinfowler.com/bliki/CircuitBreaker.html

提交回复
热议问题