BackendBench
Coffee
Spot the Bug #123

A producer that never learns of failure

A medium Java puzzle in the messaging and kafka mistakes family. One line below contains a real bug. Try to spot it first, then read why it fails and how to fix it.

mediumMessaging and Kafka mistakesbuggy line: 8

Highlighted: line 8. Play this one as a puzzle without the answer.

What is wrong

With acks=0 the producer does not wait for any acknowledgement, so a leader failure or a network error loses messages and the send callback reports success. For business events that is silent data loss.

The fix

props.put("acks", "all"); props.put("enable.idempotence", "true");

How to avoid it next time

Use acks=all with idempotence for important data, and always handle the send callback or future.

Want the background? Read Kafka producer in the Java concepts library.

About messaging and kafka mistakes

Message handling combines retries, offsets and transactions, and the order of those steps decides whether a failure loses data or processes it twice.

In code review: Trace what happens if the process dies after each line. Commit an offset only after the work is done, and make handlers idempotent.

More puzzles in this family

🐞 Play today's puzzleAll 132 bugs← #122#124 →

Frequently asked questions

What is the bug in "A producer that never learns of failure"?

With acks=0 the producer does not wait for any acknowledgement, so a leader failure or a network error loses messages and the send callback reports success. For business events that is silent data loss. The faulty line is line 8: props.put("acks", "0");

How do I fix it?

Replace it with: props.put("acks", "all"); props.put("enable.idempotence", "true");. Use acks=all with idempotence for important data, and always handle the send callback or future.

How do I catch messaging and kafka mistakes in code review?

Trace what happens if the process dies after each line. Commit an offset only after the work is done, and make handlers idempotent.

Is there a new puzzle every day?

Yes. The daily Spot the Bug puzzle picks one of these snippets for each UTC day, with the difficulty set by the weekday. Your streak is stored only in your browser.

More tools you might need