← Docs
Recipe

Kafka Patterns

Battle-tested patterns for building reliable, high-throughput event pipelines with Apache Kafka.

Idempotent Producer

Enable enable.idempotence=true to guarantee exactly-once delivery within a producer session. Kafka assigns a producer ID and sequence number to each message, deduplicating retries at the broker level.

Transactional Messaging

Wrap produce and consume operations in transactions when you need atomic reads and writes across multiple partitions. Set transactional.id and use the init-produce-commit cycle. Ideal for read-process-write workflows where partial updates are unacceptable.

Dead Letter Queue

Route poison-pill messages to a DLQ topic after exhausting retries. Configure a separate consumer group that monitors the DLQ and alerts on arrival. Never silently drop messages — every failure must be observable.

Competing Consumers

Scale horizontally by assigning multiple consumers to the same group ID. Kafka distributes partitions across instances automatically. Keep partition count ≥ consumer count to avoid idle consumers.

Schema Registry

Enforce Avro or Protobuf schemas at the broker boundary. Producers register schemas; consumers validate on deserialization. Use backward-compatible evolution rules to prevent breaking downstream services.

Pro tip: Combine idempotent producers with transactional consumers for end-to-end exactly-once semantics. Monitor lag with kafka-consumer-groups and set SLAs per topic.