The partition key determines which partition receives each message.
Key-based partitioning:
Messages with same key go to same partition. Order guaranteed for same key. Use user ID or order ID as key.
Round-robin (null key):
Messages distributed evenly across partitions. No ordering guarantee. Maximum throughput distribution.
Custom partitioner:
Implement your own logic. Example: VIP customers to dedicated partition.
Warning: Changing partition count breaks key-to-partition mapping.