Bird
0
0

Identify the bug in this idempotent event consumer pseudocode:

medium📝 Analysis Q6 of 15
Microservices - Event-Driven Architecture
Identify the bug in this idempotent event consumer pseudocode:
processed = set()
def consume(event):
    processed.add(event.id)
    if event.id in processed:
        return
    process_event(event)
AEvent ID is never added to the processed set
BThe processed set is cleared after each event
Cprocess_event is called before checking duplicates
DEvent ID is added before checking duplicates, so processing is skipped always
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the order of operations

    The event ID is added to the processed set before the duplicate check.
  2. Step 2: Understand the effect on duplicate check

    Since the ID is always in the set, the check always returns true and processing is skipped.
  3. Final Answer:

    Event ID is added before checking duplicates, so processing is skipped always -> Option D
  4. Quick Check:

    Check must come before add [OK]
Quick Trick: Check duplicates before adding event ID [OK]
Common Mistakes:
MISTAKES
  • Adding event ID after processing
  • Not checking duplicates at all
  • Clearing processed set incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes