RealtimeTrigger icon
Query icon
Switch icon
OutputValues icon
If icon
SlackIncomingWebhook icon
Set icon
Log icon

Real-Time Kafka DLQ Quarantine and Remediation with ClickHouse

Realtime Kafka DLQ stream subscriber that parses poison-pill messages, logs to ClickHouse ReplacingMergeTree, and sends rate-limited Slack alerts on bursts.

Categories
Data

Automate the quarantine, classification, and triage of poisoned Apache Kafka messages in real time. Instead of relying on periodic batch sweeps or allowing unhandled records to accumulate silently in dead-letter queues, this blueprint subscribes directly to Kafka DLQ topics, classifies failure categories, indexes records in ClickHouse using a deduplicating table engine, and fires high-context Slack alerts when error bursts occur.

How it works

  1. Realtime Ingestion: An io.kestra.plugin.kafka.RealtimeTrigger subscribes to the dead-letter topic, launching an independent, real-time execution for each arriving poisoned record.
  2. Metadata and Exception Extraction: Pebble expressions extract the original topic, partition, offset, exception class, stack trace, and timestamp from message payloads and Kafka headers.
  3. Schema and Table Preparation: An io.kestra.plugin.jdbc.clickhouse.Query task ensures the target quarantine table exists, configured with ClickHouse's ReplacingMergeTree engine ordered by original topic, partition, and offset.
  4. Error Classification Gate: An io.kestra.plugin.core.flow.Switch task matches the error category (such as deserialization, schema mismatch, or downstream timeout) and assigns an operational severity along with an actionable remediation hint.
  5. Deduplicated Quarantine Persistence: An io.kestra.plugin.jdbc.clickhouse.Query task inserts the message envelope into ClickHouse. Payloads are safely encoded in base64 to ensure SQL syntax integrity, while ReplacingMergeTree guarantees idempotency during message re-deliveries.
  6. Rolling Burst Calculation: ClickHouse computes the error frequency across the rolling lookback window, extracting top exception classes and sample offsets via analytical aggregate functions (topK, groupArray).
  7. Rate-Limited Alerting: An io.kestra.plugin.core.flow.If task evaluates whether errors exceed burst_error_threshold. If breached, a second check inspects the Kestra KV store. If no alert was sent within alert_cooldown_minutes, a Slack notification is delivered and the cooldown key is written with a time-to-live (TTL). Subsequent events inside the window log diagnostic metrics silently.

What you get

  • Per-Event Streaming Ingestion: Immediate quarantine processing the millisecond a poisoned message arrives on the broker.
  • Safe on Redelivery: ClickHouse ReplacingMergeTree primary key deduplication eliminates duplicate rows during consumer group rebalances.
  • Intelligent Alert Throttling: Sliding window burst detection combined with Kestra KV store TTL cooldown prevents Slack channel fatigue.
  • Zero Script Overhead: Fully declarative pipeline using native Kafka, ClickHouse JDBC, Switch flow control, and Pebble expressions without container dependencies.

Who it's for

  • Streaming Data Engineers: Managing production Kafka clusters and preventing unmonitored DLQ accumulation.
  • Platform and Site Reliability Engineers: Establishing automated event quarantine and fast incident response workflows.
  • Application Developers: Diagnosing serialized payload corruptions and contract mismatch exceptions with full stack traces.

Why orchestrate this with Kestra

While stream processors can route messages, building dedicated consumer applications requires managing infrastructure, consumer groups, offset commits, retries, and rate-limiting state stores. This blueprint differs fundamentally from batch polling flows like clickhouse-kafka-dead-letter-triage, which run periodic scheduled sweeps. Kestra acts as a native real-time subscriber, combining event-driven Kafka consumption with declarative SQL persistence, stateful KV cooldowns, and instant alerting in a unified operational blueprint.

Prerequisites

  • An accessible Apache Kafka broker with a dead-letter queue topic.
  • A running ClickHouse cluster or instance with network access from Kestra workers.
  • An incoming Slack webhook URL for alert delivery.

Secrets

  • KAFKA_BOOTSTRAP_SERVERS: Comma-separated list of Kafka broker host and port addresses.
  • CLICKHOUSE_USER: Username for authenticating with the ClickHouse database.
  • CLICKHOUSE_PASSWORD: Password for authenticating with the ClickHouse database.
  • SLACK_WEBHOOK_URL: Incoming Slack webhook URL for error burst notifications.

Quick start

  1. Configure KAFKA_BOOTSTRAP_SERVERS, CLICKHOUSE_USER, CLICKHOUSE_PASSWORD, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Ensure your ClickHouse database is accessible via the JDBC endpoint defined in clickhouse_url (jdbc:clickhouse://<your-host>:8123/<your-database>).
  3. Import this blueprint into your Kestra instance and enable the dlq_stream_consumer realtime trigger.
  4. Produce a message to your Kafka DLQ topic to verify real-time ingestion, ClickHouse table creation, and audit logging.

How to extend

  • Automated Replay Engine: Add a secondary workflow triggered by operators to read quarantined records from ClickHouse and republish valid events back to the primary topic.
  • PagerDuty Escalation: Route critical schema-mismatch error categories to PagerDuty or Opsgenie using Kestra notification plugins.
  • Materialized Aggregation Views: Build ClickHouse materialized views on the quarantine table to track hourly failure distributions by consumer group and topic.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.