Broker Sizing in Kafka: CPU, Memory, Disk and Network
A step-by-step, plain-English guide to choosing the right number and size of Kafka brokers: how to count the bytes, how to leave room for failure, and how to prove your numbers with real measurements.
Every Kafka project reaches the same awkward meeting. Someone asks, “How many servers do we need, and how big should they be?” If you guess too small, your producers slow down, your consumers fall behind, and your pager rings at night. If you guess too big, you pay for machines that sit idle for years, and the finance team asks hard questions.
The good news is that Kafka sizing is not magic. It is arithmetic plus a few well-understood habits of the software. Kafka is mostly a machine for moving bytes from a network card to a disk and back to a network card. Once you know how many bytes per second you expect, how long you keep them, and how many copies you make, you can work out almost everything else.
This guide starts from zero. Each new word is explained the first time it appears, and each big idea comes with an everyday comparison. By the end you will be able to size the disk, memory, processor and network of a Kafka broker, plan for failures, choose between many small servers and a few large ones, and check your plan with a load test.
1Why Sizing Matters and What It Really Means
Before any formulas, let us agree on what we are trying to decide and why a wrong answer is so expensive.
What is a broker?
A broker is one Kafka server. It receives events from software called producers, stores them on disk, and hands them to software called consumers. Several brokers working together form a cluster. When we talk about sizing, we mean answering two questions: how many brokers do we need, and how much processor, memory, disk and network bandwidth should each one have?
Think of a busy post office. Sizing is deciding how many counters to open, how big the storage room is, how many delivery trucks to hire, and how wide the loading dock should be. Too few counters and the queue reaches the street. Too many and you pay staff to watch the wall.
The four resources
A broker uses four main resources, and any one of them can become the bottleneck:
- Disk holds the events. It answers “how much can we keep, and how fast can we write and read it?”
- Memory speeds everything up by keeping recent events close to hand.
- CPU, the processor, does the thinking: handling requests, encrypting traffic, compressing data.
- Network carries bytes in from producers, out to consumers, and between brokers for copying.
What goes wrong when sizing is off
Slow producers
Requests wait in a queue, so applications feel delays or time out when they try to send events.
Lagging consumers
Readers fall behind, dashboards go stale and downstream systems work with old data.
Full disks
A broker whose disk fills up can stop working, and recovering is slow and stressful.
Wasted money
Idle machines cost the same as busy ones, month after month.
Slow recovery
A huge broker that fails takes a very long time to rebuild, because so much data must be copied back.
Fragile cluster
If a machine or a whole data center zone fails, the survivors cannot carry the load.
Sizing is never finished. It is a loop: estimate, build, measure, adjust. This guide gives you the estimating method and the measuring habits to keep the loop honest.
2Kafka in Five Minutes: The Parts That Cost Resources
You do not need to be an expert, but a few ideas explain almost every sizing decision that follows.
Topics, partitions and offsets
A topic is a named stream of events, such as “orders” or “payments”. Each topic is split into partitions, which are separate ordered logs. Partitions let Kafka spread work across many machines. Every event in a partition gets a running number called an offset.
Leaders and followers
Every partition has copies, called replicas. The number of copies is the replication factor, and three is a very common choice. One copy is the leader, and it serves all reads and writes for that partition. The others are followers, which keep themselves up to date by continuously fetching new data from the leader. This copying is the reason the network and disk work is larger than it first appears: every byte a producer sends is written several times.
An append-only log on disk
Kafka stores each partition as a series of files called segments. New events are only added at the end, which is called sequential writing. Reading old data is usually sequential too. Disks are much faster at sequential work than at jumping around, and this is one of the main reasons Kafka is fast.
Leaning on the operating system
Kafka does not build a large private cache of data inside its own program. Instead it relies on the operating system’s page cache, which is the free memory that the operating system uses to keep recently used file data. When a consumer reads events that were written a moment ago, they usually come straight from memory rather than from the disk. This design has a big consequence for sizing: memory that is not given to Kafka’s program is not wasted. It becomes cache that makes Kafka faster.
Zero-copy sending
When a broker sends stored data to a consumer over a plain, unencrypted connection, the operating system can pass the bytes from the page cache to the network card without copying them through the Kafka program. This trick, called zero-copy, saves a large amount of processor work. It matters because it is lost when encryption is switched on, which we will revisit in the CPU chapter.
Imagine a librarian who keeps the most requested books on a cart near the desk instead of walking to the shelves each time. The cart is the page cache. Zero-copy is like handing a book straight from the cart to the reader without first making a photocopy.
| Kafka idea | Where it uses resources |
|---|---|
| Producers sending data | Network in, CPU for requests, disk writes |
| Followers copying data | Network in and out between brokers, more disk writes |
| Consumers reading data | Network out, page cache or disk reads |
| Retention | Disk capacity |
| Encryption and compression | CPU |
| Number of partitions | Memory, open files, leader election work |
3The Four Resources and How They Interact
The four resources are not independent islands. They are stages in one pipeline, and the slowest stage sets the speed of the whole thing.
flowchart LR
P["Producers"] --> N["Network card"]
N --> T["Network threads"]
T --> Q["Request queue"]
Q --> I["I/O threads"]
I --> PC["Page cache in memory"]
PC --> D["Disk"]
PC --> R["Follower brokers"]
PC --> C["Consumers"]
Walking through the pipeline
Data arrives at the network card. A small group of network threads reads the bytes off the connections and turns them into requests. The requests wait in a request queue until one of the I/O threads is free. That thread appends the data to the log, which first lands in the page cache in memory, and the operating system writes it to disk shortly afterward. Meanwhile follower brokers and consumers fetch the same data, mostly from the page cache.
Each box in the picture can be a bottleneck. If the network card is full, data cannot arrive. If the network threads are busy, connections stall. If the I/O threads are busy, the queue grows. If the disk is slow, the page cache fills with data waiting to be written. If memory is short, reads fall through to the disk.
It is like a water pipe with several sections of different widths. Water can only flow as fast as the narrowest section. Widening one section that was never the problem changes nothing.
How the resources trade with each other
- More memory means less disk work. A bigger page cache turns disk reads into memory reads.
- Compression trades CPU for network and disk. Squeezing data costs processor time but saves bytes everywhere else.
- Encryption trades CPU for safety, and it also removes the zero-copy shortcut.
- More copies trade disk and network for safety. A higher replication factor multiplies both.
- More partitions trade memory and overhead for parallelism.
Do not tune one resource in isolation. If you add disks to a broker whose network card is already busy, you have spent money and gained nothing.
4Step Zero: Gather Your Requirements
You cannot size anything without numbers. Before opening a spreadsheet, collect the facts below. Even rough answers are far better than none.
| Question | Why it matters | Example answer |
|---|---|---|
| Peak data rate from producers, in megabytes per second | Drives network, disk write speed and CPU | 60 MB/s |
| Average data rate over a full day | Drives disk capacity | 30 MB/s |
| Average message size and messages per second | Drives request counts and CPU | 1 KB, 60,000 per second at peak |
| Retention: how long data is kept | Drives disk capacity | 7 days |
| Replication factor | Multiplies disk and network | 3 |
| Number of consumer groups reading the full stream | Drives outgoing network traffic | 3 real-time groups |
| Do readers stay near the newest data, or often replay old data? | Drives memory and disk read load | Mostly newest, occasional replay |
| Compression in use and expected ratio | Changes bytes on disk and wire | Producer-side compression, roughly 3 to 1 |
| Encryption in transit required? | Drives CPU | Yes, TLS |
| Availability target: survive a broker? a whole zone? | Drives spare capacity | Survive one full zone out of three |
| Growth over the next year or two | Avoids a rebuild soon after launch | Doubling in 12 months |
| Latency expectations | Decides how much headroom to keep | 99% of writes under 50 ms |
Peak versus average
Two numbers describe traffic, and they answer different questions. The peak rate decides whether your network, CPU and disk speed can cope at the busiest moment. The average rate, multiplied by time, decides how much disk space you consume. Mixing them up is the most common source of wrong estimates: sizing storage from the peak wastes money, and sizing speed from the average causes outages.
Measured bytes versus guessed bytes
If you already run a similar system, measure it. If you are building something new, sample real messages, compress them with your chosen method, and see the true size. Producers using JSON often shrink to a third of their original size or better, while data that is already compressed, such as images, barely shrinks at all.
When some numbers are still unknown
New projects rarely know every figure. That is acceptable, as long as you write down a low, expected and high estimate for each unknown, and size for the expected case while checking that the high case is survivable. Keep a list of who will confirm each estimate and by when. As real measurements arrive, replace the guesses one at a time. A sizing sheet with honest ranges is far more useful than one with falsely precise numbers, because everyone can see which assumptions carry the most risk and deserve early testing.
Write the assumptions at the top of your sizing sheet and keep them visible. When reality differs, you can see immediately which assumption was wrong.
5The Workload Math: Bytes In, Copies, and Fan-Out
Four short formulas turn your requirements into cluster-wide traffic. Everything later in this guide builds on them.
Let us give the numbers names
- W is the producer data rate, in megabytes per second, as stored (after any compression).
- R is the replication factor, the number of copies.
- C is the number of consumer groups that each read the full stream.
The four cluster-wide numbers
Disk write traffic = W × R
Every byte is written once on the leader and once on each follower. At 60 MB/s and three copies, the cluster writes 180 MB/s to disk.
Network in = W × R
The cluster receives W from producers plus W × (R − 1) from replication between brokers. That adds up to 180 MB/s in our example.
Network out = W × (R − 1) + W × C
Leaders send data to followers, and to each consumer group. With three consumer groups, that is 120 plus 180, which is 300 MB/s.
Disk capacity = average W × seconds of retention × R, plus headroom
The average rate, not the peak, decides this. Chapter 6 works it through.
Suppose a newspaper prints one copy of the daily edition, then makes two carbon copies for its archives, and delivers one copy to each of three subscribers. The work grows with copies and with subscribers, not just with the size of the newspaper.
Think in messages as well as megabytes
The same 60 MB/s can arrive as 60,000 messages of one kilobyte, or as 600 messages of one hundred kilobytes. The first case creates far more requests for the broker to process, so it uses more CPU. Always ask for both the bytes per second and the messages per second. Producers that batch, meaning they group many small messages into one request, reduce the request count dramatically.
Spread evenly, then check the spread
Dividing the cluster totals by the number of brokers gives a per-broker figure, but only if the work is spread evenly. In real clusters it rarely is. A topic whose messages all use the same key lands in one partition, and therefore on one leader broker. Add a safety margin for imbalance, and keep an eye on the busiest broker, not just the average one.
A single partition can only be led by one broker at a time. If one partition carries more traffic than any single broker can handle, adding more brokers will not help. You need to spread the load across more partitions or change the key.
6Disk Part One: How Much Space Do You Need?
Disk capacity is often the first resource to run out, and it is the easiest to calculate. Let us do it slowly, one line at a time.
The capacity formula
Total disk space equals the average data rate, multiplied by the number of seconds you keep data, multiplied by the number of copies, then increased to leave free room. Free room matters because a disk that is nearly full is slow, risky and hard to repair.
| Step | Calculation | Result |
|---|---|---|
| Average rate | From requirements | 30 MB/s |
| Data per day | 30 MB/s × 86,400 seconds | 2,592,000 MB, about 2.6 TB |
| Data for 7 days of retention | 2.6 TB × 7 | about 18.1 TB |
| Include three copies | 18.1 TB × 3 | about 54.4 TB |
| Leave 30 percent free | 54.4 TB ÷ 0.70 | about 78 TB |
| Allow for doubling in a year | 78 TB × 2 | about 156 TB |
In this example, the cluster needs around 78 terabytes on day one, and should be able to grow toward 156 terabytes. With nine brokers, that is roughly 8.7 terabytes each today.
It is like planning a warehouse for a bakery that keeps a week of cakes, in triplicate, and never fills the shelves past two thirds so workers can move around. The floor space you need is far more than the cakes themselves.
Why leave so much free space?
- Kafka deletes old data by whole segment files, so usage rises and falls in steps, not smoothly.
- When a broker fails and its partitions are rebuilt elsewhere, the receiving brokers need spare room to hold them.
- Traffic can surge beyond what you predicted, and retention by time then produces more data than planned.
- A very full disk performs worse and leaves no time to react to problems.
Other things that take space
Besides the events themselves, each segment has small index files that help Kafka find data quickly. Topics that use log compaction, which keeps only the latest value for each key, need extra room while the cleaner rewrites files. Temporary copies during partition moves also need space. Add a few percent for these, or simply rely on the generous free-space margin.
Compression changes the answer a lot
If producers compress their batches, the brokers store the batches in compressed form, and your measured data rate W should already reflect that. For text-like data such as JSON, a ratio of three to one is common, and structured logs may do better. For data that is already compressed, expect almost nothing. Always test with real samples, since this single ratio can shift your disk bill by a factor of three or more.
Tiered storage can shrink local disks
Newer Kafka versions support tiered storage, which keeps only recent data on the brokers’ fast local disks and moves older data to cheap object storage while still letting consumers read it. If, in our example, only one day stays local, local capacity falls to about 2.6 TB × 3 ÷ 0.7, which is around 11 TB in total, instead of 78 TB. The trade-off is that reads of old data now travel across the network from object storage, so measure that path if replays are common.
7Disk Part Two: Speed, Storage Types and Layout
Space is only half the story. The disks must also be quick enough to absorb writes and, when the cache misses, serve reads.
How much write speed per broker?
Take the cluster disk write traffic from Chapter 5 and divide by the number of brokers. In our example, 180 MB/s across nine brokers is only 20 MB/s each, which even a modest disk handles. That is typical: for many clusters, capacity is the real constraint and raw speed is easy. Clusters with very high ingest or many catch-up readers are the exceptions.
Reads: mostly cache, sometimes disk
Consumers that keep up read data that is still in the page cache, so the disk sees few reads. But a consumer that starts from the beginning, or one that was offline for hours, reads old data that is no longer in memory. Those reads hit the disk, and if many such consumers run at once, they compete with the writes. Sequential reads are handled well by most disks, but many readers at different positions create a jumpy pattern that punishes slow drives.
Choosing the kind of storage
| Storage type | Rough character | Best for | Watch out for |
|---|---|---|---|
| Spinning hard disks (HDD) | Good at sequential work, weak at random access; on the order of a couple hundred MB/s each | Large, cheap capacity with tail-reading consumers | Slow when many readers replay old data |
| SATA or SAS solid state (SSD) | Much better at random access; several hundred MB/s each | Balanced workloads | Higher cost per terabyte |
| NVMe solid state | Very high throughput and access rates; gigabytes per second possible | Heavy replay, very high ingest, low latency | Cost; the network then often becomes the limit |
| Network-attached block storage in the cloud | Speed limits set per volume and per machine | Flexible, resizable capacity | Machine-level storage bandwidth caps; latency variations |
These numbers are only rough guides, since products change every year. The habit that matters is to check the manufacturer’s or cloud provider’s stated limits and then confirm with your own test.
One big array, or many separate disks?
A broker can be given several storage directories, one per disk, in a layout often called JBOD, which means “just a bunch of disks”. Kafka spreads partitions across those directories. The alternative is to combine disks into a RAID array. RAID 10 (mirrored and striped) gives resilience but halves usable capacity, and Kafka already keeps replicas on other brokers, so many teams find the extra cost unnecessary. RAID 5 and RAID 6 slow down writes and are usually a poor fit. A common practical choice is JBOD or RAID 10, depending on how you want to handle a single disk failure and how much your operations tooling supports.
Many separate disks are like several checkout lanes at a supermarket, each with its own cashier, so work spreads out. A RAID array is like joining the lanes together with rules to protect against a cashier fainting. The protection is useful but not free.
File system and settings
- XFS is widely recommended for Kafka data directories, and ext4 is also used successfully.
- Mount data disks with the option that avoids updating “last accessed” times on every read (
noatime), to cut needless writes. - Never place Kafka data on a shared network file system such as NFS; it is unreliable for this workload.
- Keep the operating system and Kafka’s own log files on a different device from the data, so a full data disk does not make the machine unusable.
Use a disk-speed test tool on a sample machine before you buy a fleet, and record the sustained write speed, not just the burst. Some storage looks fast for a few seconds and then slows down.
8Memory Part One: The Java Heap
Kafka runs inside the Java virtual machine, and the first memory decision is how big to make its private working area, called the heap.
What the heap holds
The heap stores Kafka’s bookkeeping: information about partitions and replicas, buffers for requests in flight, connection state, and the internal structures used to track who has read what. It does not hold your message data for long. The data itself flows through the operating system’s cache. That is why brokers rarely need a huge heap.
A sensible starting point
Many production guides suggest starting with a heap of around six gigabytes for a busy broker, and moving to eight or even twelve only if measurements show pressure. Smaller brokers with modest partition counts can run happily with less. The heap needs grow with the number of partitions, the number of client connections and the size of the requests being handled.
The heap is like the size of the front desk at the post office. It must be big enough for the clerk to hold forms and a phone. Making the desk the size of the whole building would leave no room for the sorting shelves, which are the page cache.
Why not just give Kafka everything?
- It steals from the page cache. Every gigabyte given to the heap is a gigabyte the operating system cannot use to cache your data.
- It lengthens pauses. The Java garbage collector, the tidy-up process that frees unused objects, has more to scan in a big heap. Long pauses make the broker seem frozen, which can cause followers to fall out of sync or clients to time out.
Use a modern collector such as G1, which is designed to keep pauses short, and watch the pause times in your monitoring. If pauses regularly exceed a fraction of a second, look at your partition and connection counts before simply enlarging the heap.
Memory outside the heap
The Java process also uses memory outside the heap for network buffers, file mappings and internal machinery. And the operating system needs some for itself. As a rule of thumb, reserve a few gigabytes for these, in addition to the heap.
Do not allow the machine to use swap space, the disk area that acts as slow overflow memory, for Kafka’s memory. A swapped-out broker pauses in ways that look like failures. Set the operating system to strongly avoid swapping, and size memory so it is never needed.
9Memory Part Two: The Page Cache, Kafka’s Secret Weapon
If Kafka has a superpower, it is this: recently written data is almost always still sitting in memory when consumers ask for it.
sequenceDiagram
participant C as Consumer
participant B as Broker
participant M as Page Cache
participant D as Disk
C->>B: Fetch from an offset
B->>M: Look for the data in memory
alt Data is cached
M-->>B: Return data quickly
else Data is not cached
B->>D: Read from disk
D-->>B: Return data slowly
B->>M: Keep a copy for next time
end
B-->>C: Send the data
How to size the cache
The cache should be large enough to hold the data that consumers are likely to read soon. A common rule of thumb is to have room for at least about thirty seconds of a broker’s incoming data, and more if you have readers that regularly lag by minutes. Remember that a broker caches the data it writes for its follower replicas too, so use the per-broker disk write rate, not just the producer rate.
| Scenario | Per-broker write rate | Time window to cache | Cache needed |
|---|---|---|---|
| Consumers keep up in real time | 20 MB/s | 30 seconds | about 0.6 GB |
| Consumers may lag by 10 minutes | 20 MB/s | 600 seconds | about 12 GB |
| After a zone failure, load rises 1.5 times | 30 MB/s | 600 seconds | about 18 GB |
| Long replays are routine | 20 MB/s | 1,800 seconds | about 36 GB |
Turning it into a machine size
Add the pieces: heap, a few gigabytes for the operating system and off-heap needs, and the page cache you want. For the 10-minute case with a zone failure, that is 6 GB of heap, about 4 GB of other overhead and 18 GB of cache, giving 28 GB. Round up to a 32 GB machine, and choose 64 GB if long replays matter. Because Kafka’s speed depends so much on this cache, memory is often the cheapest upgrade with the biggest effect.
A chef keeps the ingredients for tonight’s menu on the counter and the rest in the walk-in fridge. Counter space is the page cache. If the menu grows but the counter stays the same, the chef keeps walking to the fridge, and dinner slows down.
The danger of cache pollution
When a consumer replays a week of history, it pulls old data into the cache and pushes out the recent data that real-time consumers need. Now the fast readers also start missing the cache, and the disk becomes busy for everyone. This is called cache pollution. There are several defences:
- Buy enough memory that replays do not evict the hot data.
- Set client quotas, so no single reader can flood the broker.
- Run big replays against a separate cluster or a copy of the data.
- Use tiered storage, so old data is served from object storage instead of the brokers’ disks.
Watch the operating system’s read activity on the data disks. If you see steady disk reads while your consumers are supposedly near the head of the log, your cache is too small or something is replaying old data.
10CPU: What Actually Burns Processor Time
Kafka is often described as light on the processor, and that is true until a few specific features change the picture. Knowing where the cycles go helps you avoid nasty surprises.
The main consumers of CPU
Encryption in transit (TLS)
Encrypting and decrypting every byte takes real work, and it also disables the zero-copy shortcut. Brokers that were comfortable without TLS may need much more CPU with it.
Request count
Handling each request has a fixed cost. Many tiny messages sent one by one cost far more than the same bytes sent in large batches.
Compression
Producers and consumers normally do the compressing and decompressing. The broker pays only if it must recompress, for instance when the topic’s setting differs from what the producer used.
Format conversion
When very old clients need data in an older format, the broker converts it on the fly. This is costly and again removes zero-copy.
Authentication
Password-based logins and certificate checks take CPU. A flood of short-lived connections can spike the load.
Cleaning, replication, GC
Compaction threads, follower fetchers and the Java garbage collector all use cycles in the background.
The broker’s thread pools
A broker does its work with groups of threads. Network threads read and write on client connections, and the default is three. I/O threads process requests and touch the disk, and the default is eight. Separate replica fetcher threads copy data from leaders, one by default per source broker. Background threads clean and delete logs. If the request queue fills because all I/O threads are busy, latency rises. You can increase the thread counts, but they only help if there are enough physical cores to run them.
Threads are like clerks at counters. Adding counters helps only if you also hire enough people to staff them. Otherwise, the extra counters sit empty and the queue still stretches out the door.
How to choose a core count
There is no honest universal formula, because so much depends on message size, TLS and compression. The dependable method is to benchmark one broker on the hardware you plan to buy, using realistic messages, the real security settings and the real compression. Find out how much traffic it can carry while the request handler threads still have spare time. Then plan to run at roughly half of that at your peak. Many production brokers use somewhere between eight and thirty-two cores, but let your own test decide.
| Illustrative benchmark step | Example result |
|---|---|
| One 8-core broker, TLS on, 1 KB messages, batched | Handles about 80 MB/s before request threads run out of idle time |
| Target utilization at peak, allowing for failure | About 50 percent |
| Planning figure per broker | About 40 MB/s |
| Brokers needed for CPU at 60 MB/s producer rate with 3 copies | Total broker work of 180 MB/s divided by 40 gives about 5 brokers |
These numbers are illustrative, not promises. Their purpose is to show the method: measure, apply a safety factor, and divide.
Always benchmark with encryption switched on if you will use it in production. A test without TLS can badly understate your CPU needs.
11Network Part One: Counting the Bytes
The network is where beginners most often undercount, because replication and fan-out multiply traffic in ways that are easy to forget.
Bytes versus bits
Storage and data rates in this guide use bytes, while network cards are sold in bits. One byte is eight bits, so multiply megabytes per second by eight to get megabits per second. A 10 gigabit card can theoretically carry about 1,250 megabytes per second. In practice, plan to use a comfortable fraction of that, since protocol overhead, encryption and bursts all take a share.
Per-broker traffic in our example
From Chapter 5, the cluster receives 180 MB/s and sends 300 MB/s at peak. Spread across nine brokers, that gives each broker about 20 MB/s incoming and about 33 MB/s outgoing.
| Measure | Per broker, normal | In megabits | Per broker after losing one zone (×1.5) |
|---|---|---|---|
| Incoming | 20 MB/s | 160 Mbps | 30 MB/s, 240 Mbps |
| Outgoing | 33 MB/s | 267 Mbps | 50 MB/s, 400 Mbps |
Even after a zone failure, the busiest direction uses well under half a gigabit. A 10 gigabit card is generous here, and even a 1 gigabit card would cope. In this example the network is not the limiting resource. That is a useful finding, not an accident: it tells you where not to spend money.
When fan-out changes everything
Now imagine the same 60 MB/s topic is read by ten consumer groups instead of three: analytics, search, alerts, machine learning and several more. Outgoing traffic becomes 120 for replication plus 600 for consumers, which is 720 MB/s across the cluster, or 80 MB/s per broker. That is 640 megabits per second per broker, which would already strain a 1 gigabit card and would leave little room for failure.
A magazine with three subscribers is easy to mail. The same magazine with ten thousand subscribers needs a much bigger loading dock, even though the magazine itself has not changed.
Keep a margin
- Add a margin of ten to twenty percent for protocol overhead and encryption.
- Plan the busiest broker, not the average, since load is never perfectly even.
- Include the extra traffic from rebuilding a failed broker, unless you throttle it.
- Include monitoring, log shipping and backup traffic that shares the same network card.
12Network Part Two: Network Cards, Zones and Cost
Getting the bandwidth number right is one job. Understanding where the traffic travels, and what it costs, is another.
flowchart LR
P["Producer"] -->|"1 copy in"| L["Leader broker"]
L -->|"2 copies out for replication"| F["Two follower brokers"]
L -->|"1 copy per consumer group"| G["Consumer groups"]
Reading the picture
One byte arrives from a producer. The leader sends it on to two followers, so two more copies cross the network. Then it sends one copy to each consumer group that reads the topic. With three consumer groups, one incoming byte causes five outgoing bytes from the leader. Sizing the outgoing side is therefore the bigger job for most clusters.
Availability zones and the cost of crossing them
Production clusters usually spread brokers across three availability zones, which are separate data center buildings within one region, so a fire or power failure in one does not stop the others. That is excellent for safety, but many cloud providers charge for data that moves between zones, typically per gigabyte. With three copies in three zones, every byte a producer sends causes two cross-zone copies for replication. Producers and consumers that talk to a leader in another zone add more.
Think of three warehouses in three cities. Sending a copy of every shipment to the other two warehouses is safe, but the courier charges for each trip between cities. Delivering to customers who live in the same city as the warehouse costs nothing extra.
Ways to reduce cross-zone traffic
- Rack awareness. Tell each broker which zone it lives in, so Kafka places replicas in different zones. This is essential for safety, though it does create the replication cost above.
- Fetching from the closest replica. A feature added in Kafka 2.4 lets a consumer read from a follower in its own zone instead of the leader in another. Consumers declare their zone, and brokers are configured with a replica selector. This can remove a large share of consumer cross-zone traffic, at the price of slightly higher delay, since followers trail the leader a little.
- Compression. Fewer bytes cross the boundary, on every hop.
- Fewer full-stream consumer groups. Share one consumer that feeds several destinations, when this is practical.
Check the machine’s true network limit
Cloud machines often advertise network speed as “up to” a number. That top speed may be a short burst, with a lower baseline that you can sustain. A Kafka broker that runs hot for hours lives at the baseline. Also note that if the disks are network-attached volumes, the traffic to them may be counted against a separate storage bandwidth limit of the machine, so check both figures in the provider’s documentation.
Do not size the network from the burst number in the product name. Read the documented baseline, and confirm it with a long test lasting an hour or more.
13Partitions and Their Hidden Costs
Partitions are how Kafka spreads work, but each one has a price. Too few limit your speed; too many drain your brokers.
How many partitions does a topic need?
A well-known rule links partitions to the speed you need. First measure two numbers on your hardware: how fast a single partition can accept data from producers (call it p), and how fast a single consumer can process one partition (call it c). If your target rate is t, you need at least t ÷ p partitions for writing and t ÷ c partitions for reading. Use the larger answer. For example, if the target is 60 MB/s, one partition takes 10 MB/s from producers, and one consumer processes 5 MB/s, you need at least 6 partitions to write and 12 to read, so choose 12 or more. Because you cannot reduce partitions later, and adding them changes where keyed messages land, leave room for growth; 24 would be a reasonable choice.
Partitions are like checkout lanes. One lane can only serve so many shoppers per hour, so a busy store opens several. But a store with a hundred lanes and three cashiers is wasteful, and each open lane needs a till, a light and floor space.
What each partition costs a broker
Open file handles
Every segment of every partition has data and index files. Multiply partitions by segments by files per segment and you can reach tens of thousands quickly.
Mapped index files
Index files are mapped into memory. The operating system limits how many mappings a process may hold, and a busy broker can hit that limit.
Bookkeeping
Each replica adds state to the heap and adds buffers in follower fetchers.
Failover work
When a broker dies, leadership of each of its partitions must move. More partitions mean longer unavailability for some of them.
Smaller batches
Spreading a fixed data rate across more partitions makes batches smaller, which raises request counts and CPU.
Replication overhead
More partitions to replicate can add delay before writes are confirmed.
Practical limits
Widely quoted guidance from Kafka experts is to keep each broker to a few thousand partition replicas, and clusters to a couple of hundred thousand in total on older setups that use ZooKeeper. Newer clusters using the built-in KRaft controller handle much larger counts, but the per-broker costs above still apply. Treat these numbers as starting points and always test with your own topics.
| Setting to raise | Why | Sensible direction |
|---|---|---|
| Open files limit for the Kafka user | Many segment and index files | Set well above 100,000 |
| Maximum memory mappings | Index files are mapped | Raise vm.max_map_count above the default |
| Swappiness | Avoid paging out Kafka | Set very low, close to zero or one |
Balance matters
All brokers should lead about the same number of partitions and hold about the same amount of data. Uneven clusters have one hot broker that limits everyone. Tools such as Cruise Control, an open-source rebalancer originally built at LinkedIn, can watch the load and move partitions to even it out. Balance is worth checking often, since a size plan assumes an even spread.
14Sizing for Failure: Headroom and Recovery
A cluster that runs perfectly when everything is healthy is only half designed. The other half is what happens on the worst day.
flowchart LR
subgraph AZ1["Zone 1"]
B1["Broker 1"]
B2["Broker 2"]
B3["Broker 3"]
end
subgraph AZ2["Zone 2"]
B4["Broker 4"]
B5["Broker 5"]
B6["Broker 6"]
end
subgraph AZ3["Zone 3 fails"]
B7["Broker 7"]
B8["Broker 8"]
B9["Broker 9"]
end
AZ3 -.-> AZ1
AZ3 -.-> AZ2
The arithmetic of losing something
With nine brokers, losing one broker leaves eight to carry the load, which raises each survivor’s share by nine eighths, or 12.5 percent. Losing a whole zone of three leaves six, which raises each survivor’s share by nine sixths, or fifty percent. The fewer brokers you have, the harder a single loss hits. Two brokers that lose one survive on half the capacity; nine brokers that lose one lose only a ninth.
| Cluster size | Load per survivor after losing one broker | Load per survivor after losing one of three zones |
|---|---|---|
| 3 brokers | ×1.5 | ×3 (only one broker left) |
| 6 brokers | ×1.2 | ×1.5 |
| 9 brokers | ×1.125 | ×1.5 |
| 12 brokers | ×1.09 | ×1.5 |
Setting the target utilization
Decide the highest load you are willing to run at after the failure, perhaps seventy or eighty percent of a broker’s tested capacity, and work backwards. If the failure multiplier is 1.5 and the post-failure ceiling is 75 percent, normal peak load should stay at or below 50 percent. This is why the earlier chapters kept talking about running at about half of tested capacity.
Safety settings that keep the cluster writable
With three copies spread over three zones, a common safe setup asks producers to wait for all in-sync replicas (acks=all) and requires at least two replicas to be in sync (min.insync.replicas=2). Losing one zone still leaves two replicas, so writes continue and no confirmed data is lost. Losing two zones stops writes, which is the correct, safe behavior.
How long does recovery take?
When a broker is replaced with an empty disk, all of its data must be copied back from other brokers. Suppose each of our brokers holds about 8.7 terabytes. If you throttle the copying to 100 MB/s to protect normal traffic, the copy takes about 87,000 seconds, which is roughly 24 hours. During that time, the cluster has fewer safe copies than normal. Faster copying finishes sooner but competes with clients.
If a warehouse burns down, refilling it from the other two takes time proportional to how much it held. A warehouse that held twice as much needs twice as long to restock, during which the company has fewer backups.
- Smaller disks per broker mean faster recovery, but more brokers to manage.
- Reattaching a surviving data volume to a replacement machine, where the platform allows it, can skip most of the copying.
- Set the copy speed limit deliberately with replication quotas, and rehearse the procedure before you need it.
Keep the number of brokers a multiple of the number of zones so that each zone holds an equal share. Uneven zones lead to uneven failure behavior.
15Putting It All Together: A Full Worked Example
Now we combine every earlier chapter into one decision. The method is simple: calculate a broker count for each resource, take the largest, then adjust for zones and failure.
flowchart TD
R["Requirements"] --> W["Workload math"]
W --> D["Disk answer"]
W --> N["Network answer"]
W --> C["CPU answer"]
W --> M["Memory answer"]
D --> X["Take the largest count"]
N --> X
C --> X
M --> X
X --> F["Add failure headroom and round to a multiple of zones"]
The requirements
Peak producer rate 60 MB/s, average 30 MB/s, messages of about 1 KB, seven days of retention, three copies, three real-time consumer groups, TLS on, three availability zones, and doubling of traffic expected within a year.
One answer per resource
| Resource | How we calculated | Brokers needed |
|---|---|---|
| Disk capacity | 78 TB total, and we choose about 12 TB usable per broker, so 78 ÷ 12 is 6.5 | 7 |
| Disk speed | 180 MB/s writes; even a few brokers manage this | 2 or 3 |
| Network | 300 MB/s out at peak; a 10 gigabit card handles about 60 percent of 1,250 MB/s, so 750 MB/s per broker | 1 or 2 |
| CPU | Benchmark planning figure 40 MB/s of broker work; 180 ÷ 40 | 5 |
| Memory | Per broker 32 GB to 64 GB; does not change the count | Not limiting |
Adjusting for reality
Take the largest
Disk capacity gives seven brokers, the highest of all the resource answers.
Round to a multiple of three zones
Seven becomes nine, so each zone holds three brokers.
Check the failure case
With one zone lost, each of six survivors carries 1.5 times the work. Per-broker work rises from 20 to 30 MB/s, which is within the 40 MB/s planning figure.
Check growth
Doubling traffic means disk capacity of 156 TB. Plan to add brokers or larger disks during the year, or use tiered storage.
Choose the machine
Around 8 to 16 cores, 64 GB of memory for a generous page cache, roughly 12 TB of disk, and a 10 gigabit network card.
Validate
Build a test cluster, run realistic load with TLS, kill a zone, and compare the measurements with this plan.
Notice that the real constraint here was disk capacity, not speed. If you had started by shopping for the fastest processors and network, you would have paid for capability you would never use.
16Which Resource Dominates? Common Workload Profiles
In our worked example, disk capacity decided the size. For other workloads a different resource takes the lead. Recognizing your profile early tells you where to look first.
Log and metrics collection
Huge ingest, one or two readers, long retention. The bill is driven by terabytes and disk write speed. Compression pays off enormously here.
Company-wide event bus
Moderate ingest but many teams reading the same streams. Outgoing bandwidth and connection counts dominate, and fetch-from-follower helps.
Stream processing with replays
Applications that rebuild state by re-reading history stress the page cache and disk reads. Extra memory or tiered storage helps most.
Secure transactional systems
Small messages, TLS everywhere, strict latency goals. Processor time and headroom dominate; the data volume is modest.
Device telemetry
Vast numbers of small messages from vast numbers of connections. Request handling, connection state and the heap are the limits.
Change data capture with compaction
Compacted topics keep the latest record per key, so the cleaner threads rewrite files in the background, using extra disk and processor time.
| Profile | Look first at | Cheap win |
|---|---|---|
| Log collection | Disk capacity and write speed | Stronger compression, shorter retention, tiered storage |
| Event bus | Network out and connections | Fetch from closest replica, fewer duplicate readers |
| Replay-heavy streaming | Page cache and disk reads | More memory, or a separate replay path |
| Secure, latency-sensitive | CPU headroom | Larger batches, more cores, tested TLS settings |
| Telemetry | Requests per second and heap | Client-side batching, connection reuse |
| Compaction heavy | Disk churn and cleaner CPU | Tune cleaner threads, add free space |
A truck stop, a hospital and a bakery all need electricity, water and a parking lot. But the truck stop worries most about the parking lot, the hospital about electricity and the bakery about water. Same resources, different priorities.
17Scale Up or Scale Out? Fewer Big Brokers or Many Small Ones
Once you know the total resources you need, you can build them from a few large machines or from many small ones. Both work, and each has costs.
Fewer, larger brokers
- Less to manage, monitor and patch.
- Fewer network connections between brokers.
- Larger page cache per machine.
- Often lower cost per unit of capacity.
Drawbacks of large brokers
- A failure removes a big slice of capacity at once.
- Rebuilding a large disk takes many hours.
- Many partitions per broker strain files, memory and failover.
- Harder to keep balanced when only a handful exist.
Many, smaller brokers
- A single failure hurts less, and recovery is faster.
- Load spreads thinly, so hot spots have less effect.
- Easier to grow in small steps.
- Work is naturally spread across zones.
Drawbacks of small brokers
- More machines to operate and secure.
- More replication and metadata traffic overall.
- Smaller caches, so replays hurt sooner.
- More total partition replicas to track for the controller.
A practical middle path
Most teams settle on a moderate number of mid-sized brokers, often between six and thirty for a single cluster, in a multiple of their zone count. Beyond that, it is often wiser to run a second cluster for a separate set of applications than to keep growing one giant cluster. This limits the blast radius, meaning how many applications a single problem can hurt.
Choose the disk size per broker by asking “how long could I stand to wait for a rebuild?” A twelve-terabyte broker copied at 100 MB/s takes over 33 hours. If that is too long, reduce disk per broker and add brokers.
18Sizing in the Cloud and on Managed Kafka
In the cloud you rent machines by the hour, so sizing becomes a menu of instance types and storage options. The same method applies; only the building blocks change. Details below are general, and cloud limits change often, so check the provider’s current documentation.
Matching instance families to profiles
| Family type | Character | Fits |
|---|---|---|
| General purpose | Balanced processor and memory | Most clusters as a starting point |
| Memory optimized | More memory per core | Replay-heavy or cache-hungry workloads |
| Storage optimized with local NVMe | Very fast disks attached to the machine | High ingest and heavy reads; data disappears if the machine is stopped or replaced, so replication is your only safety net and rebuilds copy everything |
| Compute optimized | More cores per gigabyte | TLS-heavy or request-heavy workloads |
| Arm-based processors | Often good value for the price | Worth benchmarking against the alternatives |
Network-attached disks
Most clusters use network-attached block volumes because they can be resized and can survive a machine replacement. Their speed is set per volume, for example a general-purpose SSD volume type offers a baseline throughput that you can raise up to a documented maximum. In addition, each instance has its own cap on how much storage traffic it can carry in total. So the achievable speed is the smaller of the volume limit and the instance limit. Throughput-oriented hard disk volumes are cheaper for large, mostly sequential workloads, but are slower for replays.
It is like a pipe connecting a water tank to a house. A huge tank does not help if the pipe is thin, and a wide pipe does not help if the tank outlet is small. The flow is set by the narrowest part.
Managed Kafka services
Services such as Amazon MSK let you pick broker instance sizes and storage per broker while the provider handles machine replacement, patching and much of the monitoring. You still do the sizing: how many brokers, which size, how much storage, how many partitions. Managed offerings have their own documented limits for storage per broker, throughput per broker and partitions per broker, and some can grow storage automatically. Some also absorb the cost of replication traffic between zones. Read the current limits and pricing pages before you finalize a plan, since they change.
Cost levers to remember
- Storage is often the largest line item, so compression, retention and tiered storage matter greatly.
- Cross-zone transfer can quietly rival the machine cost for high-throughput clusters.
- Commitments such as reserved capacity lower the hourly price once your size has stabilized.
- Right-sizing later is easier in the cloud than on purchased hardware, so start with a measured plan and adjust.
Cloud volumes and instances often have burst credits that make a short test look wonderful. Run your load test long enough for the credits to run out, then look at the sustained numbers.
19Sizing the Neighbors: Controllers, Connect and Friends
Brokers rarely live alone. Several other components share the platform, and each has its own needs. Giving them the wrong home can undo careful broker sizing.
Cluster controllers
The controllers manage cluster metadata: which broker leads which partition, topic settings and access rules. Modern Kafka runs them with its own consensus system called KRaft. Production clusters usually use three, or five for higher safety, dedicated controller nodes. They need modest processors and memory, a small but reliable fast disk for the metadata log and a dependable network. Running controllers and brokers on the same machines is fine for small or test clusters, but a busy broker can then slow down cluster management just when you need it most.
Kafka Connect workers
Connect moves data between Kafka and other systems. Its workers do real processing such as converting formats and applying small transformations, which can use a lot of processor time and memory. Run them on their own machines, not on the brokers, and size them by the number of connector tasks and the volume they handle.
Schema registry and other helpers
A schema registry stores the formats of your messages. It is light on resources but must be highly available, since producers and consumers consult it. Run at least two instances and give them a small, fast disk or rely on Kafka itself for storage as designed.
Stream processing applications
Programs built with Kafka Streams or similar tools keep local state on their own disks and use their own memory. They are clients from the broker’s point of view but add load: every restart may replay a lot of data. Include them when you count consumer groups and when you think about cache pollution.
Keep brokers dedicated
Do not run databases, batch jobs or web servers on broker machines. They compete for cache, disk and network in unpredictable ways.
Spread helpers over zones
Controllers, registries and workers should survive a zone failure just like the brokers.
Count their bandwidth
Connect and mirroring tools can read the whole stream. They are consumers in your network math.
Size them separately
Their needs grow with the number of connectors, not with the number of brokers.
Operating system settings that support your sizing
- Raise the open-file limit and the memory-mapping limit, as described in Chapter 13.
- Keep swapping essentially off.
- Use a modern file system on data disks with access-time updates disabled.
- Keep the clocks synchronized, since replication and logs rely on time.
- Set network buffer sizes suitable for high-bandwidth links, especially between zones or regions.
20Proving Your Numbers: Load Tests and Metrics
A sizing plan is a prediction. Testing is how you find out whether the prediction was right, before your users do.
How to run a good test
Build a like-for-like cluster
Same machine type, same disks, same number of zones, same security and compression settings as production.
Use realistic messages
Sample real sizes and shapes. Synthetic messages that compress unrealistically well give misleading results.
Generate load with proven tools
Kafka ships with producer and consumer performance test tools, and an open-source benchmarking framework called OpenMessaging Benchmark is also popular.
Test the steady peak for hours
Short tests hide cache warm-up, disk credit exhaustion and garbage collection patterns.
Test the bad days
Double the traffic for a while, start a consumer from the beginning, stop a broker, then stop a whole zone, and perform a rolling restart under load.
Compare with the plan
Where reality and the spreadsheet disagree, find out why, and fix the assumption rather than shrugging.
The dashboard that tells you if sizing is right
| Signal | What it tells you | Worry when |
|---|---|---|
| Request handler idle percentage | How much spare time the I/O threads have | It drops toward 20 or 30 percent at peak |
| Network processor idle percentage | Spare time of network threads | It drops toward 30 percent |
| Bytes in and bytes out per broker | Actual traffic against the network card limit | Sustained use above about 60 percent of the card |
| Produce and fetch request latency (99th percentile) | What clients feel | It grows steadily or breaks your target |
| Under-replicated partitions | Followers falling behind | Anything above zero for a sustained time |
| Disk usage and disk busy time | Space left and disk saturation | Usage above about 70 percent or disks near fully busy |
| Operating system read activity on data disks | Page cache misses | Steady reads while consumers are current |
| Garbage collection pause time | Health of the heap | Pauses regularly beyond a fraction of a second |
| Consumer lag | Whether readers keep up | It rises without recovering |
| Leader and partition count per broker | Balance | One broker carries far more than the others |
Load testing is a fire drill for your cluster. You would rather discover that the exit is blocked during practice than during the real fire.
Save the test results and the dashboards as a baseline. Six months later, when someone asks whether the cluster needs to grow, you can compare today’s numbers with a known good starting point.
21Client Settings That Change Broker Load
Brokers do not decide alone how hard they work. The programs that talk to them make choices that can double or halve the load. Sizing goes better when you influence those choices early.
Batching: the single biggest lever
A producer can wait a few milliseconds to gather many messages before sending them together. Two settings control this: how long to wait (linger.ms) and how large a batch may grow (batch.size). Bigger batches mean fewer requests, better compression and less CPU on the broker. The cost is a small added delay for each message. For most data pipelines, waiting five to twenty milliseconds is invisible to users and saves a large amount of broker work.
A courier who drives to the depot for every single parcel wastes fuel and time. A courier who waits ten minutes to collect a full van makes far fewer trips, and customers barely notice the wait.
Choosing a compression method
| Method | Shrinks data | CPU cost on clients | Typical use |
|---|---|---|---|
| None | Not at all | None | Data that is already compressed |
| LZ4 | Moderately | Very low | Speed-sensitive pipelines |
| Snappy | Moderately | Low | A long-standing balanced choice |
| Zstandard | Strongly | Moderate | Saving disk and network at scale |
| Gzip | Strongly | High | Rarely the best choice for busy systems |
Ask the client teams to compress, and ask them to keep the topic’s own compression setting at “producer”, which means the broker stores batches exactly as they arrive. If the topic demands a different method, the broker must decompress and recompress every batch, and that uses processor time you did not plan for.
Acknowledgements and safety
Producers choose how many confirmations to wait for. Waiting for all in-sync replicas is the safest and adds a little latency. It does not add much extra work for the broker, but it does mean producers hold requests open longer, so account for that in connection and buffer sizing.
How consumers ask for data
Consumers fetch data in requests too. If a consumer asks for data with no minimum size and no waiting time, and the topic is quiet, it can send thousands of empty requests per second. Setting a sensible minimum amount of data (fetch.min.bytes) and a maximum wait (fetch.max.wait.ms) lets the broker hold the request until there is something worth sending. This lowers request counts and CPU for idle or slow topics.
Connections
Every client connection uses memory and file handles on the broker. Thousands of applications that each open connections to every broker add up. Encourage long-lived connections instead of opening and closing them constantly, since each new secure connection costs a handshake that burns CPU.
Batch and compress
Use modest waiting time, larger batches and a light compression method.
Fetch in bulk
Set minimum fetch sizes and reasonable waits so idle topics stay quiet.
Reuse connections
Create clients once and keep them, rather than creating one per request.
Set quotas
Cap the bandwidth and request rate of each client so one bug cannot swamp the cluster.
Publish a short “good client settings” page for every team that uses your cluster. It is far cheaper to prevent a thousand tiny-batch producers than to buy brokers to survive them.
22A Second Worked Example: Heavy Fan-Out, Short Retention
To see how a different profile changes the answer, let us size a cluster where many teams read the same modest stream and nobody keeps data for long.
The requirements
Peak producer rate 25 MB/s and an average of 15 MB/s. Three copies, three days of retention, twelve consumer groups each reading the full stream, TLS on, and three availability zones.
The workload math
| Quantity | Calculation | Result |
|---|---|---|
| Cluster disk writes and network in | 25 × 3 | 75 MB/s |
| Cluster network out | replication 25 × 2 = 50, plus consumers 25 × 12 = 300 | 350 MB/s |
| Combined in plus out | 75 + 350 | 425 MB/s |
| Disk capacity | 15 MB/s × 86,400 s × 3 days × 3 copies ÷ 0.7 | about 17 TB |
One answer per resource
- Disk capacity: at about 8 TB usable per broker, 17 TB needs three brokers.
- Disk speed: 75 MB/s of writes is trivial.
- Network: with six brokers, each sends about 58 MB/s, roughly 467 megabits per second. A one gigabit card at 60 percent (75 MB/s) fails the zone-loss test, so choose a ten gigabit card.
- CPU: suppose benchmarks show one broker can handle about 100 MB/s of combined incoming and outgoing traffic with TLS at a comfortable load. Then 425 divided by 100 needs at least five brokers.
flowchart LR
D["Disk: 3 brokers"] --> X["Largest is CPU at 5"]
N["Network: 2 brokers on 10 Gbps"] --> X
C["CPU: 5 brokers"] --> X
X --> Z["Round up to a multiple of 3 zones: 6"]
Z --> F["Failure check with 6 brokers"]
F --> R["Zone loss gives 106 MB/s per broker, above the 100 target"]
R --> S["Choose 9 brokers: 71 MB/s after zone loss"]
The failure check changes the answer
With six brokers, normal load is 425 ÷ 6, about 71 MB/s each. Losing one zone leaves four brokers, each carrying 425 ÷ 4, about 106 MB/s, which is above our comfortable 100 MB/s. So six is not enough. With nine brokers, normal load is about 47 MB/s each, and after losing a zone six survivors carry about 71 MB/s each, which is comfortable. The alternative is six larger brokers with more cores, which could also work if benchmarks prove it.
Compare a small newsstand and a huge library. The newsstand stores few papers but hands out thousands of copies a day, so it needs more counter staff than shelves. The library stores millions of books and lends few, so it needs shelves more than staff. The first example was a library; this one is a newsstand.
What else can lower the cost?
- Fetch from the closest replica to cut cross-zone charges for the twelve readers.
- Ask whether several consumer groups could share one reader that feeds them, reducing full-stream copies.
- Use light compression so each byte to twelve readers is smaller.
- Check memory: at 75 MB/s of cluster writes across nine brokers, each writes about 8 MB/s, so ten minutes of cache is only about 5 GB, and 32 GB machines are plenty.
23Growth and Capacity Planning Over Time
The day you launch is the easiest day of a cluster’s life. Traffic grows, new teams arrive, and retention requests creep upward. Good sizing includes a plan for the next two years.
Forecast the three curves
- Data rate: ask product teams about launches, campaigns and new regions, then add a buffer.
- Consumer fan-out: every new team that reads a stream adds outgoing traffic.
- Retention and partitions: requests for “just keep it longer” and “just add partitions” quietly consume disk and overhead.
Decide your triggers in advance
| Signal | Trigger to start growing | Why start early |
|---|---|---|
| Disk usage | Around 60 to 70 percent of usable space | Buying and rebalancing takes weeks, and rebuilds need free room |
| Request handler idle time | Trending toward 40 percent at peak | Failure headroom is disappearing |
| Network card use | Around 50 percent at peak | A zone loss would push it past the limit |
| Partitions per broker | Approaching your tested limit | Failover time and file counts rise |
Adding brokers is not the end of the job
Here is a fact that surprises many newcomers: when you add a broker to a running cluster, Kafka does not automatically move existing partitions onto it. The new machine sits nearly empty until you run a partition reassignment, which copies chosen partitions over to it. That copying uses network and disk on the old brokers, so apply a speed limit and do it during a quieter period. Tools such as Cruise Control can plan and execute balanced moves for you.
Hiring a new clerk does not shorten the queue until someone actually sends customers to that clerk’s window. Reassignment is the act of pointing customers to the new window.
Review the sizing sheet every quarter with the actual numbers from monitoring. Two minutes of comparing predicted and observed traffic saves months of surprise.
24Real-World Examples
Here is how the ideas above show up in real organizations. Some describe publicly known systems, and others are illustrative scenarios that show how a typical team would apply the same reasoning.
LinkedIn: where Kafka began, and where scale forced tooling
Kafka was created at LinkedIn to carry activity and operational data, and the company has publicly reported volumes measured in trillions of messages per day. At that scale, keeping thousands of brokers balanced by hand was impossible, which led to the open-source Cruise Control rebalancer. The lesson: at large scale, balance and automation matter as much as raw machine size.
Netflix: a large streaming data pipeline built on Kafka
Netflix has publicly described its Keystone data pipeline, which moves very large numbers of events per day and uses Kafka as its backbone. Its engineers have talked about running separate clusters for different purposes and about designing for the loss of an entire cloud zone. The lesson: separate clusters limit the blast radius, and zone failure is a normal design case.
Uber: many regions and heavy fan-out
Uber has described Kafka as the backbone for a wide range of real-time systems across data centers, including tooling to copy data between clusters. With many consumers reading each stream and replication between regions, outgoing network traffic and cross-cluster bandwidth become central concerns. The lesson: fan-out multiplies network needs long before storage becomes the issue.
Managed-service guidance: published sizing recommendations
Both Confluent and Amazon publish sizing guidance for Kafka, and their advice repeats the themes of this guide: plan for peak throughput, account for replication and fan-out, leave storage headroom, avoid running near full disks, and test. The lesson: even vendors who run Kafka for a living tell you to measure your own workload.
Illustrative scenario: a retailer before a big sale
An online shop runs comfortably at 10 MB/s for most of the year, but its sale day produces ten times that for six hours. The team sizes network, CPU and disk speed for the sale-day peak, but sizes disk capacity from the yearly average plus the sale spike. Two weeks before the sale they run a load test at double the expected peak and discover that TLS raises CPU far more than forecast, so they add cores. The lesson: sizing to the average would have failed on the one day that mattered.
Illustrative scenario: a device fleet with millions of small messages
A company collects readings from a million small devices, each sending a tiny message every few seconds. The data rate is small in megabytes but the request rate is huge, so brokers run out of request-handling time and heap long before disk or network. Grouping readings into larger batches at gateways cuts the request count tenfold. The lesson: for tiny messages, count requests per second, not only bytes.
25Design Patterns and Anti-Patterns
Patterns are proven habits, and anti-patterns are traps that many teams fall into. Knowing both shortens the path to a stable cluster.
Patterns worth adopting
Measure, then size
Benchmark one broker on real data and real security settings, then scale the result by arithmetic.
Size for the failure case
Choose the post-failure ceiling first, then work backwards to normal utilization.
Brokers in multiples of zones
Equal shares in every zone keep failure behavior predictable.
Dedicated broker machines
Nothing else competes for cache, disk or network on a broker.
Tiered storage for long retention
Keep recent data local and old data in cheap object storage.
Client quotas
Cap what any one application can send or read so neighbors are protected.
Separate replay path
Run heavy history reads on a copy or a separate cluster so live readers keep their cache.
Automated balancing
Use a rebalancer to keep partitions and traffic even after growth and failures.
Anti-patterns to avoid
What it looks like
Sizing speed from the daily average instead of the busiest moment, or sizing disk from the peak.
Why it hurts
Average-based speed plans fail during bursts. Peak-based disk plans waste large sums.
Do this instead
Use the peak for network, CPU and disk speed, and the average for capacity.
What it looks like
Giving the Java heap most of the machine’s memory “to be safe”.
Why it hurts
The page cache shrinks, so reads go to disk, and long garbage collection pauses make brokers look dead.
Do this instead
Keep the heap modest and leave the rest to the operating system’s cache.
What it looks like
Running data disks at ninety percent full because “there is still room”.
Why it hurts
Rebuilds and surges have nowhere to go, and a full disk can take a broker offline.
Do this instead
Alert at sixty to seventy percent and grow before you must.
What it looks like
Counting only producer traffic when checking the network, ignoring replication and consumer fan-out.
Why it hurts
The real traffic is several times larger, so network cards saturate unexpectedly.
Do this instead
Use the formulas in Chapter 5 and include every consumer group.
What it looks like
Load testing without encryption, with tiny test data or for only a few minutes.
Why it hurts
Test results look wonderful, then production needs far more CPU, and cloud burst credits run out.
Do this instead
Test with production settings and realistic messages, for hours.
26Best Practices and Common Mistakes
Here is a sensible order for doing this work, followed by the mistakes that trip up most teams.
A sizing routine you can follow
Write down the requirements
Peak and average rates, message size, retention, copies, consumer groups, security, failure goals and growth.
Do the workload math
Compute cluster disk writes, network in, network out and capacity.
Calculate a broker count per resource
Disk, network, CPU and memory each give an answer; the largest wins.
Add failure headroom
Check the one-broker and one-zone cases against your post-failure ceiling.
Choose partitions carefully
Derive them from per-partition throughput, then leave room to grow.
Pick the machines
Cores, memory for the cache, disks with the right speed and size, and a network card with enough sustained bandwidth.
Test
Long steady runs, bursts, replays and failures, all with production settings.
Set triggers and review often
Alerts on the signals from Chapter 20 and a quarterly capacity review.
The most common mistakes
- Forgetting the copies. Replication multiplies disk writes and network traffic.
- Ignoring consumer fan-out. Every additional group reading the full stream adds outgoing bytes.
- Trusting burst numbers. Sustained network and disk speeds are lower than advertised peaks.
- Skipping failure math. A cluster with no headroom becomes an outage when one machine fails.
- Over-partitioning. More partitions are not free and cannot be removed later.
- Mixing workloads on broker machines. Neighbors steal cache, disk and network.
- Tuning without measuring. Changes made by guess often move the bottleneck rather than remove it.
- Never revisiting the plan. Traffic grows, and yesterday’s right answer becomes today’s risk.
A short self-check
- Do we know our peak and average rates, and did we use each in the right place?
- Could we survive losing a full zone without running above our ceiling?
- Do we know how long a broker rebuild would take?
- When did we last test with encryption on, at length, with realistic data?
- Which alerts tell us to grow, and what will we do when they fire?
27Frequently Asked Questions
Quick answers to the questions that come up most often when teams size Kafka for the first time.
28Summary and Key Takeaways
Broker sizing turns a vague worry into a repeatable calculation. Four resources, a handful of formulas and a habit of testing will take you a long way.
Key Takeaways
- Count every byte: disk writes and incoming network are the producer rate times the number of copies, and outgoing network adds every consumer group.
- Use peak and average correctly: the peak sizes speed, the average sizes capacity, and free space of thirty percent or more keeps you safe.
- Memory is mostly cache: keep the heap modest, and give the rest to the page cache that makes Kafka fast.
- CPU depends on features: encryption, request counts and format conversion matter more than raw data volume, so benchmark with production settings.
- Size for the bad day: plan for a lost broker and a lost zone, run at about half of tested capacity, and use a broker count that is a multiple of your zones.
- Watch partitions and balance: they cost files, memory and failover time, and a single partition can only use one broker at a time.
- Test, monitor, review: prove the plan with long realistic tests, watch idle thread time, lag and disk use, and revisit the sizing every quarter.