Urgent.News

What's breaking now, across thousands of outlets.

Tech

Circuit Breaker Pattern

One-liner: A circuit breaker stops calling a failing service to give it time to recover — instead of hammering it with requests that are guaranteed to fail. ❓ The Problem: Cascading Failures User Request ↓ Service A ──► Service B ──► Service C (DOWN 💥) ↑ ↑ Threads hang Threads hang (timeout 30s) (timeout 30s) → Service A's thread pool exhausts → Service A goes down → Everything upstream dies →…

The circuit breaker pattern is a technique that prevents a failing service from being repeatedly called, allowing it time to recover. This protects the entire system from cascading failures that occur when one slow service causes a chain reaction, exhausting thread pools and timeouts which then bring down everything upstream.

There are three states in a circuit breaker: CLOSED (normal operation), OPEN (service is down), and HALF-OPEN (testing recovery). When the failure threshold is exceeded, the circuit trips to the OPEN state, immediately failing requests without making a network call and returning cached or default responses. After a reset timeout, the circuit enters HALF-OPEN state to test if the service has recovered. If successful, it returns to CLOSED; if not, it remains in OPEN.

Circuit breakers are implemented in various programming languages, such as Java (Resilience4j, Hystrix), Node.js (opossum), Go (sony/gobreaker), Python (pybreaker), and .NET (Polly). They can also be integrated into service meshes like Istio, requiring no code changes.

Using circuit breakers offers several benefits: preventing cascading failures, providing quick responses instead of long timeouts, and enabling graceful degradation with fallback strategies like cached responses or static pages. However, implementing circuit breakers adds complexity, and tuning the failure threshold can be tricky to avoid flapping or slow tripping. Probes during the HALF-OPEN state may still allow some failures to pass through, and stale cached data as fallback can mislead users.

Circuit breakers are particularly useful when calling external APIs, microservices, or synchronous calls with timeout risks. They should be avoided for local in-process functions, async message queues, or when already using a service mesh that handles circuit breaking.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Japan bag maker develops backpack that turns into life jacket

TAMBA, Hyogo -- A bag manufacturer here has developed and is selling a backpack that can be converted into a life jacket during emergencies. The produ

  • Maru Su Bags develops LIFEBOX backpack as life jacket
  • Converts into flotation device in 60 seconds
  • Inspired by 2011 earthquake, tested in pools

PTA launches upgraded CMS mobile app

The Pakistan Telecommunication Authority (PTA) has launched the upgraded PTA CMS mobile app for iOS and Android, providing consumers with a more secure and user-friendly platform for registering and…

More from Saturday 12 September →