How it works
A slow dependency can do more harm than a dead one, because callers hold threads and connections while they wait. For example, a page server has 200 threads and calls a recommendations service 100 times per second. If that service hangs with no timeout set, the pool is exhausted in 2 seconds, and pages that never needed recommendations stop too. A 1-second timeout caps the threads held by this call at about 100 (100 per second times 1 second), and the server stays up. Set timeouts from measured latency, and pass the remaining deadline downstream, or lower services keep working on requests nobody is waiting for.
With a circuit breaker, the caller tracks recent failures, and past a threshold the breaker opens: calls fail immediately without touching the dependency, which also gives it room to recover. After a pause it goes half-open and lets a few trial calls through. If they succeed, it closes. Pair it with a fallback where one exists, such as rendering the page with no recommendations. Notification System uses a breaker for unhealthy providers. Track failures per dependency or shard, so one failing shard does not open the breaker for all.
Load shedding is the server’s own defense. It rejects excess requests early with a fast 503, so accepted requests still finish within their deadline. Shed by priority, so checkout survives when recommendations do not, and decide from in-flight count or queue delay. The costs: rejected users see errors, thresholds need tuning, and a rejection must be far cheaper than the work it avoids.
A product page calls inventory, which it cannot render without, and recommendations, which are optional. Recommendations normally answers in 80 ms at p99 and has started hanging. How do you treat each dependency?
Give recommendations a short timeout a little above its normal p99, perhaps 200 ms, plus a breaker and a fallback that renders the page without it. Inventory needs a timeout too, set longer from its own latency data, and its breaker has no fallback: when open, the page returns a clear error quickly rather than hold threads. Treating both alike either loses pages to an optional feature or gives up on a required one too early.
Use this as a guide for self review; written answers are not graded.Keep in mind
- A remote call with no timeout lets a slow dependency take its callers down with it.
- A timeout limits one wait, a breaker stops calling for a while, and shedding refuses work at the server.
- A fast rejection protects the requests a server has already accepted.