Quick overview
This workflow exposes a webhook-based circuit breaker that routes requests to approved external APIs, tracks failures per service in Redis, and temporarily blocks calls when failure thresholds are exceeded, optionally sending an alert to a Slack-compatible webhook.
How it works
- Receives a POST webhook request with a service name plus the target path, method, and payload.
- Validates the service against a configured allowlist, builds the target URL, and rejects unknown services or unsafe paths with a 404 response.
- Reads the service’s circuit state from Redis and either allows the call, rejects immediately with 503 and a Retry-After header, or enters a half-open state after the cool-down.
- If half-open, claims a single probe slot in Redis so only one request tests recovery while others receive 503.
- Calls the external API with a configured timeout and classifies failures as network/timeout errors, HTTP 5xx, or HTTP 408 (while other 4xx responses do not count as service failures).
- On success, returns the upstream response and closes the circuit in Redis if the request was a half-open probe.
- On failure, increments a Redis failure counter, opens the circuit when the threshold is reached (or on a failed probe), optionally posts an alert via an HTTP webhook, and returns a 502 response describing the failure and circuit status.
Setup
- Configure Redis credentials for every Redis step and ensure your Redis instance is reachable from n8n.
- Update the service registry in the configuration (service name to base URL, with optional per-service thresholds and open duration) so only approved APIs can be called.
- Adjust default thresholds and timeouts (failure threshold/window, open duration, request timeout) to match your reliability requirements.
- If you want notifications, set an alertWebhookUrl for a Slack-compatible incoming webhook endpoint.
- Copy the production webhook URL for the circuit breaker endpoint and update your calling workflows/apps to send POST requests with { service, path, method, payload }.