Partition Strategy

The partition strategy determines how to write data to Kafka partitions. You can use a partition strategy to balance the work load or to write data semantically.

The Kafka Producer provides the following partition strategies:
Round-Robin
Writes each record to a different partition using a cyclical order. Use for load balancing.
Random
Writes each record to a different partition using a random order. Use for load balancing.
Expression
Writes each record to a partition based on the results of the partition expression. Use to perform semantic partitioning.
When you configure the partition expression, define the expression to evaluate to the partition where you want each record written. The expression must return a numeric value.
For example, the following expression writes records to two partitions based on the value in the Age field:
${record:value('/Age') < 21 ? 0 : 1}
The following example writes to three partitions based on the value of the Age field:
${record:value('/a') < 21 ? 0 : record:value('/a') < 55 ? 1 : 2}
Default
Writes each record using the default partition strategy that Kafka provides.
When you use the default partition strategy, you configure a partition expression that returns the partition key from the records, such as ${record:value('/partitionkey')}. The expression must return a string value.

The Kafka Producer writes each record to a partition based on a hash of the partition key.