0
0
Kafkadevops~10 mins

Topic deletion and cleanup in Kafka - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Topic deletion and cleanup
Start
Request Topic Deletion
Mark Topic for Deletion
Broker Deletes Topic Data
Cleanup Logs and Metadata
Topic Removed from Cluster
End
The flow shows how a topic deletion request marks the topic, then brokers delete data and clean metadata, finally removing the topic from the cluster.
Execution Sample
Kafka
kafka-topics.sh --delete --topic my-topic --bootstrap-server localhost:9092
This command requests deletion of 'my-topic' from the Kafka cluster.
Process Table
StepActionInternal State ChangeResult
1Send delete request for 'my-topic'Topic marked for deletion in controllerDeletion initiated
2Controller notifies brokersBrokers receive deletion commandPrepare to delete topic data
3Brokers delete topic partitions dataTopic data files removed from diskStorage freed
4Brokers clean up topic metadataTopic metadata removed from logsMetadata cleaned
5Controller updates cluster stateTopic removed from cluster metadataTopic no longer listed
6Clients receive updated metadataNo references to 'my-topic'Topic deletion complete
💡 Topic fully deleted and cleaned up from cluster and brokers
Status Tracker
VariableStartAfter Step 1After Step 3After Step 5Final
Topic StateExistsMarked for deletionData deletedMetadata removedDeleted
Broker StorageContains topic dataContains topic dataTopic data removedCleaned metadataNo topic data
Cluster MetadataIncludes topicIncludes topicIncludes topicTopic removedNo topic
Key Moments - 3 Insights
Why does the topic still appear briefly after deletion is requested?
Because the topic is first marked for deletion (Step 1) and brokers need time to delete data and metadata (Steps 3 and 4). It is removed from cluster metadata only after cleanup (Step 5).
What happens if a client tries to produce to the topic during deletion?
Clients receive updated metadata after deletion (Step 6). Before that, produce requests may fail or be rejected because the topic is marked for deletion and data is being removed.
Is topic deletion immediate?
No, deletion involves multiple steps: marking, data deletion, metadata cleanup, and cluster update. This ensures safe removal without data loss.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the topic data actually removed from disk?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Check the 'Internal State Change' column for data removal details.
According to the variable tracker, what is the state of 'Cluster Metadata' after Step 5?
AIncludes topic
BMarked for deletion
CTopic removed
DNo topic data
💡 Hint
Look at the 'Cluster Metadata' row under 'After Step 5' column.
If the deletion command is sent but brokers fail to delete data, what step would not complete successfully?
AStep 1
BStep 3
CStep 5
DStep 6
💡 Hint
Step 3 is when brokers delete topic partitions data.
Concept Snapshot
Topic deletion in Kafka:
- Use kafka-topics.sh --delete to request deletion
- Topic is marked for deletion by controller
- Brokers delete topic data and clean metadata
- Controller updates cluster metadata
- Clients see updated metadata without the topic
- Deletion is asynchronous and involves multiple steps
Full Transcript
This visual execution trace shows how Kafka deletes a topic. First, a delete request marks the topic for deletion. Then the controller tells brokers to delete the topic data from disk. Brokers remove the data files and clean up metadata. After that, the controller updates the cluster metadata to remove the topic. Finally, clients receive updated metadata and the topic is fully deleted. The process is not instant but happens step-by-step to ensure safe cleanup. Variables like topic state, broker storage, and cluster metadata change gradually from existing to deleted. Common confusions include why the topic still appears briefly after deletion starts and what happens if clients try to use the topic during deletion. The quizzes test understanding of when data is deleted, cluster metadata state, and failure points in deletion.