Bird
Raised Fist0
Kafkadevops~20 mins

Exactly-once stream processing in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Exactly-Once Kafka Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Exactly-Once Semantics in Kafka

Which Kafka feature ensures that messages are processed exactly once in a stream processing application?

AKafka Transactions
BKafka Consumer Groups
CKafka Partitions
DKafka Replication
Attempts:
2 left
💡 Hint

Think about what mechanism allows atomic writes and commits in Kafka.

💻 Command Output
intermediate
1:30remaining
Kafka Producer Transaction Initialization Output

What is the expected output when a Kafka producer successfully initializes transactions?

Kafka
producer.initTransactions();
System.out.println("Transactions initialized");
ATransactions initialized
BException: Transactions not supported
CNo output
DError: Producer not configured
Attempts:
2 left
💡 Hint

Consider what happens when the initTransactions method completes without error.

🔀 Workflow
advanced
2:00remaining
Correct Order of Steps for Exactly-Once Processing in Kafka Streams

Arrange the following steps in the correct order to achieve exactly-once processing in a Kafka Streams application.

A1,3,2,4
B2,1,3,4
C1,2,3,4
D2,3,1,4
Attempts:
2 left
💡 Hint

Think about starting the transaction before processing and committing after sending output.

❓ Troubleshoot
advanced
2:00remaining
Identifying the Cause of Duplicate Messages in Exactly-Once Kafka Streams

A Kafka Streams application configured for exactly-once processing is producing duplicate output messages. What is the most likely cause?

AThe producer is not using transactions
BThe application is using at-least-once processing mode
CThe input topic has multiple partitions
DThe consumer group ID is not set
Attempts:
2 left
💡 Hint

Consider the processing guarantee mode configured in the application.

✅ Best Practice
expert
2:30remaining
Best Practice for Configuring Kafka Producer for Exactly-Once Semantics

Which configuration is essential to enable exactly-once semantics in a Kafka producer?

Alinger.ms=1000 and max.in.flight.requests.per.connection=5
Backs=0 and retries=0
Ccompression.type=none and batch.size=0
Denable.idempotence=true and transaction.id set
Attempts:
2 left
💡 Hint

Think about settings that prevent duplicate sends and enable transactions.

Practice

(1/5)
1. What is the main benefit of exactly-once stream processing in Kafka?
easy
A. It ensures messages are processed only once, avoiding duplicates.
B. It speeds up message delivery by skipping acknowledgments.
C. It allows messages to be processed multiple times for safety.
D. It disables message ordering to improve throughput.

Solution

  1. Step 1: Understand exactly-once processing goal

    Exactly-once processing means each message affects the system only once, preventing duplicates.
  2. Step 2: Compare options with this goal

    Only It ensures messages are processed only once, avoiding duplicates. describes avoiding duplicates by processing messages once.
  3. Final Answer:

    It ensures messages are processed only once, avoiding duplicates. -> Option A
  4. Quick Check:

    Exactly-once = no duplicates [OK]
Hint: Exactly-once means no duplicate effects on data [OK]
Common Mistakes:
  • Confusing exactly-once with at-least-once processing
  • Thinking it speeds up delivery by skipping steps
  • Assuming it allows multiple processing for safety
2. Which Kafka producer configuration enables exactly-once semantics?
easy
A. compression.type = none
B. enable.idempotence = true
C. acks = 0
D. max.in.flight.requests.per.connection = 10

Solution

  1. Step 1: Identify config for exactly-once

    Enabling idempotence ensures the producer can retry without duplicates.
  2. Step 2: Match config options

    Only 'enable.idempotence = true' enables this feature.
  3. Final Answer:

    enable.idempotence = true -> Option B
  4. Quick Check:

    Idempotence enabled = exactly-once [OK]
Hint: Idempotence true enables exactly-once in Kafka producer [OK]
Common Mistakes:
  • Choosing acks=0 which disables acknowledgments
  • Confusing compression with processing guarantees
  • Setting max.in.flight.requests without idempotence
3. 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();
}
medium
A. Processed record is committed multiple times.
B. Processed record may be duplicated after restart.
C. Processed record is committed exactly once.
D. Processed record is lost and not committed.

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

  1. Step 1: Review transaction lifecycle

    After beginTransaction and send, a commit or abort must finalize the transaction.
  2. Step 2: Identify missing step

    The code closes producer without committing or aborting, causing incomplete transaction.
  3. Final Answer:

    Missing commitTransaction or abortTransaction before close. -> Option A
  4. 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

  1. Step 1: Understand exactly-once requirements

    Exactly-once needs atomic commit of data and offsets to avoid duplicates or loss.
  2. Step 2: Match approach to requirements

    Using idempotent producer with transactions and atomic offset commits ensures exactly-once updates.
  3. Final Answer:

    Use idempotent producer with transactions and commit offsets atomically. -> Option C
  4. Quick Check:

    Idempotent + transactions + atomic commit = exactly-once [OK]
Hint: Atomic commit with idempotent producer ensures exactly-once [OK]
Common Mistakes:
  • Relying on retries without transactions causes duplicates
  • Using multiple producers without coordination breaks exactly-once
  • Not committing offsets leads to message reprocessing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard