How to see the size of a Kafka topic in bytes
Codemia Knowledge Hub ·
A Kafka topic's size is the disk space used by its partition logs, so you get it by summing partition sizes. The quickest way is kafka-log-dirs.sh --describe, which reports the size of each partition on every broker; for code, use the AdminClient describeLogDirs API.
How Kafka stores topic data
Topics are split into partitions for scalability and fault tolerance. Each partition is an ordered, immutable sequence of records that is continually appended to (a commit log), and those records are stored in a set of segment files on disk. The topic size therefore depends on what retention or log compaction leaves in those segments.
Using kafka-log-dirs.sh
kafka-log-dirs.sh ships with Kafka and describes the log directories on brokers. To check the size of a topic's partitions across all brokers, run:
Replace localhost:9092 with your broker address and my-topic with your topic name. The output lists the size of each partition on every broker; add them up to get the topic total.
Using the AdminClient API in Java
To fetch sizes from code, use AdminClient:
Here my-topic is the topic name. The code prints the size of each partition of that topic.
Related metrics to monitor
| Metric | Description | Relevance |
| Topic Size | Total size of the topic across all partitions. | Useful for monitoring the disk space utilization. |
| Partition Count | Number of partitions in the topic. | Important for load balancing and parallelism. |
| Replication Factor | Number of replicas per partition. | Critical for fault tolerance and durability. |
| Broker Storage Utilization | Percentage of storage used in each broker. | Prevents brokers from getting overwhelmed. |
What changes a topic's size
- Retention policies: retention settings control how long data is kept, and therefore how big the topic gets. Make sure they fit your storage capacity.
- Compaction: with log compaction, older records are replaced by the latest value for each key. This can shrink a topic a lot when it has frequent updates but few unique keys.
- Performance: large topics can slow rebalances and recoveries, so keeping size in check helps performance.
Related reading
- Seeing partition doesn't exist warnings/failures after kafka using kafka partition re-assignment tool
- Select an element from a stream with uniform distributed probability
- Send bulk of messages Kafka Producer
- Send byte array to storm kafka bolt
- Send email from Elmah?
- Sending information to a ngnix from php on the same server without http
- Send Custom Java Objects to Kafka Topic
- Send KafkaProducer from local machine to hortonworks sandbox on virtualbox
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.