← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Topics & Partitions

messaging Intermediate

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

Added 23 Mar 2026
Views 47
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 4 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 2 pings S 0 pings S 2 pings M 0 pings T 0 pings W 0 pings T
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
crawler 38 pre-tracking 3
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

✓ schema.org compliant