B. Processed record may be duplicated after restart.
C. Processed record is committed exactly once.
D. Processed record is lost and not committed.
Solution
Step 1: Analyze transaction handling
If an exception occurs before commit, abortTransaction() is called, rolling back changes.
Step 2: Determine output effect
Rollback means the processed record is not committed and effectively lost in this run.
Final Answer:
Processed record is lost and not committed. -> Option D
Quick Check:
Abort transaction = no commit = lost record [OK]
Hint: Abort transaction means no commit, so data is lost [OK]
Common Mistakes:
Assuming record is committed despite failure
Thinking abortTransaction duplicates records
Confusing commitTransaction with abortTransaction
4. Identify the error in this Kafka Streams code snippet for exactly-once processing:
props.put("enable.idempotence", "true");
props.put("transactional.id", "txn-1");
KafkaProducer producer = new KafkaProducer(props);
producer.beginTransaction();
producer.send(record);
// Missing commit or abort here
producer.close();
medium
A. Missing commitTransaction or abortTransaction before close.
B. enable.idempotence should be false for transactions.
C. transactional.id must be unique per message.
D. KafkaProducer cannot be closed after sending messages.
Solution
Step 1: Review transaction lifecycle
After beginTransaction and send, a commit or abort must finalize the transaction.
Step 2: Identify missing step
The code closes producer without committing or aborting, causing incomplete transaction.
Final Answer:
Missing commitTransaction or abortTransaction before close. -> Option A
Quick Check:
Transactions need commit or abort before close [OK]
Hint: Always commit or abort before closing producer [OK]
Common Mistakes:
Thinking idempotence false is needed for transactions
Believing transactional.id changes per message
Assuming producer close auto-commits transactions
5. You want to build a Kafka Streams application that updates user balances exactly once, even if failures occur. Which approach ensures this behavior?
hard
A. Process messages without committing offsets to avoid duplicates.
B. Disable transactions and rely on at-least-once processing with retries.
C. Use idempotent producer with transactions and commit offsets atomically.
D. Use multiple producers without transactions to increase throughput.
Solution
Step 1: Understand exactly-once requirements
Exactly-once needs atomic commit of data and offsets to avoid duplicates or loss.
Step 2: Match approach to requirements
Using idempotent producer with transactions and atomic offset commits ensures exactly-once updates.
Final Answer:
Use idempotent producer with transactions and commit offsets atomically. -> Option C