Data and Knowledge SystemsVersioning and migrationPrincipal
Why can a retained Kafka topic fail to preserve the history needed for an agent’s audit?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
An agent must explain who changed a refund policy last year and which rule applied at that time. The team retained a Kafka topic keyed by policy ID and assumes replay will reconstruct every change. Explain how compaction and retention affect that claim, what evidence you would inspect, and how you would design current-state rebuilding and historical audit as separate requirements.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
A retained topic can preserve enough information to reconstruct current state without preserving every historical change. Kafka log compaction removes superseded values for a key in the background. That is useful for rebuilding a latest-value table, but an audit needs the intermediate values and the evidence explaining when and why they changed.
What does “retained” mean for this topic? With log compaction, Kafka keeps a recent value for each key so a consumer can rebuild current state. Older values for that key can be removed during background cleaning. A tombstone can eventually remove the key from that reconstructed state too. Kafka's design documentation describes compaction as a latest-value-per-key mechanism. It does not promise to preserve every change event forever just because the topic still exists and its beginning offset can be read.
Imagine policy refund-limit changed from 100 to 200 and then 150. A newly started consumer of a compacted topic may see only 150. That is enough to build the latest policy table. It cannot answer “who raised it to 200 last March, and what did the agent know that day?” A long-lived consumer that processed every event earlier might have written its own history, but replay from the compacted topic alone cannot recreate what compaction removed. Even a non-compacted topic is not automatically a permanent audit archive. Its time and size retention settings still matter.
I would inspect cleanup.policy, retention settings, compaction and tombstone age, key design and actual oldest records. If each update has a unique event ID as its key, compaction behaves differently, but retention and audit integrity still need a deliberate design. For a defensible history, publish immutable change events with actor, effective time, recorded time, old and new version or a stable reference, then retain them under a governed policy. Materialize current state separately. If policy updates and event publication can diverge, use a transactional outbox or equivalent recovery path, and reconcile the current policy against the audit stream.
This matters to an AI agent because asking it for a historical explanation requires evidence from that historical moment. A current compacted policy topic can tell the agent what rule applies now. It cannot safely supply a missing chronology. If the history is gone, the honest answer is that the evidence is unavailable, not a plausible narrative inferred from today's value. The audit log says approved. Can you prove what the reviewer saw? asks whether an approval log proves what a reviewer saw. Here the log chosen for source replay was designed to discard intermediate values.
In the hypothetical 100 → 200 → 150 sequence, the archive needs enough evidence to reconstruct both transitions. That could be the initial state plus two change events, or two events that carry their complete before-and-after values. A current-state consumer may need only 150. Keeping each change under its own event identity avoids collapsing all transitions under one compaction key, but the archive still needs explicit time/size retention, access controls and integrity checks. The choice of key is only one part of the evidence lifecycle.
Record effective time separately from recorded time when rules can be entered late or scheduled for the future. A policy entered today but effective next month must not be treated as yesterday’s governing rule. Also preserve the policy revision actually supplied to an agent run if the question is what that run knew. Do not infer past model context from the source’s current value. If an archive or version is missing, disclose that limit instead of synthesizing an audit chronology.
Related questions
Keep practising data and knowledge systems
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux