Reliably Save State & Publish Events (Outbox Pattern)
Video Statistics and Information
Channel: CodeOpinion
Views: 18,851
Rating: undefined out of 5
Keywords: Outbox Pattern, software architecture, software design, cqrs, event sourcing, design patterns, software architect, .net, .net core, soa, microservices, message queues, kafka, event bus, event driven architecture, azure service bus, rabbitmq, distributed transactions, service bus, mass transit, nservicebus, message queue, messaging patterns, service oriented architecture, microservice architecture, enterprise service bus, outbox pattern microservices, Outbox pattern c#
Id: u8fOnxAxKHk
Channel Id: undefined
Length: 9min 9sec (549 seconds)
Published: Wed Nov 25 2020
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
Love your channel. Have learned a lot on things I couldn't quite get my head around through other sources. Like CQRS.
Thats really cool, thanks.
What do you think of accepting that you may publish events twice and making sure your services are written in a way to expect events being published at least once?
Watching you do that in a few lines of code made me cry. We use go at work...
Iβve been looking for this solution for a while, makes perfect sense and you should always be able to handle duplicate messages anyway!
Your channel is a goldmine! You have filled a few evenings of βwatch latterβ content! *subbed! Thanks :)
I used this pattern for interfacing with multiple systems in a way that made them seem like a transaction. I did it with NServiceBus sagas. My saga would keep track of which actions it already performed. If the handler encountered an exception while processing the request, a series of retries would happen in order to finish processing the request. Each retry would resume where the handler left off. Most of the time, a simple retry would fix the issue.
Like you said, it is possible to publish duplicate messages this way, but that's why we designed everything to be idempotent. The only issue we couldn't avoid was sending API calls to a 3rd party. That 3rd party API may not be idempotent which means we may accidently calling it multiple times. I remember this being an issue when a 3rd party introduced a breaking change in their response model. We encountered an error when deserializing the response, which meant we were calling their API multiple times because of our retry policy.
Get out of my head! :P
This issue was actually brought up at work, and something I pushed (unsuccessfully) to fix at my last job because we saw events that got dropped on the floor because of exceptions (my favorite was an issue where something wasn't SNS client wasn't registered as a singleton and something else wasn't awaited properly and the SNS client got disposed of before sending the message, whooooops).
I'll have to look at CAP and NServiceBus as possible solutions rather than using the of toy solution I wrote up (was fun to build though).
I'd be interested in seeing a commentary on the inbox pattern. For the unfamiliar, that's kind of the opposite where an inbound message is recorded in the database and a separate thread/thing handles processing it.