Bird
0
0

A developer wrote this code snippet for event communication:

medium📝 Analysis Q14 of 15
Microservices - Event-Driven Architecture
A developer wrote this code snippet for event communication:
eventBus.publish('UserCreated', userData);
userService.createUser(userData);
What is the main problem with this approach regarding decoupling?
AThe event is published before the user is created, causing inconsistency
BThe userService call is synchronous, blocking the event publishing
CThe eventBus and userService are tightly coupled by calling both directly
DThere is no problem; this is a fully decoupled event-driven design
Step-by-Step Solution
Solution:
  1. Step 1: Check event timing relative to action

    The event 'UserCreated' is published before the actual user creation happens.
  2. Step 2: Understand impact on consistency and decoupling

    This can cause other services to react to an event for a user that does not yet exist, breaking consistency and decoupling principles.
  3. Final Answer:

    The event is published before the user is created, causing inconsistency -> Option A
  4. Quick Check:

    Publish event after action = D [OK]
Quick Trick: Publish events only after the action completes [OK]
Common Mistakes:
MISTAKES
  • Publishing events before the actual state change
  • Assuming synchronous calls improve decoupling
  • Thinking calling both is fully decoupled

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes