Kafka Hardware Considerations
Kafka Setup Hardware Considerations๐
Disk Throughput๐
SSD's are used if there are lot of client connections.
Disk Capacity๐
Memory๐
๐น 1. JVM Heap Basics๐
- Kafka brokers run on the Java Virtual Machine (JVM).
- The JVM provides a heap = the memory area where Java objects live (data structures, buffers, metadata, etc.).
- The heap is managed by the Garbage Collector (GC), which automatically frees unused objects.
๐น 2. What goes into Kafkaโs Heap๐
Even though Kafka is an I/O-heavy system (most data lives on disk or page cache), it still needs the heap for several critical tasks:
-
Message Buffers
-
Temporary storage for messages being read from producers before written to disk.
-
Buffers used when serving fetch requests to consumers.
-
Metadata
-
Cluster metadata: topics, partitions, offsets, leader/follower info.
-
Zookeeper/KRaft state in memory.
-
Indexes and Caches
-
Offset index and time index objects.
-
In-memory caches like the
ReplicaFetcher
buffer, producer state maps, etc. -
Control Structures
-
Java objects representing network connections, requests, and responses.
-
Threads, queues, locks, and other concurrency structures.
-
ZooKeeper/KRaft client state
-
If Kafka is using ZooKeeper (older versions), ZooKeeper client connections use heap.
- In KRaft (newer versions), metadata quorum state also lives in heap.
๐น 3. What does not live in Heap๐
- Actual log data (the big message payloads) is written to disk (segment files).
- Kafka relies heavily on the OS page cache to serve log reads/writes efficiently.
- So the heap is not where Kafka keeps gigabytes of topic data โ itโs more for metadata and transient objects.
๐น 4. JVM Heap + GC Issues in Kafka๐
- If heap is too small โ OutOfMemoryError (OOM).
- If heap is too big โ GC pauses get long (stop-the-world events).
-
Thatโs why Kafka best practice is:
-
Keep heap moderate (e.g., 4โ8 GB for brokers, even if broker has 64โ128 GB RAM).
- Let the OS page cache handle log segment data.
- Use G1 GC (Garbage First) for predictable pause times.
๐น 5. Analogy๐
-
Think of Kafka like a library:
-
The heap is the librarianโs desk (indexes, notes, active tasks).
- The page cache + disk is the massive archive of books (actual topic data).
- The librarianโs desk must be tidy and efficient (GC keeps it clean), but the heavy lifting (book storage) happens outside the desk.
โ In short: In Kafka, the JVM heap holds metadata, temporary buffers, and control structures, but not the bulk of the log data. That bulk lives in disk files + OS page cache. The JVM heapโs job is to make sure Kafka can efficiently manage metadata, requests, and temporary data, while avoiding GC stalls.
Networking๐
We should have atleast 10Gb NICs and older 1Gb NICs is not sufficient.