jeudi 11 juin 2020

Need for transacional outbox pattern on microservices

I see a recommendation for using the transactional outbox pattern (https://microservices.io/patterns/data/transactional-outbox.html) for scenarios in which a message should be published to a broker after some change in the database, so it can be transactional. My question is: why not put the message publish inside the transaction like this?

try {
   beginTransaction()
   saveStuff()
   publishMessage() 
   commitTransaction()
} catch() {
   rollbackTransaction()
}

This way, whenever the message publish fails, the transaction will be rolled back. I see only one issue: you may not want to rollback the transaction when the message publish fails, trying again later. Are there other issues with this approach?

Aucun commentaire:

Enregistrer un commentaire