Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Circuit Breaker and Connection Timeout?

From my understanding, circuit breaker is a thing that can "disconnect" a connection when there is a issue (takes a long time than usual) when communicating to other service. Instead of always retrying to communicate with broken service, it will wait for a moment to give the broken service time to recover.

But we also already have "connection timeout", if a connection takes a long time it will stop and return error.

Therefore what is the difference?

like image 432
Shalahuddin Al-Ayyubbi Avatar asked Sep 15 '25 03:09

Shalahuddin Al-Ayyubbi


1 Answers

The two ideas are certainly similar, and can be used to achieve similar properties.

A connection timeout is often implemented at a lower level. In your question, you say that "we already have" it. And it's true: most TCP or HTTP libraries will offer this feature by default. It might help to know that there are some services where it will not apply - for example connectionless services like UDP.

Sometimes, there can be a problem even if the connection is successful. It may be that the service you're connecting to keeps returning an error. Or maybe it takes a long time to respond with a useful answer, even though the connection doesn't drop. It's these higher-level aspects that can be caught with a circuit breaker pattern.

Some references that I find helpful:

  • https://blog.codecentric.de/en/2019/06/resilience-design-patterns-retry-fallback-timeout-circuit-breaker/
  • https://martinfowler.com/bliki/CircuitBreaker.html
like image 89
John Avatar answered Sep 17 '25 18:09

John