---
title: Kafka
slug: telemetry-pipeline/kafka
docTags: 
createdAt: 2025-04-21T00:46:23.924Z
---

## Kafka Source

Collect logs, metrics, and traces from **Apache Kafka topics** using a consumer group–based ingestion model.

This source allows worker to act as a **Kafka consumer**, reading observability data from one or more topics and integrating Kafka-native streaming pipelines into centralized telemetry architectures.

## Collection Model

- Worker connects to Kafka using **bootstrap servers**&#x20;
- One or more topics are consumed via a **consumer group**&#x20;
- Partitions are assigned dynamically by Kafka&#x20;
- Events are decoded from raw message payloads&#x20;
- Successfully processed events advance committed offsets&#x20;

This model aligns with **Kafka-native scalability and fault tolerance** patterns.

## Consumer Group Semantics

- Each worker instance joins the specified consumer group&#x20;
- Kafka guarantees:&#x20;
  - Partition ownership by a single consumer at a time&#x20;
  - Automatic rebalancing on scale-up or failure&#x20;
- Offsets are committed periodically based on configuration&#x20;

This enables:

- Horizontal scaling&#x20;
- High availability&#x20;
- Exactly-once *processing intent* with at-least-once delivery guarantees&#x20;

## Offset Management and Reliability

### Offset Commit Behavior

- Offsets are committed at configurable intervals&#x20;
- Commit timing balances:&#x20;
  - Throughput&#x20;
  - Recovery speed&#x20;
  - Duplicate processing risk&#x20;

On restart or rebalance:

- Consumption resumes from the last committed offset&#x20;
- Uncommitted messages may be reprocessed&#x20;

### Shutdown and Rebalance Handling

During shutdown or partition revocation:

- Worker attempts to drain pending acknowledgements&#x20;
- A configurable timeout ensures:&#x20;
  - Graceful shutdown&#x20;
  - Consumer group stability&#x20;
  - Prevention of forced rebalance eviction&#x20;

## Topic Selection Strategy

- Topics can be defined explicitly&#x20;
- Regular expressions are supported&#x20;
- Enables:&#x20;
  - Dynamic topic discovery&#x20;
  - Prefix-based ingestion&#x20;
  - Multi-tenant Kafka usage&#x20;

This is particularly useful in environments with **high topic churn**.

## Event Decoding

Kafka messages are delivered as raw bytes and must be decoded.

### Supported Codecs

- JSON&#x20;
- Syslog (RFC 3164 / RFC 5424)&#x20;
- GELF&#x20;
- Avro (including schema ID stripping)&#x20;
- Protobuf&#x20;
- OTLP (logs, metrics, traces)&#x20;
- InfluxDB Line Protocol&#x20;
- Worker native formats&#x20;
- Raw bytes&#x20;
- VRL-based custom decoding&#x20;

Some codecs can automatically infer the event signal type.

### Multi-Signal Support

The Kafka source supports:

- Logs&#x20;
- Metrics&#x20;
- Traces&#x20;

For OTLP and native formats:

- Signal types can be auto-detected&#x20;
- Parsing order can be restricted for performance optimization&#x20;

## Framing and Message Boundaries

Framing defines how events are extracted from Kafka message payloads.

Supported strategies include:

- Byte passthrough&#x20;
- Newline-delimited&#x20;
- Character-delimited&#x20;
- Length-delimited&#x20;
- Octet counting&#x20;
- Varint length-delimited&#x20;
- Chunked GELF&#x20;

Frame size limits prevent malformed messages from exhausting memory.

## Metadata Enrichment

Kafka-specific metadata can be attached to each event, including:

- Topic name&#x20;
- Partition number&#x20;
- Offset&#x20;
- Message key&#x20;
- Message headers&#x20;

These fields enable:

- Debugging&#x20;
- Replay logic&#x20;
- Downstream routing and filtering&#x20;
- Auditing and lineage tracking&#x20;

## Kafka Client Configuration

### librdkafka Integration

Worker uses **librdkafka** internally, enabling:

- Fine-grained client tuning&#x20;
- Broker-specific optimizations&#x20;
- Advanced protocol features&#x20;

Low-level Kafka parameters can be passed directly when needed.

## Security and Authentication

### TLS Support

- Encrypted connections to Kafka brokers&#x20;
- Custom CA bundles&#x20;
- Certificate verification and hostname validation&#x20;
- Required for production-grade clusters&#x20;

### SASL Authentication

Supported mechanisms:

- PLAIN&#x20;
- SCRAM-based authentication&#x20;

For advanced mechanisms (e.g. Kerberos):

- Native librdkafka options are used&#x20;

This allows compatibility with **enterprise Kafka deployments**.

## Metrics and Observability

### Consumer Lag Metrics

Optional metrics expose:

- Per-topic lag&#x20;
- Per-partition lag&#x20;

These metrics are critical for:

- Backlog detection&#x20;
- Capacity planning&#x20;
- Pipeline health monitoring&#x20;

## Reliability Characteristics

- At-least-once delivery semantics&#x20;
- Stream-based ingestion&#x20;
- Backpressure-aware processing&#x20;
- Offset-based recovery&#x20;
- Stateless processing model&#x20;

These properties make the Kafka source suitable for **high-volume, continuous telemetry ingestion**.

## Common Use Cases

- Centralized log aggregation from Kafka&#x20;
- Metrics and trace ingestion via OTLP over Kafka&#x20;
- Streaming observability pipelines&#x20;
- Multi-tenant Kafka telemetry platforms&#x20;
- Decoupled producer–consumer architectures
