Quick revision
The short answer
The delete removed payments-events from the cluster metadata at once; the brokers stopped serving it, renamed its partition folders with a -delete suffix and removed them after file.delete.delay.ms, 60 seconds by default, and Kafka has no undelete. Because auto.create.topics.enable was true, the producers' next metadata requests created a brand new topic with the defaults, one partition and replication factor 1, under a new topic id. We recover by stopping producers, deleting the accidental topic, recreating it properly and refilling it from a mirror, an archive or the source systems, then resetting consumer offsets, and we prevent a repeat by disabling auto-creation and restricting who may delete topics.
What to remember
In this answer, we saw that a topic deletion removes the topic from the KRaft metadata immediately and the brokers delete its data a minute later, with no undelete. Running producers then recreated the name through auto-creation, using one partition and replication factor 1 under a new topic id. Recovery means stopping producers, recreating the topic with 48 partitions and replication factor 3, refilling it from a mirror, archive or the source systems, and resetting consumer offsets. Prevention means no auto-creation in production, delete rights only for automation, reviewed topic pipelines, safe defaults, and optionally delete.topic.enable=false.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The delete removed payments-events from the cluster metadata at once; the brokers stopped serving it, renamed its partition folders with a -delete suffix and removed them after file.delete.delay.ms, 60 seconds by default, and Kafka has no undelete. Because auto.create.topics.enable was true, the producers' next metadata requests created a brand new topic with the defaults, one partition and replication factor 1, under a new topic id. We recover by stopping producers, deleting the accidental topic, recreating it properly and refilling it from a mirror, an archive or the source systems, then resetting consumer offsets, and we prevent a repeat by disabling auto-creation and restricting who may delete topics.
Why this question is asked
Deleting the wrong topic is one of the classic Kafka incidents, and the automatic recreation makes it worse: the topic seems to be back, so dashboards look green while ordering and durability are broken. Interviewers like this scenario because a good answer needs to know what deletion does inside the brokers, why the topic came back, how to rebuild data that Kafka itself no longer has, and how to change the platform so one command cannot do this again. In this answer, we will follow the deletion step by step, explain the recreation, walk through the recovery, and finish with the guard rails.
1What Happens Inside Kafka When a Topic Is Deleted
In a KRaft cluster, the controllers own the metadata. When kafka-topics.sh --delete runs, it sends a DeleteTopics request; the active controller writes a record removing the topic to the metadata log, and from that moment the topic no longer exists for clients. Every broker applies the record, stops serving the topic's partitions, and renames each partition directory, for example payments-events-12 becomes something like payments-events-12.<id>-delete.
The renamed directories are removed from disk after file.delete.delay.ms, which defaults to 60,000 milliseconds. So by the time anyone notices, the data is normally gone from every replica. There is no supported undelete command. In theory someone could copy a -delete directory aside within that minute, but restoring it would mean hand-editing metadata, and nobody should plan around that.
7 messages in order. Play them, or step through them one at a time.
The producers did nothing wrong: auto-creation turned their metadata lookups into a topic creation.
2Why the Topic Came Back With One Partition
Producers that were still running got errors for the vanished topic and refreshed their metadata. With auto.create.topics.enable=true, which is the broker default, a metadata request for a topic that does not exist makes the cluster create it. Auto-created topics use the broker defaults num.partitions and default.replication.factor, and both are 1 unless someone changed them.
Notice what that means. The new topic has the same name but a new topic id, so to Kafka it is a different topic. All keys now land on partition 0, so per-key ordering survives only by accident, consumer parallelism is gone, and every record lives on a single broker, so one broker failure loses data. The 7 days of history are not in it, and consumer groups have committed offsets such as 8,400,000 that refer to the old topic.
3Recovering the Topic and Its Data
The first move is to stop writing to the broken topic, otherwise every minute adds records we must later move. We pause or scale down the producers, or block them with a temporary ACL. Then we delete the accidental one-partition topic and create the topic properly.
Next we refill it from the best copy we have. If a MirrorMaker 2 standby cluster exists, the mirrored topic still has the data, because MirrorMaker 2 does not replicate deletions, and we can copy it back with a reverse replication flow or a small copy job. If an object-storage archive exists, we replay the needed days from it. If neither exists, the source systems that produced the payments, such as a payments database with an outbox, republish the last seven days. Records produced during the incident window into the accidental topic are copied over as well, so nothing written in that minute is lost.
Finally, the consumers. Their old offsets are meaningless on the new topic, so we reset each group, usually to the earliest offset of the restored data or to a timestamp, and rely on idempotent consumers to absorb records they had already processed before the deletion. Restarting producers comes last, once the topic is complete.
4Preventing a Repeat
Several guard rails stack up here, and each covers a different part of the failure. Setting auto.create.topics.enable=false on production brokers means a missing topic produces an error instead of a silent new topic. Even then, we set default.replication.factor=3 and a sensible num.partitions, so anything created without explicit settings is at least durable.
Next, permissions. With ACLs, only an automation identity, such as the service account of a topic provisioning pipeline, holds the Delete operation on production topics. Engineers then cannot run the command by hand against the wrong cluster, and every topic change goes through a reviewed pipeline, for example topics declared in Git and applied by Terraform or a GitOps controller, with a plan that shows the deletion before anyone approves it.
Stricter still, delete.topic.enable=false makes the brokers refuse every topic deletion. It is a static broker setting, so legitimate cleanups need a planned rolling change to switch it on and off again. Some regulated platforms accept that friction, because a deleted payments topic is far more expensive than a slow cleanup.
| Setting or practice | What it prevents |
|---|---|
auto.create.topics.enable=false | Silent recreation with wrong layout |
default.replication.factor=3, num.partitions | Fragile topics if something is still created |
| Delete ACL only for automation identity | Manual deletes against the wrong cluster |
| Topic changes through reviewed pipeline | Unreviewed or mistyped changes |
delete.topic.enable=false | All deletion, at the cost of planned cleanups |
| Mirror or archive of critical topics | Permanent loss when the rest fails |
5Follow-up questions
Why was the producer able to create a topic at all?
Topic auto-creation happens on the broker side when it answers a metadata request for a missing topic and auto.create.topics.enable is true. The producer also has allow.auto.create.topics, true by default, which lets it request that. Turning off the broker setting is the reliable control, because it covers every client regardless of its configuration.
Would the consumers have noticed anything?
Consumers subscribed by name would see the new topic after a metadata refresh, find no committed offsets for its new partition, and apply auto.offset.reset, so they would start reading from the earliest or latest offset of the one-partition topic. They would not report an error, which is why this kind of incident can hide for hours.
6Conclusion
In this answer, we saw that a topic deletion removes the topic from the KRaft metadata immediately and the brokers delete its data a minute later, with no undelete. Running producers then recreated the name through auto-creation, using one partition and replication factor 1 under a new topic id. Recovery means stopping producers, recreating the topic with 48 partitions and replication factor 3, refilling it from a mirror, archive or the source systems, and resetting consumer offsets. Prevention means no auto-creation in production, delete rights only for automation, reviewed topic pipelines, safe defaults, and optionally delete.topic.enable=false.
Open with
First I would explain what happened. The delete removed payments-events from the controller's metadata immediately, brokers stopped serving it, renamed the partition directories with a delete suffix and removed them after file.delete.delay.ms, which is 60 seconds by default.
Then, if they want more
There is no undelete. Then the producers, still running, refreshed metadata, and because auto.create.topics.enable is true by default, the cluster created a new topic with num.partitions and default.replication.factor, both 1 by default. It has a new topic id, everything goes to one partition on one broker, and the history is gone.
To recover, I would stop the producers, delete the accidental topic, recreate it with 48 partitions, replication factor 3 and the original configs, and refill it from the best copy: a MirrorMaker 2 replica, an object-storage archive, or a republish from the source systems, plus the few records written during the incident.
Then I would reset each consumer group's offsets, since old offsets point to deleted data, relying on idempotent consumers. To prevent a repeat, I would disable auto-creation in production, give Delete permission only to an automation identity, route topic changes through a reviewed pipeline, set safe defaults anyway, and for regulated topics consider delete.topic.enable=false.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What happened inside Kafka, what can you recover, and what changes prevent a repeat?": https://scrivio-interview-library.netlify.app/spring-boot/kafka-operations/12399fa315/