Bird
0
0

Given this Kafka Streams code snippet, what is the output if a failure occurs before commit?

medium📝 Predict Output Q13 of 15
Kafka - Advanced Stream Processing
Given this Kafka Streams code snippet, what is the output if a failure occurs before commit?
streams.start();
try {
  streams.process(record);
  streams.commitTransaction();
} catch (Exception e) {
  streams.abortTransaction();
}
AProcessed record is committed multiple times.
BProcessed record may be duplicated after restart.
CProcessed record is committed exactly once.
DProcessed record is lost and not committed.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze transaction handling

    If an exception occurs before commit, abortTransaction() is called, rolling back changes.
  2. Step 2: Determine output effect

    Rollback means the processed record is not committed and effectively lost in this run.
  3. Final Answer:

    Processed record is lost and not committed. -> Option D
  4. Quick Check:

    Abort transaction = no commit = lost record [OK]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes