Kafka client configuration
StoatFlow constructs its own Kafka consumer, producer, and restoration consumers. You configure those clients by passing standard Kafka client properties through your application.yaml under stoatflow.kafka.*. This page covers the passthrough form, the opinionated defaults StoatFlow layers on top, and the small set of properties it forces for exactly-once correctness.
Passthrough form
Every property you set under stoatflow.kafka.consumer, stoatflow.kafka.producer, stoatflow.kafka.restoration-consumer or stoatflow.kafka.admin is passed straight to the corresponding Kafka client, using the exact Kafka property names (dotted keys):
stoatflow:
bootstrap-servers: localhost:9092
kafka:
consumer:
max.poll.records: 1000
auto.offset.reset: latest # StoatFlow defaults this to earliest; override to latest here
fetch.min.bytes: 65536
producer:
batch.size: 524288
linger.ms: 50
compression.type: lz4
You don't need to list every property — only the ones you want to change. Anything you omit falls back to StoatFlow's framework default, and anything StoatFlow doesn't set falls back to the Kafka client default.
Keys are passed to the client exactly as written, so write them dotted, as Kafka spells them. A dashed key whose dotted form is a real client property is almost certainly a typo, and StoatFlow says so at start:
stoatflow.kafka.consumer.group-id: did you mean group.id? Kafka client properties are dotted; 'group-id' reaches the client as written
The key still reaches the client as group-id, which ignores it. Under stoatflow.config.strict: true the start fails instead. A dashed key that is not a client property — a serde's own setting, such as Apicurio's apicurio.registry.auto-register — passes silently.
For where these keys sit in the wider configuration tree (and how YAML, environment variables, and system properties compose), see the configuration model and the core configuration reference.
How consumer properties resolve
Consumer properties are resolved by merging layers, each overwriting the previous:
| Layer | Source | Purpose |
|---|---|---|
| 1 | Kafka client defaults | Implicit defaults from the Kafka client library |
| 2 | Framework defaults | StoatFlow's opinionated defaults (see below) |
| 3 | stoatflow.kafka.consumer | Your overrides |
| 4 | main.consumer. keys | Main-consumer-only overrides — reachable only from a KS-keyed Properties, not YAML |
| 5 | Forced overrides | Set by the framework, cannot be overridden |
Framework defaults
| Property | StoatFlow default | Kafka default | Rationale |
|---|---|---|---|
max.poll.records | 500 | 500 | Matches the Kafka default |
fetch.max.bytes | 50 MiB | 50 MiB | Matches the Kafka default |
max.partition.fetch.bytes | 10 MiB | 1 MiB | A single instance consumes all partitions; larger per-partition fetches reduce network round trips |
auto.offset.reset | earliest | latest | Matches Kafka Streams (which also defaults its main consumer to earliest) — a fresh application.id processes the topic from the beginning. Overridable. |
max.poll.interval.ms | 10 min | 5 min | StoatFlow is single-instance, so a coordinator partition revocation caused by another member is always fatal (no peer to rebalance to — a revocation caused by a deleted pattern-matched topic is classified separately and survived). Genuine hangs are already caught by the commit-pipeline watchdog (commit-stall-threshold-ms, 45 s) and the stall-aware liveness probe, so a short interval only causes spurious fatal shutdowns under transient slowness (GC pauses, CPU contention, a slow blocking downstream). A generous default removes that false-positive risk. Overridable. |
partition.assignment.strategy | CooperativeStickyAssignor | [Range, CooperativeSticky] → Range | Kafka's default list runs the eager protocol: every rebalance revokes the whole assignment first, and StoatFlow reads a post-start revocation as "a second instance joined" and stops. Under cooperative-sticky a single member sees no revocation when a topic starts matching a stream(Pattern) source or when a source topic's partition count grows — both become incremental assignments. A second instance joining, and a deleted literal source topic, remain fatal; a deleted pattern-matched topic is survived by an in-place engine restart. Overridable, but an eager override reinstates the self-termination and disables the graceful deletion path — under an eager assignor every rebalance revokes the whole assignment, so a deleted topic can never be told apart from a second member (StoatFlow logs this distinctly when it happens). StoatFlow logs a startup warning when the first entry of the effective strategy is not cooperative-sticky. |
One conditional default: a topology with a stream(Pattern) source sets metadata.max.age.ms to 30 s (Kafka: 5 min) unless you set the key yourself — it bounds how long a newly created matching topic waits to be picked up. A pure-literal topology's consumer config is untouched. The /config endpoint renders the same merge the engine runs with, this default included.
Forced overrides
These are always set by the framework. Setting them under stoatflow.kafka.consumer has no effect.
| Property | Value | Reason |
|---|---|---|
bootstrap.servers | from stoatflow.bootstrap-servers | Must match the cluster |
group.id | the application ID | Static group membership for the single instance |
group.instance.id | the application ID | Static membership (KIP-345) for instant partition re-assignment on restart |
enable.auto.commit | false | Offsets are committed by StoatFlow's commit protocol, not by the Kafka client |
isolation.level | read_committed — exactly-once only | An exactly-once application must not ingest a transactional upstream's aborted batches. Matches Kafka Streams. Under at-least-once the key is not forced, so you can still set it yourself if you read a transactional upstream |
allow.auto.create.topics | false | StoatFlow never creates source topics, and Kafka's client default (true) lets a permissive broker create any topic a consumer names — silently resurrecting a deleted topic, turning a typo'd name into a real empty one, or giving a changelog the broker's cleanup.policy=delete. Matches Kafka Streams, which also forbids overriding it. Note this narrows the exposure, it does not close it: producer-side auto-creation is hardcoded in the Kafka client. Static sink and declared dead-letter topics are checked at start (validation.validate-output-topics), so a missing one refuses the start before any send, but a topic a TopicNameExtractor or a custom handler picks per record can still be created by a send — and, since the Kafka 4.4 client, under exactly-once the producer keeps asking for the source topics whose offsets it committed in roughly the last 10 minutes, so a source topic matched by a pattern and deleted in that window can be re-created, empty, before StoatFlow drops it (StoatFlow commits a partition's offset when it moves, about 15 minutes after a start and every 12 hours; an idle topic is exposed only in the ~10 minutes after those). Only broker-side auto.create.topics.enable=false is complete |
bootstrap.resolve.timeout.ms | 0 | Synchronous bootstrap DNS resolution, the client default. A positive value (KIP-909) makes a client resolve asynchronously and stay permanently broken if resolution fails — it has to be closed and rebuilt, which StoatFlow does not do for the clients it owns. Matches Kafka Streams 4.4, which forces the same value |
auto.offset.reset defaults to earliest (matching Kafka Streams) rather than the raw Kafka client's latest. It is not forced — override it globally under stoatflow.kafka.consumer, or per source topic with Consumed.withOffsetResetPolicy(...), which takes precedence for that topic. As in Kafka Streams, while any source has a policy of its own (a globalTable always has one), StoatFlow runs the main consumer with none and resets each partition it cannot position itself — one with no committed offset, or one whose committed offset is no longer in the topic: by its source's policy, else by your auto.offset.reset. A partition with neither (policy none, or no policy under auto.offset.reset: none) stops the application, naming it. A log truncated by an unclean leader election is not a reset: the consumer resumes where its log diverged from the new leader's, whatever the policy. /config still shows your value.
One exception: with hot-standby HA enabled, group.instance.id is omitted (and any user-set value removed) — HA pods use assign() with no consumer-group membership, so static membership does not apply.
How producer properties resolve
Producer properties resolve through the same layered merge:
| Layer | Source | Purpose |
|---|---|---|
| 1 | Kafka client defaults | Implicit defaults from the Kafka client library |
| 2 | Framework defaults | StoatFlow's opinionated defaults (see below) |
| 3 | stoatflow.kafka.consumer security subset | The consumer's security.* / ssl.* / sasl.* settings, so a secured cluster needs its credentials only once |
| 4 | stoatflow.kafka.producer | Your overrides |
| 5 | Forced overrides | Set by the framework, cannot be overridden |
security. / ssl. / sasl. family inherits the rest and ends up mixed. A consumer on OAUTHBEARER plus a producer setting only sasl.mechanism: PLAIN and sasl.jaas.config still inherits the consumer's sasl.login.callback.handler.class, and the producer then fails to construct at startup. The admin client and the restoration consumers inherit the consumer's security keys the same way (see SASL and SSL). StoatFlow warns when it detects a partial shadow in stoatflow.kafka.producer, stoatflow.kafka.admin or stoatflow.kafka.restoration-consumer, and names the inherited keys.Framework defaults
| Property | StoatFlow default | Kafka default | Rationale |
|---|---|---|---|
batch.size | 256 KiB | 16 KiB | StoatFlow produces output across many keys at once; larger batches improve throughput |
linger.ms | 20 | 0 | Wait up to 20 ms to fill batches — paired with the larger batch.size |
retry.backoff.ms | 50 | 100 | Halves the per-retry wait on the transaction coordinator's transient CONCURRENT_TRANSACTIONS response, shrinking the commit-latency tail at frequent commit cadences |
buffer.memory | 256 MiB | 32 MiB | Headroom for the larger batches without producer-side backpressure |
enable.idempotence | true | true | Explicit baseline locked to the StoatFlow version, insulating you from upstream default changes. Also forced in EOS mode (below). |
acks | all | all | Explicit baseline locked to the StoatFlow version. Also forced in EOS mode. |
max.in.flight.requests.per.connection | 5 | 5 | Explicit baseline locked to the StoatFlow version. Also forced in EOS mode. |
compression.type | zstd | none | Compresses everything the processing producer sends — outputs, changelogs and dead letters. Shortens the commit's producer flush (and so the commit cadence) and cuts broker disk and network bytes; every Kafka consumer since 2.1 reads zstd. Kafka Streams sets no codec. |
buffer.memory (256 MiB) is producer-side buffering and is separate from RocksDB and state-store memory. On small-heap deployments (under ~2 GiB) with both heavy state writes and heavy sink output, consider reducing buffer.memory — see the memory-constrained scenario below and the tuning guide.Forced overrides
| Property | Value | Reason |
|---|---|---|
bootstrap.servers | from stoatflow.bootstrap-servers | Must match the cluster |
retries | Integer.MAX_VALUE | Unlimited retries are required for idempotent / transactional producer correctness |
max.block.ms | the configured barrier timeout | Bounds how long a send() can block on a slow broker, so a broker slowdown surfaces as a timeout rather than a silent stall |
delivery.timeout.ms | the configured barrier timeout | Bounds the end-to-end delivery path on the same budget |
bootstrap.resolve.timeout.ms | 0 | Synchronous bootstrap DNS resolution — see the consumer's forced overrides. Also forced on the admin client |
The barrier timeout is the stoatflow.commit-barrier.timeout-ms knob — see the core configuration reference.
Exactly-once mode only
When the processing guarantee is EXACTLY_ONCE, StoatFlow additionally forces the transactional producer properties:
| Property | Value | Reason |
|---|---|---|
transactional.id | {applicationId}-producer | Transaction-coordination identity. StoatFlow commits every source partition's offset at least every 12 hours, even with no records, so the brokers' transactional.id.expiration.ms (default 7 days) never expires it — keep that setting at a day or more |
transaction.timeout.ms | the configured barrier timeout | Must align with the commit budget |
enable.idempotence | true | Required for the transactional producer — disabling it breaks exactly-once |
acks | all | acks < all weakens durability under broker failures, which is incompatible with the exactly-once guarantee |
max.in.flight.requests.per.connection | 5 | The maximum that still preserves the idempotent producer's ordering guarantee |
In at-least-once mode (AT_LEAST_ONCE), enable.idempotence, acks, and max.in.flight.requests.per.connection stay at the framework-default layer and remain overridable via stoatflow.kafka.producer, so you can trade throughput against durability. In exactly-once mode they are forced: any value you set under stoatflow.kafka.producer is overwritten by the framework's forced override, so the client never sees a configuration that would break exactly-once. To see what the producer actually receives, check the resolved configuration (see Inspecting the resolved configuration below).
Restoration consumer
State stores recover from changelog topics on startup using dedicated restoration consumers, which are configured independently of the processing consumer under stoatflow.kafka.restoration-consumer. They inherit the processing stoatflow.kafka.consumer as a shared baseline, then layer restoration-specific defaults and overrides on top:
| Layer | Source | Purpose |
|---|---|---|
| 1 | Kafka client defaults | Implicit defaults from the Kafka client library |
| 2 | stoatflow.kafka.consumer | Processing-consumer config — shared baseline inherited by restoration |
| 3 | Framework defaults | Restoration-specific defaults (see below) |
| 4 | stoatflow.kafka.restoration-consumer | Your restoration overrides |
| 5 | Forced overrides | Set by the framework, cannot be overridden |
Framework defaults
Tuned for bulk changelog reads during recovery:
| Property | Default | Kafka default | Rationale |
|---|---|---|---|
max.poll.records | 1,000 | 500 | Larger batches reduce poll overhead during bulk reads |
fetch.max.bytes | 50 MiB | 50 MiB | Matches the Kafka default (already large) |
max.partition.fetch.bytes | 10 MiB | 1 MiB | Faster per-partition fetches during restoration |
Forced overrides
| Property | Value | Reason |
|---|---|---|
bootstrap.servers | from stoatflow.bootstrap-servers | Must match the cluster |
group.id | {applicationId}-restoration-{timestamp} | Unique per restoration run |
enable.auto.commit | false | Restoration offsets are tracked alongside the state, not by the Kafka client |
auto.offset.reset | none | A restore never skips records it has not read. A restore reads from an exact offset, from the store's checkpoint or from the topic's start. If that offset is no longer in the topic (retention or deleteRecords moved the log start past it during the restore), the start fails, naming the store, partition and offset, and keeps local state; the store is marked, and the next start restores it in full. One exception: a partition that held nothing yet and has read nothing — a full restore's, or one with no local state — just starts at the new log start. Kafka Streams' restore consumer is none too. On a hot standby the in-place re-restore of a store is retried instead, three attempts in all |
isolation.level | read_committed (exactly-once only) | Under exactly-once a restore reads only committed data, as processing does. Under at-least-once it is not forced: the restore reads at your consumer (or restoration-consumer) isolation level, Kafka's default read_uncommitted. Set read_committed on consumer, not under main.consumer., so processing and the restore both skip a transactional upstream's aborted records: a main.consumer. key does not reach the restore consumer (Kafka Streams parity) |
allow.auto.create.topics | false | StoatFlow never creates source topics, and Kafka's client default (true) lets a permissive broker create any topic a consumer names — silently resurrecting a deleted topic, turning a typo'd name into a real empty one, or giving a changelog the broker's cleanup.policy=delete. Same reasoning as the processing consumer; a restoration consumer assigns changelog partitions, and assign() requests creation just as subscribe() does. Note this narrows the exposure, it does not close it: producer-side auto-creation is hardcoded in the Kafka client — static sink and declared dead-letter topics are checked at start (validation.validate-output-topics), but a topic chosen per record can still be created by a send — only broker-side auto.create.topics.enable=false is complete |
bootstrap.resolve.timeout.ms | 0 | Synchronous bootstrap DNS resolution — see the processing consumer's forced overrides. The HA standby's changelog consumer is built from this configuration, so it is forced there too |
Restoration tuning:
stoatflow:
kafka:
restoration-consumer:
max.poll.records: 5000
fetch.max.bytes: 104857600 # 100 MiB
Common tuning scenarios
High throughput
For maximum throughput with high event rates:
stoatflow:
kafka:
consumer:
max.poll.records: 2000
fetch.min.bytes: 65536 # 64 KiB — wait for larger fetches
fetch.max.wait.ms: 200 # max wait for fetch.min.bytes
producer:
batch.size: 524288 # 512 KiB
linger.ms: 50 # allow more time to fill batches
compression.type: lz4 # cheaper CPU than the zstd default; more bytes on the wire
Low latency
For latency-sensitive workloads:
stoatflow:
kafka:
consumer:
fetch.min.bytes: 1 # return immediately (Kafka default)
max.poll.records: 100 # smaller batches for lower processing latency
producer:
linger.ms: 0 # send immediately
batch.size: 16384 # Kafka default (16 KiB)
Large records
When individual records are large (e.g. complex Avro > 10 KB):
stoatflow:
kafka:
consumer:
max.partition.fetch.bytes: 20971520 # 20 MiB
fetch.max.bytes: 104857600 # 100 MiB
producer:
max.request.size: 10485760 # 10 MiB
buffer.memory: 536870912 # 512 MiB
Memory-constrained environments
When heap is limited:
stoatflow:
kafka:
consumer:
max.poll.records: 100
max.partition.fetch.bytes: 1048576 # 1 MiB (Kafka default)
fetch.max.bytes: 10485760 # 10 MiB
producer:
batch.size: 32768 # 32 KiB
buffer.memory: 33554432 # 32 MiB (Kafka default)
Fast restoration
For large state stores where recovery time matters:
stoatflow:
kafka:
restoration-consumer:
max.poll.records: 5000
receive.buffer.bytes: 1048576 # 1 MiB socket buffer
Low-memory restoration
When restoration causes GC pressure on a constrained heap:
stoatflow:
kafka:
restoration-consumer:
max.poll.records: 200
max.partition.fetch.bytes: 1048576 # 1 MiB (Kafka default)
fetch.max.bytes: 10485760 # 10 MiB
Setting properties via environment variables
Kafka client properties can also be set via environment variables, which take precedence over -D system properties and YAML. The variable is the map's path — STOATFLOW_KAFKA_CONSUMER_, STOATFLOW_KAFKA_PRODUCER_, STOATFLOW_KAFKA_RESTORATION_CONSUMER_ or STOATFLOW_KAFKA_ADMIN_ — followed by the property name, upper-cased, with each . as _:
# Consumer properties
export STOATFLOW_KAFKA_CONSUMER_MAX_POLL_RECORDS=1000 # max.poll.records
export STOATFLOW_KAFKA_CONSUMER_FETCH_MAX_BYTES=104857600 # fetch.max.bytes
# Producer properties
export STOATFLOW_KAFKA_PRODUCER_BATCH_SIZE=524288 # batch.size
export STOATFLOW_KAFKA_PRODUCER_LINGER_MS=50 # linger.ms
export STOATFLOW_KAFKA_PRODUCER_COMPRESSION_ZSTD_LEVEL=3 # compression.zstd.level
# Restoration consumer properties
export STOATFLOW_KAFKA_RESTORATION_CONSUMER_MAX_POLL_RECORDS=5000
A property whose name contains _ or - uses the escapes: __ is a literal _ and ___ a literal - (the convention Confluent's images use). So Apicurio's apicurio.registry.auto-register on the producer is:
export STOATFLOW_KAFKA_PRODUCER_APICURIO_REGISTRY_AUTO___REGISTER=true
A -D system property names the entry verbatim: -Dstoatflow.kafka.producer.linger.ms=50. See How configuration works for the full rule and precedence.
SASL and SSL
Authentication and encryption are plain Kafka client properties — pass them through like any other:
Set them once, under consumer. StoatFlow propagates the consumer's security.* / ssl.* / sasl.* subset to every other client it builds — the producer, the admin clients (changelog topic management, broker health check, consumer-group preflight), the restoration consumers, and the HA coordination-topic clients:
stoatflow:
bootstrap-servers: broker-1:9093,broker-2:9093
kafka:
consumer:
security.protocol: SASL_SSL
sasl.mechanism: PLAIN
sasl.jaas.config: ${KAFKA_SASL_JAAS_CONFIG}
ssl.truststore.location: /etc/kafka/truststore.jks
ssl.truststore.password: ${KAFKA_TRUSTSTORE_PASSWORD}
Keep secrets out of committed files — reference them with placeholders as shown: ${KAFKA_SASL_JAAS_CONFIG} reads a variable, and ${secret:…} a mounted file.
If a particular client authenticates as a different principal, override it on that client's own map — stoatflow.kafka.producer, stoatflow.kafka.admin or stoatflow.kafka.restoration-consumer — which always wins over the inherited subset. Spell out every key of the family you are overriding: the override is per key, so anything you leave out is still inherited (see the warning above). The HA coordination-topic clients follow the same maps: their producer takes stoatflow.kafka.producer's keys, their admin client stoatflow.kafka.admin's, and their consumer — which reads the topic like a restoration consumer — stoatflow.kafka.restoration-consumer's. Each also takes its counterpart's client.dns.lookup, which Kerberos behind a CNAME bootstrap depends on (resolve_canonical_bootstrap_servers_only).
stoatflow:
kafka:
consumer:
security.protocol: SASL_SSL
sasl.mechanism: PLAIN
sasl.jaas.config: ${KAFKA_SASL_JAAS_CONFIG}
admin:
# only when the admin principal differs from the consumer's
sasl.jaas.config: ${KAFKA_ADMIN_SASL_JAAS_CONFIG}
Properties normally spells these unprefixed (security.protocol at the top level, no consumer. prefix). That works: StoatFlow routes a bare client key to every client it is valid for, exactly as Kafka Streams does, with any prefixed spelling taking precedence. See the KS compatibility matrix.Secrets from a mounted directory
The simplest way to keep a credential out of YAML is ${secret:name}, which reads the file name from the secrets directory — /run/secrets, unless STOATFLOW_SECRETS_DIR says otherwise — once at start. It works in every value, on every client map, with no per-client setup:
stoatflow:
kafka:
consumer:
security.protocol: SASL_SSL
sasl.mechanism: SCRAM-SHA-512
sasl.jaas.config: ${secret:jaas}
ssl.truststore.location: /etc/kafka/truststore.jks
ssl.truststore.password: ${secret:truststore-password}
The value is masked in /config, in the logs and in error messages. Mount the files with a Kubernetes Secret volume or Docker secrets — see Secrets from files for the rules (one trailing newline removed, a missing file fails the start naming the path).
Secrets from Kafka config providers
Kafka's own config providers — FileConfigProvider (KIP-297), DirectoryConfigProvider — use the same ${…} shape, but they are not StoatFlow placeholders: a ${dir:…} or ${file:…} reference reaches the client as written, and the client resolves it, once the client's map names the provider and its class:
stoatflow:
kafka:
producer:
config.providers: dir
config.providers.dir.class: org.apache.kafka.common.config.provider.DirectoryConfigProvider
config.providers.dir.param.allowed.paths: /etc/kafka-secrets
sasl.jaas.config: ${dir:/etc/kafka-secrets:jaas}
Declare the provider on every client map that uses a reference — the config.providers keys are client properties like any other. A JVM started with Kafka's hardening flag -Dorg.apache.kafka.automatic.config.providers=<classes> allows only the provider classes it lists. ${secret:…} needs none of this setup, so prefer it unless your platform already standardises on Kafka's providers.
Inspecting the resolved configuration
The merged application configuration is available at runtime from the /config HTTP endpoint, with sensitive values (passwords, secrets, tokens, anything from ${secret:…}) masked. It serves JSON or YAML by content negotiation. See the REST API reference.
The resolved configuration is also logged at startup when the engine logger is at DEBUG:
logging:
level:
io.stoatflow.core.runtime.StreamProcessingEngine: DEBUG
Defaults, adaptivity, and the memory plan
Why a minimal StoatFlow config runs well — the opinionated defaults, the parts that self-tune within bounds you set, the memory plan that splits the container between the heap and RocksDB, and the RocksDB knobs you can change.
The runtime
The batteries-included :runtime module — StoatFlowRuntime.fromConfig, the lifecycle (start / awaitTermination / stop), and what it adds over the bare :core engine.