The Silent Cost Multiplier: How Consumer-to-Partition Imbalance Inflates Your MSK Broker CPU and Blocks Downsizing
How a misconfigured Kafka consumer group can generate thousands of idle TCP connections, inflate CPU by ~40%, and make broker downsizing impossible — plus a step-by-step guide to detect and fix it.
You've done the math. Your Amazon MSK cluster's
BytesInPerSec and BytesOutPerSec are well within capacity. The right-sizing formula says you should be fine on smaller brokers. So you downsize from kafka.m5.2xlarge to kafka.m5.large — and within minutes, CPU idle drops to 3%, brokers start throwing NodeNotReadyError , and you're scrambling to revert.What went wrong? Your throughput was fine. Your storage was fine. But you had 7,000 TCP connections that shouldn't have existed.
This post explains a pattern that standard MSK sizing guidance doesn't cover: consumer-to-partition imbalance as a hidden CPU multiplier. I'll walk through how to detect it, quantify the impact, and safely fix it — based on a real engagement that delivered $74K in annualized savings across a multi-region MSK deployment.
The Setup: High CPU, Low Throughput
Here's the scenario. A production event streaming platform running on Amazon MSK:
- 3 regions, 12 brokers per cluster (
kafka.m5.2xlarge)
- Processing ~230K authentication events/month at peak
- Topics configured with 10 partitions, replication factor 3,
min.insync.replicas=2
- CPU utilization sitting at ~40% — way higher than expected for the throughput
The egress metrics suggested massive headroom. The operations team tried downsizing to save costs. It caused a production incident. They reverted and accepted the "unexplained" CPU as a fact of life.
It wasn't.
Why the Standard Sizing Formula Misses This
max(t_cluster) <= min{ max(t_storage) * #brokers / r, max(t_EBSnetwork) * #brokers / r, max(t_EC2network) * #brokers / (#consumer_groups + r - 1)}This formula models consumer groups as a driver of EC2 network egress. But it assumes each consumer group has a reasonable number of consumers — ideally matching the partition count.
What it doesn't model: the CPU overhead of maintaining thousands of idle TCP connections from consumers that are group members but never receive a partition assignment because there are more consumers than partitions.
The Root Cause: Over-Subscribed Consumer Groups
Quick Kafka Refresher
In Apache Kafka, a consumer group cooperatively consumes from a topic. The partition assignment protocol ensures:
- Each partition is assigned to exactly one consumer within a group
- If
consumers > partitions, the excess consumers sit idle
- Idle consumers still maintain active TCP connections to brokers
- Idle consumers still send heartbeats and participate in group coordination
What We Found
$ kafka-consumer-groups.sh --bootstrap-server $BROKERS --describe --group event-processor --members
GROUP MEMBERS ASSIGNMENTevent-processor 53 10 partitions assigned, 43 idle53 consumers competing for 10 partitions. Only 10 ever do any work. The other 43 maintain TCP connections, send heartbeats every 3 seconds, and participate in every rebalance — for zero processing value.
Across multiple consumer groups, this added up to ~7,000 idle TCP connections cluster-wide.
The Math on CPU Impact
Each idle connection costs the broker:
- Heartbeat processing: 7,000 connections × 1 heartbeat/3s = ~2,333 network events/second the broker processes continuously
- Metadata refreshes: periodic
metadata.max.age.msrequests (default 5 min)
- Socket buffer management: kernel-level CPU for maintaining open connections
- Group coordination: JoinGroup/SyncGroup during rebalances (all 53 members participate)
At scale, this created ~40% CPU usage with almost no message throughput. And it's invisible to standard capacity planning because
BytesInPerSec / BytesOutPerSec don't reflect connection overhead.Why Downsizing Fails Without Fixing This
The operations team's initial approach was logical:
"CPU is 40% on m5.2xlarge but throughput is low → we're over-provisioned → downsize to m5.large"
The result:
Metric | Before (m5.2xlarge) | After (m5.large) |
|---|---|---|
CPU Idle | 60–70% | 3–10% |
Errors | None | NodeNotReadyError , LeaderNotAvailableError |
Outcome | Stable | Production incident → revert |
The smaller instance couldn't handle the connection management overhead. The CPU wasn't processing messages — it was managing connections. Downsizing without fixing the root cause is like trying to lose weight by eating less while running a fever — you're treating the wrong variable.
The Fix: Consumer-to-Partition Alignment
The number of consumers in a consumer group should not exceed the number of partitions in the topic being consumed.
But knowing the best practice and operationalizing it across a multi-region production deployment are different things. Here's the phased approach that worked:
Phase 1: Validate in Non-Production (4 weeks)
Reduced consumer count per group from 53 → 10 (matching partition count) in the test environment.
Monitored:
-
ActiveConnectionCount→ dropped ~80%
-
CpuUser→ reduced 15–20%
- Consumer lag → unchanged
- Message latency → unchanged
The 43 idle consumers contributed zero value to message processing. Removing them changed nothing except CPU.
Phase 2: Production Rollout (5 months)
Gradually right-sized consumer groups across production clusters, monitoring for regressions at each step.
Result: Zero customer-facing impact. Zero message loss.
Phase 3: Broker Downsizing (After validation)
With idle connections eliminated and CPU headroom confirmed:
Action | Savings |
|---|---|
Broker removal across 3 regions | $74,000/year |
Additional broker removal (in progress) | ~$86,000/year |
Total | ~$160,000/year |
The sequence matters: fix root cause → validate CPU reduction → then downsize. Skipping to step 3 is what caused the initial production incident.
How to Detect This in Your Environment
Step 1: Check Your Connection-to-Throughput Ratio
aws cloudwatch get-metric-statistics \ --namespace "AWS/Kafka" \ --metric-name "ActiveConnectionCount" \ --dimensions Name=Cluster\ Name,Value=YOUR_CLUSTER \ --start-time $(date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%S) \ --end-time $(date -u +%Y-%m-%dT%H:%M:%S) \ --period 300 \ --statistics AverageRed flag: If
ActiveConnectionCount is 5–10x higher than (#partitions × #consumer_groups × 2) , you likely have idle consumer overhead.Step 2: Audit Consumer Group Membership
# List all consumer groupskafka-consumer-groups.sh --bootstrap-server $BROKERS --list
# For each group, check member count vs. assigned partitionskafka-consumer-groups.sh --bootstrap-server $BROKERS \ --describe --group $GROUP --membersRed flag: Any group where
MEMBERS > MAX(partition_count across subscribed topics) .Step 3: Quantify the Waste
For each over-subscribed group:
idle_consumers = members - partition_countwasted_connections = idle_consumers × broker_countestimated_heartbeat_overhead = wasted_connections / heartbeat_interval_ms × 1000If
wasted_connections is in the thousands, you've found your phantom CPU consumer.Step 4: Compare Against Expected CPU
Use the MSK sizing spreadsheet to calculate expected CPU for your throughput. If observed CPU significantly exceeds what your throughput should generate, connection overhead is the likely culprit.
Decision Framework
Signal | What It Means | Action |
|---|---|---|
High CPU + Low BytesOutPerSec | CPU is spent on connections, not messages | Audit consumer group sizes |
ActiveConnectionCount > 5x expected | Over-subscribed groups exist | Right-size consumers to partitions |
Downsizing fails despite low throughput | Connection bottleneck on smaller instance | Fix consumers first, then downsize |
Frequent consumer group rebalances | Over-subscription amplifies rebalance cost | Reduce to partition count |
CPU spikes during deployments | Too many consumers joining/leaving groups | Review deployment consumer count |
Common Causes of Consumer Over-Subscription
- Kubernetes autoscaling without Kafka awareness — HPA scales pods (each running a consumer) based on CPU or memory, oblivious to partition count
- Microservice proliferation — each service instance runs its own consumer, and the service was scaled for HTTP request capacity, not Kafka partition count
- Legacy configurations — consumer count was set for a topic that once had 50 partitions, which was later consolidated to 10
- Copy-paste deployments — a consumer group config was copied from a high-partition topic to a low-partition topic without adjustment
Key Takeaways
- Standard MSK sizing formulas assume well-configured consumers. If your consumer groups are over-subscribed, the formulas will underestimate CPU requirements — making your cluster appear oversized when it's actually overloaded by connections.
- High CPU + low throughput ≠ "needs a bigger instance." Before scaling up (or failing to scale down), check
ActiveConnectionCountagainst expected.
- Consumer-to-partition alignment is a cost lever, not just a best practice. Idle consumers cost nothing in message processing but can cost thousands in inflated infrastructure.
- Fix the root cause before downsizing. The correct sequence is always: eliminate idle connections → validate CPU reduction → then downsize.
- Phased rollout is non-negotiable for production Kafka. Validate in non-production first, monitor for 4+ weeks, then make infrastructure changes.
Related Resources
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article