Bird
0
0

Consider this simplified event processing code snippet in a microservice:

medium📝 Analysis Q13 of 15
Microservices - Event-Driven Architecture
Consider this simplified event processing code snippet in a microservice:
eventQueue = []

function processEvent(event) {
  if (event.type === 'update') {
    database.update(event.data)
  }
}

// Events arrive asynchronously
processEvent({type: 'update', data: {id: 1, value: 'A'}})
processEvent({type: 'update', data: {id: 1, value: 'B'}})

// What is the likely final value in the database for id 1?
AThe value remains unchanged
B'A', because the first event updates the value
CAn error occurs due to conflicting updates
D'B', because the second event overwrites the first
Step-by-Step Solution
Solution:
  1. Step 1: Analyze event processing order

    Events are processed in order: first update to 'A', then update to 'B'.
  2. Step 2: Determine final database state

    The second update overwrites the first, so final value is 'B'.
  3. Final Answer:

    'B', because the second event overwrites the first -> Option D
  4. Quick Check:

    Last update wins = 'B' [OK]
Quick Trick: Last event update overwrites previous data [OK]
Common Mistakes:
MISTAKES
  • Assuming first update persists ignoring later events
  • Expecting errors on normal overwrites
  • Thinking data stays unchanged without updates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes