3. Kafka Producers: Writing Messages to Kafka
3. Kafka Producers: Writing Messages to Kafka
Chapter 3 of Kafka: The Definitive Guide — 16 sections.
Source: Kafka: The Definitive Guide, 2nd Ed., Ch. 3 Learning goal: the producer API is ~10 lines. Everything that matters is (a) what happens on the internal threads, and (b) how ~15 configs interact to define durability, ordering, latency, and throughput. Most production Kafka bugs are producer misconfigurations.
Sections
- 3.01The motivating example (keep this in your head)A credit-card transaction processing system:
- 3.11How does it work internally? Producer architecture
- 3.2Constructing a producerBuilt in: ByteArraySerializer ("which doesn't do much"), StringSerializer, IntegerSerializer, and much more.
- 3.32The three ways to sendEverything that goes wrong at or after the broker is invisible.
- 3.42Configuring producers — every important knobA logical identifier for the client and the application it's used in.
- 3.53Message delivery time — the timeout configs and how they interactHow long the producer may block when calling send() and when explicitly requesting metadata via partitionsFor().
- 3.62⚠️ ORDERING GUARANTEES — the reordering bug
- 3.71Remaining configsControls the size of a produce request. It caps both:
- 3.82SerializersThat last point is the organizational killer — the same lockstep-deploy problem Ch. 1 identified, now embedded in your byte layout.
- 3.94PartitionsThat's a genuine, deliberate availability-for-consistency trade.
- 3.10HeadersThat last clause is the compelling one: headers let an intermediary route/trace data it is not authorized to read.
- 3.11InterceptorsProducerInterceptor has two key methods:
- 3.122Quotas and throttlingVia kafka-config.sh or the AdminClient API:
- 3.13Failure catalogWhat actually breaks in production — Ch. 3 consolidated
- 3.143Deploy / monitor / scale — the producer's operational surfaceThere is no producer-side backup, but there is a producer-side durability boundary, and knowing where it sits is what matters:
- 3.15Self-testSelf-test