Webhook icon
Schedule icon
OutputValues icon
If icon
Fail icon
RedisCLI icon
Docker icon
Log icon
Pause icon
SlackIncomingWebhook icon

Quarantine Redis Streams Poison Messages After Repeated Delivery

Safely quarantine repeatedly delivered Redis Streams entries by original ID; XACK follows a durable, idempotent hash write.

Categories
DataInfrastructure

A worker crash can leave a Redis Stream entry pending, while a poison payload can fail every delivery. This flow handles the second case: entries already retried enough times. It checks idle time and delivery count, then stores the original fields in a Redis hash before XACK. It does not delete consumers or promise exactly-once business processing.

How it works

  1. validate_inputs rejects unsafe CLI arguments and unbounded scans.
  2. inspect_pending calls bounded XPENDING IDLE; log_findings records candidate IDs and counts.
  3. route_candidates (If) requires apply=true, dry_run=false, and candidates. A Pause asks for approval.
  4. quarantine_poison rechecks the live PEL, uses XAUTOCLAIM JUSTID, writes one hash field per original ID with HSETNX, then calls XACK only after the field exists.
  5. verify_quarantine fails if a pending ID has no source payload. notify_quarantine sends one actionable Slack alert for newly stored entries.

Error handling

  • RedisCLI retries connection failures with exponential backoff, and errors names the execution and cause.
  • The Lua handoff is isolated from other clients. If a failure occurs after HSETNX but before XACK, the next run verifies the original-ID record and finishes the ACK without writing a second record.
  • A missing payload is never ACKed by this flow. Inspect it manually because Redis may already have trimmed or deleted it.
  • The batch is bounded to 100 inspected rows. Approval is bound to the inspected IDs; a late approval rechecks each ID and its thresholds before any write.

What this blueprint teaches about Kestra

Combine a read-only plan, If and Pause approval gate, and a RedisCLI Lua handoff that keeps message state recoverable across retries. A disabled Schedule can be enabled after tuning the thresholds; the Webhook allows on-call to request an immediate review.

Prerequisites

Redis 7 or later with a stream and consumer group; redis-cli Docker tasks must reach it. The Redis role needs XPENDING, XRANGE, XAUTOCLAIM, HGET, HSETNX, HLEN, and XACK. Configure the Slack webhook secret. For protected Redis, add password: "{{ secret('REDIS_PASSWORD') }}" to both RedisCLI tasks.

Secrets

  • SLACK_WEBHOOK_URL: operator alert destination; pass as a Kestra secret, never a flow input.
  • REDIS_PASSWORD (optional): Redis password when enabling authentication on both CLI tasks.

Inputs

  • stream=orders, group=g1: source stream and existing group.
  • quarantine_hash=orders:g1:quarantine: hash where each source ID maps to JSON with hex-encoded original fields and delivery count.
  • rescue_consumer=poison-review: owner used only while claiming a poison ID for quarantine.
  • min_idle_ms=900000, max_deliveries=5: thresholds; tune above normal processing time and expected retries.
  • batch_count=25, start_id=-: bounded page through idle PEL entries; pass the returned next_start for the next page.
  • host=redis-poison, port=6379, database=0, network=redis-poison-net: connection and Docker network.
  • apply=false, dry_run=true, approval_timeout=PT2H: three safeguards before XACK.

Outputs

  • inspection (JSON): total pending, scanned rows, poison IDs, and next page bound.
  • quarantine (JSON): newly stored IDs, recovered existing records, missing payload IDs, and pending count after. Empty on a read-only run.

Quick start

  1. Start Redis 7 on a Docker network and create orders plus group g1; arrange for a worker to leave a repeatedly delivered entry pending.
  2. Import the flow and set SLACK_WEBHOOK_URL. Run read-only first and inspect the candidate IDs.
  3. Set apply=true and dry_run=false; approve the Pause. Confirm HGET orders:g1:quarantine <id> before manually redriving the payload. fields_hex preserves binary field names and values in alternating order; decode each hex string before replay.

Plugins used

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.