Topics & Partitions
TL;DR
Kafka topics are divided into partitions — the unit of parallelism and ordering. More partitions = more parallelism; partition key determines which partition a record lands in.
Explanation
Topic: a named stream of records. Partition: an ordered, immutable log. Records appended with offset. Multiple partitions per topic: parallel reads/writes. Partition assignment: by key hash (same key → same partition → ordering), round-robin (no key → load balanced → no ordering), custom partitioner. Replication: each partition has one leader and N-1 followers. Leader handles reads/writes; followers replicate. Partition count: set at creation (can increase, never decrease). More partitions → more parallelism → more overhead (file handles, memory). Typical: 3-12 partitions for throughput, 1 for strict ordering.
Common Misconception
✗ More partitions is always better — each partition has overhead (file handle, memory, rebalancing cost). Start with 3-6 and increase if needed.
Why It Matters
Partition count determines maximum parallelism — it's the most important Kafka sizing decision and can't easily be reduced after creation.
Common Mistakes
- Too many partitions for the workload — overhead without benefit.
- Changing partition count without updating consumers — key routing changes.
- No replication in production — single partition leader = single point of failure.
Code Examples
✗ Vulnerable
# 1 partition — no parallelism:
kafka-topics --create --topic orders --partitions 1 --replication-factor 1
# 1000 partitions — unnecessary overhead
✓ Fixed
# Balanced: 6 partitions, 3 replicas:
kafka-topics --create --topic orders --partitions 6 --replication-factor 3
# PHP producer with partition key:
$conf->set('partitioner', 'consistent_random'); // Same key = same partition
$producer->produce(RD_KAFKA_PARTITION_UA, 0, $payload, $orderId); // Key = orderId
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
23 Mar 2026
Views
47
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 14
Perplexity 12
Unknown AI 4
Ahrefs 3
Google 3
ChatGPT 2
Meta AI 2
SEMrush 1
Also referenced
How they use it
crawler 38
pre-tracking 3
Related categories
⚡
DEV INTEL
Tools & Severity
🔵 Info
⚙ Fix effort: Medium
⚡ Quick Fix
Start with 3-6 partitions per topic. Set replication-factor=3 for production. Use entity ID as partition key for ordering. Monitor partition lag per consumer group.
📦 Applies To
cli
queue-worker
🔗 Prerequisites
🔍 Detection Hints
partitions|partition_key
Auto-detectable:
✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: Medium
Context: File