NestJS · Senior · Question 17 of 75
How do you get reliable event publishing from a Nest service that also writes to the database?
- 1Call
client.emit()before committing - 2Call
client.emit()after committing and hope it succeeds - ✓Correct answer: Use a transactional outbox: write the event row in the same transaction, and a separate publisher sends it to the broker
Explanation
Emitting outside the transaction can lose or duplicate events if either step fails.