Kafka Streams EOS: Processing Guarantees That Hold
Senior level ยท What processing.guarantee actually buys you, and the four ways teams break it.
Prerequisites
- !Kafka Streams topology basics
- !Transactional producers and isolation levels
What You'll Learn
- 1Choose between at_least_once, at_least_once_v2, exactly_once and exactly_once_v2
- 2Explain how changelog topics back Kafka Streams state stores
- 3Configure standby replicas for fast task restoration
- 4Identify the four mistakes that break the exactly-once guarantee
One setting, four behaviors
Kafka Streams exposes a single property, processing.guarantee, that selects among four modes. The names look similar and the semantics are not.
| Mode | Output commits | State restoration | Typical use |
|---|---|---|---|
| at_least_once | Immediate per record | Replay from changelog | Metrics, logs, non-critical feeds |
| at_least_once_v2 | Improved batching, still duplicated | Replay from changelog | Throughput-sensitive non-critical |
| exactly_once | Transactional, per task | Replay plus transaction markers | Legacy, superseded |
| exactly_once_v2 | Transactional across input offsets and output records | Replay plus markers, fewer | Default recommendation for critical paths |
exactly_once_v2, introduced as the replacement for the original transactional mode, commits input offsets and output records in a single producer transaction per task. The older exactly_once mode still works, but it opens more transactions and pays a throughput penalty that v2 largely removed, so new topologies should not select it.
Properties props = new Properties();
props.put(StreamsConfig.APPLICATION_ID_CONFIG, "orders-enrichment");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka1:9092");
props.put(StreamsConfig.PROCESSING_GUARANTEE_CONFIG,
StreamsConfig.EXACTLY_ONCE_V2);
props.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
props.put(StreamsConfig.NUM_STANDBY_REPLICAS_CONFIG, 1);
// Input topic is read_committed so aborted transaction records are skipped
props.put(ConsumerConfig.ISOLATION_LEVEL_CONFIG, "read_committed");
The commit interval matters more under exactly_once_v2 than under at_least_once. Every commit opens and closes a transaction, so a short interval increases overhead and a long interval delays output visibility. One hundred milliseconds is a common starting point; go shorter only when downstream latency demands it and you have measured the cost.
How the guarantee is actually built
Three mechanisms combine. An idempotent producer with a task-scoped transactional id prevents duplicates within a task. A producer transaction spans the records written for a batch of input and the corresponding input offsets, so a crash before commit means neither the output nor the offset advance is visible. read_committed on downstream consumers hides any records from aborted transactions that still landed in the topic.
State stores have their own machinery. Every stateful store is backed by a changelog topic, and every update to the store writes through to that topic. On restore, the task replays the changelog to rebuild its local RocksDB or in-memory state. Exactly-once ties the store updates and the output records into the same transaction, so a crash mid-batch leaves the store and the output consistent with each other rather than one ahead of the other.
โ ๏ธExternal side effects are outside the guarantee
Standby replicas and restore time
props.put(StreamsConfig.NUM_STANDBY_REPLICAS_CONFIG, 1);
props.put(StreamsConfig.STATE_DIR_CONFIG, "/mnt/nvme/streams-state");
props.put(StreamsConfig.REPLICATION_FACTOR_CONFIG, 3);
props.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 10 * 1024 * 1024);
A standby replica keeps a warm local copy of a task state store by tailing the same changelog. When the active task fails, the standby can be promoted with seconds of restore instead of replaying an entire changelog, which for a multi-gigabyte store can otherwise take minutes. The cost is an additional consumer and disk footprint per replica, so one standby for critical topologies is the usual trade.
Without standbys, a full restore replays the changelog from its earliest available offset. Compaction on the changelog bounds that size, but compaction is not instant, and a store that accumulated hours of updates before a failure restores slowly enough to look like an outage on its own.
The four mistakes that break exactly-once
// 1. Side effects outside Kafka
.transformValues((v) -> {
httpClient.post("/billing", v); // not transactional, will duplicate
return enrich(v);
});
// 2. Ignoring read_committed on a downstream consumer
// Consumer reads records from an aborted transaction
// 3. External store used as the only sink without idempotent writes
// Task retries after restore, upsert runs twice with non-idempotent logic
// 4. Resetting application.id without resetting offsets
// New group reprocesses from earliest while old transactional ids linger
The first and third are the same root cause in different clothing: the guarantee ends at the Kafka boundary. The second is invisible until an abort happens, which is why read_committed belongs in the shared client configuration rather than in a review checklist. The fourth shows up after a redeploy as duplicated output with no error in the logs, because the new application id starts a fresh group while stale transaction state confuses the broker.
Measuring whether EOS is costing you
Exactly-once_v2 typically costs ten to thirty percent of throughput relative to at_least_once, mostly from transactional overhead and reduced batching. Measure produce throughput and end-to-end latency with both modes on a staging cluster using production-like record sizes before committing a critical path to it. If the workload is a metrics rollup where a duplicate aggregate is harmless, at_least_once_v2 buys the throughput back with no real risk.
When state restoration becomes the incident
The moment a stateful Streams task fails, the recovery story shifts from processing to restoration, and restoration time is a function of changelog size, not of input rate. A store that accumulated hours of updates before a failure will replay all of them, and until the replay finishes the task is not processing new input. For a small store this is a blip; for a multi-gigabyte aggregation store it can exceed the recovery time objective of the business process the topology serves, which means the topology is correct and still unacceptable in production.
Standby replicas reduce restore time by keeping a warm copy, but they do not eliminate it entirely. A standby that was a few seconds behind the active at the moment of failure still has a small gap to close, and if the standby itself was still restoring from an earlier failure, promotion does not help at all. Monitoring restore duration and the lag between active and standby store sizes gives you the signal that a promotion would actually be fast versus one that would not; without that signal, standby replicas provide a false sense of readiness.
The other lever is bounding state growth. A key-space that grows without bound, such as an aggregation keyed by a user id that never expires, produces a changelog that grows without bound, and every restore gets slower over the same workload that was fine last month. Windowed aggregations with explicit retention, or periodic sessionization that folds old keys into a lower-cardinality summary, keep the store size proportional to recent activity rather than to the lifetime of the system. This is a design decision made once at topology authoring time and invisible in throughput metrics until the first restore fails under its own weight.
One more operational habit is worth adopting: rehearse the restore. Periodically kill a stateful instance in a staging environment, measure how long the task takes to return to active processing, and compare it against the recovery objective. Teams that have never watched a real restore routinely discover that their five-minute recovery objective is actually a forty-minute changelog replay, and that discovery is far cheaper to make in staging than in an incident channel.
Common Mistakes
Selecting exactly_once instead of exactly_once_v2 on a new topology
Fix: Use exactly_once_v2. The older mode opens more transactions and pays throughput the newer mode reclaimed, with no additional guarantee.
Calling an external API inside a processor under EOS
Fix: Route critical side effects through an output topic, or make the external call idempotent with a business key. EOS covers Kafka-to-Kafka transactions only.
Running downstream consumers without read_committed
Fix: Set isolation level to read_committed in the shared consumer configuration, otherwise records from aborted transactions are processed as if they committed.
Leaving num.standby.replicas at zero for a large stateful topology
Fix: Configure at least one standby for critical tasks. Full changelog restore on a multi-gigabyte store can take longer than the incident you are recovering from.
Best Practices
- Default new critical topologies to exactly_once_v2 and measure the throughput cost per service
- Set read_committed on every consumer of an EOS output topic, and enforce it in a shared client library
- Keep at least one standby replica for stateful topologies whose restore time would exceed the recovery objective
- Compacted changelogs plus bounded state keep restore times predictable; alert on changelog size growth
- Make external writes idempotent with a business key rather than relying on the Kafka transaction to cover them
Interview Questions
Q1: What does processing.guarantee=exactly_once_v2 actually guarantee?
That each record is processed and its output committed exactly once across task restarts, by committing input offsets and output records in a single producer transaction per task. It does not cover side effects outside Kafka.
Q2: How do changelog topics relate to state stores?
Every stateful store writes every update to a dedicated changelog topic. On restore the task replays that topic to rebuild local state, and under EOS the store updates participate in the same transaction as the output records.
Q3: Why set a standby replica?
A standby tails the changelog and holds a warm copy so a failed active task can be promoted in seconds instead of replaying the full changelog, which for large stores can take minutes.
Q4: What breaks the guarantee most often in production?
External side effects inside a processor. The call succeeds, the task crashes before the transaction commits, and on restore the call runs again. The fix is an output topic or an idempotent external write.
Q5: How much throughput does exactly_once_v2 cost?
Typically ten to thirty percent relative to at_least_once, depending on record size and commit interval. Measure it on staging with production-like traffic before committing a critical path.
Key Takeaways
- exactly_once_v2 is the default recommendation; the older exactly_once mode costs throughput for no extra guarantee
- EOS commits input offsets and output records in one transaction per task, and nothing beyond the Kafka boundary
- Changelog topics back every state store; standbys turn a multi-minute restore into seconds
- read_committed isolation on downstream consumers is part of the guarantee, not an optional setting
- External side effects must be routed through topics or made idempotent, because the transaction will not cover them