Schedule icon
Script icon
If icon
Create icon
SlackIncomingWebhook icon
Log icon

Apache Kafka Under-Replicated Partition Health Sentinel

Monitor Apache Kafka partition replication and prevent data loss risks with Kestra. Query cluster metadata, open GitHub issues, and alert Slack.

Categories
DataInfrastructure

Mission-critical streaming platforms rely on Apache Kafka's distributed replication protocol to safeguard event data against broker node failures. When a broker falls behind due to network saturation, I/O bottlenecks, or JVM garbage collection pauses, it drops out of the In-Sync Replicas (ISR) set, leaving partitions in an under-replicated state. If additional brokers fail while partitions are under-replicated, data loss or topic unavailability occurs. This blueprint queries Kafka cluster topic metadata periodically via an admin client, identifies partitions whose ISR count is smaller than configured replicas, opens a prioritized GitHub SRE incident ticket, and alerts the streaming platform team on Slack.

How it works

  1. periodic_kafka_partition_check (io.kestra.plugin.core.trigger.Schedule) initiates the audit every 15 minutes (shipped disabled for safe verification).
  2. probe_under_replicated_partitions (io.kestra.plugin.scripts.python.Script) connects to the bootstrap brokers using KafkaAdminClient and reads partition replica vs ISR arrays across all topics.
  3. branch_on_under_replicated (io.kestra.plugin.core.flow.If) evaluates whether any partitions have fewer in-sync replicas than configured replicas (has_under_replicated == true):
    • then: Automatically files a GitHub tracking issue via create_kafka_incident_issue (io.kestra.plugin.github.issues.Create) and alerts the Slack channel via alert_streaming_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook).
    • else: Emits an informational log entry (log_cluster_healthy) confirming all partitions are fully replicated.
  4. log_audit_complete (io.kestra.plugin.core.log.Log) records the final health summary.
  5. The errors block alerts Slack if broker connection times out or authentication fails.

What you get

  • Automated, scheduled auditing of distributed Kafka partition health.
  • Early warning before multi-broker failures cause data loss or cluster write blocks.
  • Consolidated GitHub incident tickets with topic names, partition IDs, and replica vs ISR ratios.
  • Real-time Slack notifications with direct ticket hyperlinks.

Who it's for

  • Streaming Platform Engineers and Kafka Administrators operating high-throughput event backbones.
  • Site Reliability Engineers safeguarding real-time event streaming availability.
  • Data Engineers monitoring message durability and broker balance.

Why orchestrate this with Kestra

Kestra coordinates external cluster admin API querying, replica metadata comparison, conditional escalation, and chat alerting in a single declarative workflow. It provides complete execution history and eliminates the need for separate standalone monitoring daemons or fragmented bash cron scripts.

Prerequisites

  • An Apache Kafka cluster (OSS Kafka, Strimzi, AWS MSK, or Confluent Platform).
  • Network connectivity from the Kestra worker to Kafka broker endpoints.
  • A GitHub Personal Access Token with repository issue creation permissions.
  • A Slack incoming webhook URL for notifications.

Secrets

  • GITHUB_TOKEN: GitHub token used to open incident issues.
  • SLACK_WEBHOOK: Incoming Webhook URL for streaming alerts.

Inputs

  • bootstrap_servers (STRING, default kafka-broker1.internal.company.com:9092,kafka-broker2.internal.company.com:9092): Comma-separated list of Kafka broker endpoints.
  • target_repository (STRING, default my-org/streaming-platform): Target GitHub repository for logging incident issues.

Outputs

  • outputs.probe_under_replicated_partitions.vars.total_partitions: Total count of partitions inspected.
  • outputs.probe_under_replicated_partitions.vars.under_replicated_count: Number of partitions currently under-replicated.
  • outputs.probe_under_replicated_partitions.vars.under_replicated_partitions: List of degraded partition objects (topic, partition, configured_replicas, in_sync_replicas).

Quick start

  1. Configure GITHUB_TOKEN and SLACK_WEBHOOK in your Kestra namespace.
  2. Import this flow and set bootstrap_servers to match your cluster endpoints.
  3. Run the flow manually to verify cluster metadata querying and Slack notification delivery.
  4. Enable the periodic_kafka_partition_check trigger for continuous streaming health monitoring.

How to extend

  • Add an automated reassignment task (kafka-reassign-partitions.sh) to rebalance partitions across healthy brokers.
  • Integrate TLS/mTLS or SASL/SCRAM authentication configurations into the Python admin script.
  • Route urgent alerts to PagerDuty or Opsgenie if more than 5 partitions remain under-replicated for over 30 minutes.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.