Bird
0
0

Which code snippet correctly checks if an event has been processed before in a Python event consumer?

easy📝 Conceptual Q3 of 15
Microservices - Event-Driven Architecture
Which code snippet correctly checks if an event has been processed before in a Python event consumer?
Aprocessed_events.add(event.id) if event.id in processed_events: return
Bif event.id in processed_events: return processed_events.add(event.id)
Cif event.id not in processed_events: return processed_events.add(event.id)
Dif event.id == processed_events: return processed_events.add(event.id)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the logic to skip duplicates

    If the event ID is already in the set, skip processing by returning early.
  2. Step 2: Add event ID after confirming it's new

    Only add the event ID to the set after confirming it wasn't processed before.
  3. Final Answer:

    if event.id in processed_events: return processed_events.add(event.id) -> Option B
  4. Quick Check:

    Check before add = Correct idempotency check [OK]
Quick Trick: Check membership before adding to processed set [OK]
Common Mistakes:
MISTAKES
  • Returning when event ID is not in processed set
  • Adding event ID before checking duplicates
  • Comparing event ID to entire set instead of membership

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes