⚙️ Protect downstream APIs with a circuit breaker using Data Tables
⚡ 2 views · ⚙️ DevOps & CI/CD
Description
Quick overview
Stop n8n workflows from repeatedly calling an unavailable API by opening a circuit after consecutive failures, enforcing a cooldown, and allowing a controlled half-open recovery trial.
How it works
- Receives a POST request on the
/webhook/circuit-breaker-checkendpoint with aservice_keyto decide whether a downstream API call should proceed. - Looks up the service’s circuit state in the
service_circuitsn8n Data Table and evaluates whether to allow, block, or start a half-open trial based on the current state and cooldown window. - Creates or updates the circuit record when entering half-open, then responds with
allow_request, the currentstate, andretry_after_secondsfor the caller. - Receives a POST request on the
/webhook/circuit-breaker-resultendpoint with theservice_keyplussuccessand optionalerrorto record the outcome of an allowed call. - Updates the
service_circuitsrecord to close the circuit on success or increment failures and open the circuit (withopen_until) when the failure threshold is reached or a half-open trial fails, then returns a confirmation response.
Setup
- Create an n8n Data Table named
service_circuitswith the columns listed in the template (includingservice_key,state,failure_count,failure_threshold, and the timestamp fields) and select it in each Data Table step. - Copy the two webhook URLs from n8n and configure your calling service to POST to
/webhook/circuit-breaker-checkbefore an external API call and to/webhook/circuit-breaker-resultafter each allowed call. - Update the circuit breaker defaults in the configuration step (for example
failure_thresholdandcooldown_minutes) to match your reliability requirements.
Requirements
- Data Tables enabled
- No credentials or paid services are required.
Customization
- Use a separate service_key for each provider or endpoint.
- Adjust thresholds for critical or rate-limited services.
- Route blocked requests to a queue, fallback response, or retry workflow.
- Replace Data Tables with PostgreSQL for strict concurrency guarantees.
🔗 Nodes Used
Webhook, Data table
📥 Import
Download workflow.json and import into n8n:
Workflow menu → Import from File