Skip to main content

Kafka topics & client configuration

jeap-messaging tunes Kafka client defaults for MESSAGING (events and commands), not data streaming. It favours durability over latency and throughput, provides at-least-once semantics, commits offsets only after successful processing or hand-off to error handling, expects idempotent consumers and is tuned for clusters with 3 or more nodes.

jEAP messaging default overrides

ScopeParameterjeap-messaging defaultKafka defaultWhy
Produceracksall1Durability
Consumerenable.auto.commitfalsetrueCommit only after success
Listenerspring.kafka.listener.ack-modeMANUALBATCHListener acks after success, error handler acks on failure
Consumermax.poll.records10500~30s per poll batch for transactional event processing
Consumergroup.id${spring.application.name}One group per service
Clientreconnect.backoff.max.ms50001000Retry the broker connection at least every 5s
Listenerauth-exception-retry-interval10snoneRecover from transient auth failures (e.g. cert rotation) without a restart

Recommended topic settings: replicas = 3 and min.insync.replicas = 2 — these must be set on the topic itself.

Topic settings

SettingMeaningTypical
ReplicasCopies of the data including the leader; durability and availability3
RetentionHow long records are keptdev/ref 7d, abn/prd 28d
PartitionsLimit consumer concurrency — one partition per consumer in a groupper throughput
UsersAccess per protection needper topic
min.insync.replicasWith acks=all, the minimum replicas that must ack a write2
message.max.bytesMaximum record size; Kafka is not for large records~1MB

For large payloads, send a reference that is retrievable via S3 or HTTP instead of the payload itself.

Partitioning and keys

Kafka records are key/value pairs with an optional key. The key controls partition distribution via hashing; with no key, records spread evenly across partitions. Records with the same key are consumed in order — ordering is the main reason to set an explicit key. Keys should be fine-grained (for example a business id) to avoid partition imbalance. Do NOT use a key unless ordering guarantees are required. Prefer one message type per topic for maximum decoupling.

Client configuration

Set client tuning via Spring's spring.kafka.* properties:

  • spring.kafka.producer.properties.*
  • spring.kafka.consumer.properties.*
  • spring.kafka.properties.*

Background

Replication

Each partition has a leader and follower replicas. Writes go to the leader and are replicated to the followers; the in-sync replicas are those caught up with the leader.

Consumer groups

Partitions are distributed across the consumers of a group. The maximum number of parallel consumers equals the number of partitions.

Rebalancing

A rebalance happens when a consumer joins or leaves, or on a metadata change. It pauses consumption while partitions are reassigned.

Ordering caveats

Error-handler resubmits and max.in.flight.requests.per.connection > 1 (default 5) can reorder records on retry. This is another reason an idempotent consumer is important.