Implement a Thread-Safe Circuit Breaker

Asked at Databricks · Coding Questions · Difficulty: Hard · Last asked Nov 17, 2025

A service that keeps calling a broken dependency wastes time on calls that will fail and can make the outage worse. Build a **circuit breaker**: an object that wraps calls to the dependency, stops sending them after repeated failures, and lets one trial call through after a cool-down to see whether the dependency has recovered. Many threads share one breaker, so it must be thread-safe.

Loading the problem…