Skip to main content

Question 9 of 50

What is a Producer?

Mid-levelSenior

Question

"What is a Producer in Kafka, and what does it need to decide when publishing a message?"

What the interviewer wants to assess

Basic architecture knowledge — usually a warm-up question before moving on to deeper topics like key choice and delivery guarantees.

Resposta rápida

A Producer is the application that publishes events to a Kafka topic. When sending a message, it decides which topic to send to, which key to use (which determines the destination partition), and how to serialize the value — usually JSON, Avro, or Protobuf. The producer doesn't know, and doesn't need to know, who will consume that event.

Resposta nível Sênior

A Producer is any application — typically a microservice — that publishes a business fact as an event to a topic. Three decisions fall to the producer on every send: the destination topic, the message's key (which determines which partition it's stored in, and therefore its ordering relative to other messages with the same key), and the value's serialization format. In Spring Boot, this translates into a call to KafkaTemplate.send(topic, key, value). One point that's often missed: the producer also decides (via configuration) the delivery guarantee level it wants — acks=0, 1, or all — a latency-versus-durability trade-off that comes back in Chapter 10, on delivery guarantees.

In-depth explanation

See "Producer" in Chapter 3. For the key decision, see Chapter 4 on partitions and ordering.

Exemplo financeiro

The card authorization service, when approving a purchase, acts as a producer by publishing the CompraAutorizada event to the compras.autorizadas topic, using cartaoId as the key — ensuring all purchases on the same card land on the same partition, in order.

"The producer knows which consumers will process the message"

No — that's exactly Kafka's decoupling point. The producer publishes to the topic with no knowledge of how many Consumer Groups exist or what each one does with the event.

Pode vir a seguir

Expect: "can a producer be a microservice?" (next question) and "what happens if the producer doesn't specify a key?".

Related chapters