BeginnerCoder

Lesson 23 — Circuit breaker (half-open)

Let the breaker heal itself

An open breaker should not stay open forever. After a cooldown time it goes half-open: it lets one test call through. If that call succeeds, the breaker closes (back to normal); if it fails, it opens again and waits another cooldown.

States: closed → (too many fails) → open → (cooldown passed) → half → closed or open. We pass the time now in so the result is predictable.

Note: real DevOps tools (CI servers, load balancers, Docker, Kubernetes) cannot run in your browser, so this exercise is a small plain-JS simulation of the logic those tools use.

Why it matters: services recover without anyone restarting them by hand at 3 a.m.

Want it another way?
Task

When the breaker is open and now - openedAt >= cooldown, set state to "half" so the test call goes through.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with DevOps Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.