Skip to content
BENIBIX Learn

Kafka Producer

Also known as Producer (Kafka), Kafka Producer Client

A program that writes events into Kafka. It does not know who reads them.

Think of it like

It is like a person posting letters through a mail slot. They drop them in and walk on.

Example

A shop's checkout is a producer. Each order goes to the orders topic. The key is the customer ID, so each customer's orders stay in order.

Why it matters

The producer picks the key, and the key decides the order. A careless key can scramble events that must stay in line.

Definition

A Kafka producer is a program that writes events to a Kafka topic. It sends each event to a broker, often with a key. Events with the same key go to the same partition, so they stay in order. The producer waits for the broker to confirm each write. By default it waits until every in-sync copy has the event. It does not know or care who reads the events later.

Example code

console
$ bin/kafka-console-producer.sh --topic orders --bootstrap-server localhost:9092
> order 1001 placed
> order 1002 placed
Each line typed after the prompt becomes one event in the orders topic.
The producer is on the left. It writes each event into one of the three partitions.

Common mistake

Sending with no key when order matters. The events then spread across partitions and lose their order.

Key takeaways

  1. 1
    Key picks the partition. Same key, same partition.
  2. 2
    Waits for a yes. Brokers confirm each write.
  3. 3
    Knows no readers. Writers and readers stay apart.