Webhook icon
Script icon
Process icon
If icon
Request icon
Set icon
Write icon
SlackIncomingWebhook icon

Webhook Circuit Breaker and Dead-Letter Quarantine Sentinel

Circuit breaker for webhooks in Kestra. Tracks consecutive downstream failures in KV, sheds load when degraded, and quarantines payloads to DLQ storage.

Categories
CoreInfrastructure

Webhook receivers from external platforms like Stripe, GitHub, or Shopify can easily overwhelm degraded downstream microservices during outages or database lockups. When internal endpoints start failing with 5xx errors, retry storms compound the issue, causing catastrophic cascades and lost webhook events.

This blueprint implements an adaptive Circuit Breaker & Dead-Letter Quarantine pattern directly within Kestra:

  1. Circuit State Evaluation: Every inbound webhook inspects the current circuit state (CLOSED or OPEN) and consecutive failure tally stored in Kestra's namespace KV store.
  2. Graceful Delivery & Error Trapping: When CLOSED, the flow forwards the payload to the downstream internal service using options.allowFailed: true. Non-2xx responses do not crash the workflow, allowing Kestra to inspect the exact status code.
  3. Automated Tripping: On success, consecutive failures are reset to 0. On failure, the counter increments. Once failures cross the configurable failure_threshold, the circuit flips to OPEN and fires a high-priority Slack alert.
  4. Dead-Letter Quarantine: When the circuit is OPEN, subsequent webhooks bypass the degraded downstream service entirely. The raw payload is immediately enveloped with execution context and saved to Kestra internal storage (io.kestra.plugin.core.storage.Write).
  5. Concurrency Serialization: Uses concurrency: {limit: 1, behavior: QUEUE} to ensure consistent sequential evaluation and race-free KV counter updates.

How it works

  1. External webhooks POST to the inbound_webhook trigger (io.kestra.plugin.core.trigger.Webhook).
  2. check_circuit_state reads webhook_circuit_state and webhook_circuit_failures from the namespace KV store.
  3. route_delivery_or_quarantine (io.kestra.plugin.core.flow.If) branches:
    • If CLOSED: Calls attempt_forward (io.kestra.plugin.core.http.Request). If the response is HTTP 2xx, reset_circuit_on_success sets failures back to 0. If the response is non-2xx, record_delivery_failure increments the counter, updates KV, writes the payload to quarantine_failed_delivery, and notifies Slack via notify_slack_trip if the threshold was crossed.
    • If OPEN: quarantine_open_payload stores the event directly in internal storage and notify_slack_quarantine posts an operational update to Slack.

What you get

  • Automatic protection against cascading microservice outages and thundering herds.
  • Dead-letter quarantine: intercepted or failed webhook payloads are preserved in Kestra internal storage as immutable JSON artifacts when storage writes succeed.
  • State machine tracking via Kestra's native KV store with no external database dependency.
  • Instant Slack alerts upon circuit tripping or event quarantine.
  • Full execution outputs exposing final_circuit_state, delivery_status_code, and dead_letter_uri.

Who it's for

  • Platform Engineers and SREs managing inbound webhooks from SaaS providers.
  • Backend developers operating APIs with fragile dependencies during maintenance or traffic spikes.
  • Teams looking for a turnkey dead-letter queue (DLQ) and circuit breaker pattern without deploying complex proxy infrastructure.

Prerequisites

  • A Slack Incoming Webhook URL to receive incident and quarantine alerts.
  • Python 3 on the Kestra worker environment (Process runner).

Secrets

  • WEBHOOK_SECRET_KEY: Secret key segment for the Kestra webhook trigger endpoint URL.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for alerting.

Inputs

  • receiver_url: Downstream HTTP service URL (defaults to https://httpbin.org/post).
  • failure_threshold: Number of consecutive failures before tripping the circuit (defaults to 3).
  • request_timeout: HTTP request timeout duration (defaults to PT10S).

Quick start

  1. Configure secrets WEBHOOK_SECRET_KEY and SLACK_WEBHOOK_URL in your Kestra namespace.
  2. Deploy the flow into namespace company.team.
  3. Trigger a test event by sending an HTTP POST request to the webhook endpoint:
    curl -X POST "http://localhost:8080/api/v1/executions/webhook/company.team/webhook-circuit-breaker-quarantine-sentinel/${WEBHOOK_SECRET_KEY}" \
      -H "Content-Type: application/json" \
      -d '{"event_id": "evt_101", "type": "payment.succeeded", "amount": 4200}'
    
  4. Inspect the execution logs:
    • If receiver_url is healthy, the output will show final_circuit_state: CLOSED and delivery_status_code: 200.
    • To simulate a circuit trip, set receiver_url to an endpoint returning 500 (e.g. https://httpbin.org/status/500) and send requests until the threshold is met.

Manual Reset

To reset an OPEN circuit back to CLOSED, either update the KV key in the Kestra UI under Namespaces > KV Store, or run a one-line curl command:

curl -X PUT "http://localhost:8080/api/v1/namespaces/company.team/kv/webhook_circuit_state" \
  -H "Content-Type: application/json" \
  -d '"CLOSED"'

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.