تقسیم کی حکمت عملی کا انتخاب — کہ واقعات کسی موضوع کی تقسیموں میں کیسے تقسیم ہوتے ہیں — Kafka کے ڈیزائن کا ایک اہم فیصلہ ہے جو ترتیب، متوازی کاری، اور بوجھ کی تقسیم کو متاثر کرتا ہے۔ partition key اور count کو احتیاط سے منتخب کیا جانا چاہیے۔
تقسیم کیسے کام کرتی ہے
A producer's message goes to a partition based on:
→ with a KEY → hash(key) → determines the partition (same key → same partition consistently)
→ no key → distributed (round-robin / sticky) across partitions
→ the KEY choice determines ordering and distribution
Partition key کا انتخاب
The KEY determines two crucial things:
✓ ORDERING → all events with the same key go to the same partition → ordered together
(e.g. key=userId → all of a user's events are ordered)
✓ DISTRIBUTION → keys should spread evenly across partitions (good cardinality) → balanced load
PITFALLS:
✗ LOW cardinality / skewed keys → HOT partitions (one partition overloaded) → bottleneck
✗ Wrong ordering scope → if you need per-X ordering, key by X (but that limits parallelism
within X)
→ choose a key giving the ORDERING you need AND EVEN distribution
