# Kafka Producer

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

**Field:** Data Engineering  
**Category:** Ingestion & Streaming  
**Also known as:** Producer (Kafka), Kafka Producer Client

## Think of it like

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

## 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

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.

## 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.

## 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.

## Common mistake

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

## Three principles

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

## Related terms

- [Apache Kafka](https://learn.benibix.com/term/data/apache-kafka)
- [Kafka Topic](https://learn.benibix.com/term/data/kafka-topic)
- [Kafka Partition](https://learn.benibix.com/term/data/kafka-partition)
- [Kafka Consumer](https://learn.benibix.com/term/data/kafka-consumer)
- [Kafka Broker](https://learn.benibix.com/term/data/kafka-broker)
- [Message Ordering](https://learn.benibix.com/term/data/message-ordering)

![A producer writes events into a topic with three partitions, each an ordered list of numbered events. Two consumers in one group each read their own partitions, and each keeps its place with an offset.](https://learn.benibix.com/diagrams/kafka-topic-partitions.svg)

---

Source: https://learn.benibix.com/term/data/kafka-producer
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
