Distributed

Circuit Breaker Pattern

Description

The Circuit Breaker pattern prevents an application from repeatedly trying to execute an operation that's likely to fail. It allows the application to continue without waiting for the fault to be fixed or wasting CPU cycles while it determines that the fault is persistent.

Where to use

  • Microservice communication.
  • \n
  • Preventing cascading failures.
  • \n
  • External API dependencies.

Real World Example

If the 'Recommendation Service' is down, the 'Frontend' stops calling it (Circuit Open) and just shows popular products from a cache instead of hanging for 30 seconds.

Code Example

# Code Concept for Circuit Breaker Pattern\n# This pattern is architectural.\n\nclass Service:\n    def execute(self):\n        # Implementation logic\n        pass