This project demonstrates the Circuit Breaker Design Pattern, implemented in Go, to improve the resilience of distributed systems. It simulates an unstable external service that randomly fails, showing how the circuit breaker prevents cascading system failures.
The Circuit Breaker Pattern works like an electrical switch that “opens” the circuit after detecting too many consecutive failures. This prevents the main system from continuously calling a failing service, allowing it to recover gracefully.
Circuit States:
| State | Description |
|---|---|
| 🟢 Closed | All good — requests flow normally. |
| 🔴 Open | Too many consecutive failures — block new requests for a cooldown period. |
| 🟡 Half-Open | Allow a few test requests to check if the service has recovered. |
resilience-lab/ ├── main.go # Simulation runner ├── flaky_service.go # Unstable service simulation ├── circuit_breaker.go # Circuit Breaker implementation └── go.mod
# Initialize Go module
go mod init resilience-lab
# Run the simulation
go run .