The short answer
Here is a fresher-friendly produce path:
Step by step
- 1Create producer with
bootstrap.servers, serializers, acks, etc. - 2Send a
ProducerRecord(topic, optional key, value, optional headers/). - 3Producer serializes key/value (e.g. String, Avro, ).
- 4Partitioner chooses a partition:
- If partition set explicitly → use it
- Else if key present → hash(key) % numPartitions
- Else → sticky / round-robin style distribution
- 1Producer may batch records for that partition (linger + batch size).
- 2Send batch to the leader broker for that partition.
- 3Leader appends to its log and replicates per
ackspolicy. - 4Broker returns success/failure; producer callbacks / futures complete.
- 5On success (depending on acks), the record has an assigned offset.
App → serialize → choose partition → batch → network
→ leader broker → (replicas if acks=all) → ack to producerTiny mental example
ProducerRecord(topic="orders", key="cust-9", value="{...}")
→ partition 2 (hash of cust-9)
→ leader of partition 2 on broker-3
→ offset 184422 assignedCommon producer settings to mention
acksretries/ delivery timeoutlinger.msandbatch.sizeenable.idempotence- compression (
snappy,lz4,zstd)
Interview tip: Narrate key → partition → leader → ack. That shows you understand the path, not just the API.