This skill diagnoses ClickHouse Kafka engine health and consumer performance to reduce lag and prevent thread starvation.
npx playbooks add skill altinity/skills --skill altinity-expert-clickhouse-kafka
Answers "are the Kafka consumers polling, committing and keeping up, and is anything starving them?" from system.kafka_consumers, system.metric_log, system.query_views_log and system.text_log.
Run altinity-expert-clickhouse-connection first if the connection mode, cluster and time window are not yet established.
checks.sql — 7 checks: consumption health per consumer (kafka-01), average rows per commit (kafka-02), rebalances and assignments (kafka-03), consumers versus message broker pool size (kafka-04), pool utilization over 12 hours (kafka-05, needs system.metric_log), slow materialized views on Kafka tables (kafka-06, needs system.query_views_log), Kafka messages in the log (kafka-07, needs system.text_log).advanced_checks.sql — 4 checks: consumer exception drill-down for one table (needs {db} and {kafka_table}), total lag per table, lag per partition, broker connection health. The last three parse rdkafka_stat. The file also contains a three-statement consumption-speed recipe marked @skip-matrix: it creates a temporary table, sleeps, then compares snapshots, so all three statements must run in ONE clickhouse-client session. It cannot run over MCP or as separate --query calls.troubleshooting.md — common Kafka errors and configuration fixes (ACL errors, poll interval, dead letter queue, offset rewind, parallel consumption tuning).references/rack-awareness.md — cross-AZ and client.rack investigation; load it when the question involves AWS MSK, KAFKA_CLIENT_RACK, cross-AZ cost, VPC endpoints, or a Kafka cluster migration.reference.md — background (Kafka engine and librdkafka settings); read only when you need to explain a recommendation.; and start with a -- @check <id> <title> header; keep the id with its result.-- @requires: skip the statement when the named table is missing, when keeper is required and the server has no Keeper/ZooKeeper, or when the version condition is not met. List skipped ids with the reason.{cluster} as written when a cluster macro exists; otherwise apply the connection skill's rewrite rule. Any other {placeholder} is a template variable: substitute a real value first or skip the statement.UNKNOWN_IDENTIFIER, run DESCRIBE TABLE system.<table> and drop the missing column.severity column is the verdict for that row. Copy it; do not re-grade.last_exception_time >= last_poll_time or last_exception_time >= last_commit_time: it is failing rather than progressing. Otherwise treat it as healthy even if lag exists.exceptions is a tuple of arrays with matching indices. exceptions.time[-1] and exceptions.text[-1] are the most recent error; quote both.kafka_consumers > mb_pool_size (kafka-04) is thread starvation: consumers wait for a free thread. Fix by raising background_message_broker_schedule_pool_size (default 16). Size it as the total of all Kafka, RabbitMQ and NATS consumers plus 25 percent.max.poll.interval.ms, which gets the consumer kicked from the group. Errored view executions are usually the rebalance interrupting a batch mid-flight, not an independent bug.JSONExtract calls re-parsing the same JSON blob. The fix is one-pass JSONExtract(json, 'Tuple(...)') plus tupleElement(); see troubleshooting.md in this directory.rdkafka_stat is empty unless <statistics_interval_ms> is set in the Kafka engine config. If it is empty, report the three lag and broker checks as skipped for a missing prerequisite, not as OK.client.rack alone changes nothing: the brokers must run RackAwareReplicaSelector, which is not the default. Verify the broker-side selector before recommending any rack setting.tx and rx are request and response counts while txbytes and rxbytes are bytes. Attribute per-broker and cross-AZ traffic from the byte counters only.check, severity, object, evidence, recommendation; one row per finding, Critical first. Evidence quotes the numbers from the result rows.altinity-expert-clickhouse-ingestionaltinity-expert-clickhouse-mergesaltinity-expert-clickhouse-reportingaltinity-expert-clickhouse-schemaaltinity-expert-clickhouse-replicationaltinity-expert-clickhouse-metricsWeekly roundup of top Claude Code skills, MCP servers, and AI coding tips.