Changelog Topic

A changelog topic is a Kafka topic that records the updates to a stream processing application’s local state store โ€” the store’s own changes, not the input events that caused them โ€” so the store can be rebuilt after a failure or when the work moves to another instance. Kafka Streams keeps state on the instance that processes a partition and, for each state store, “maintains a replicated changelog Kafka topic in which it tracks any state updates.” With the record cache enabled, several updates to one key can be forwarded as one.

The arrangement is worth stating as a shape rather than a feature: state is local, and the log is the backup. Reads and writes go to a store on the same machine, which is fast; durability comes from the fact that every change is also appended to a topic that Kafka replicates like any other.

How the pieces line up

The changelog is partitioned along with everything else: each local store instance “has its own dedicated changelog topic partition.” That alignment is what makes recovery straightforward โ€” each store instance belongs to one task, and its state is rebuilt from that task’s changelog partition, with no coordination across instances. It also inherits the same ceiling as the rest of the model: parallelism is “bounded by the maximum number of stream tasks, which itself is determined by maximum number of partitions of the input topic(s)” โ€” where the input, for a sub-topology fed by an internal repartition topic, is that topic, whose partition count the application sets.

Recovery time is log length

Rebuilding a store means replaying its changelog partition into a local store โ€” from the beginning when no usable local copy exists, or from the point a surviving local copy had reached. Nothing about that is subtle, which is the appeal โ€” and it means the time to recover is set by how many changelog bytes and records have to be replayed and how fast the store applies them, not by how large the final state happens to be.

Two mechanisms shorten it. Retaining only the latest value per key โ€” log compaction โ€” brings the replay down toward the size of the state rather than the history of updates, which is why changelog topics are normally compacted โ€” with the qualification that compaction runs in the background, so a changelog can hold many not-yet-cleaned updates and the replay is bounded by the state size only once the cleaner has caught up. And a standby replica keeps a warm copy of the store on another instance: the documentation states that on a task migration, Kafka Streams “will assign a task to an application instance where such a standby replica already exists in order to minimize the task (re)initialization cost,” contributing to “a faster recovery time when the rack of the active tasks fails.” A standby still applies whatever it had not yet caught up on, so it shortens the replay rather than eliminating it. Standbys cost memory, disk, and network on the instances holding them, which makes this one of the few availability dials whose price is as visible as its benefit.

Treat it as an operational asset

Changelog topics are created by the framework, which is exactly why they go unmonitored until they matter. Three habits are worth adopting. Watch their size together with the cleaner’s lag, because a growing changelog can mean state that nothing expires, or a few keys updated faster than compaction clears them. Confirm the compaction and retention settings rather than assuming them, since a changelog retained by time can discard updates the store still needs. And remember that adding partitions to a source topic, or changing an internal repartition topic’s count, to scale beyond the task ceiling changes which keys land where, which makes existing state and its changelog no longer aligned โ€” a migration rather than a resize.

How this approach compares with snapshot-based recovery, and what each asks of the team operating it, is worked through in Three Streaming Engines, Three Answers; where a job’s state comes from in the first place is covered in stateful stream processing.

Further reading


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.