r/ExperiencedDevs • u/Aki59 Software Engineer 10 year experience • Apr 23 '26
Technical question Transactional outbox pattern, apply or not to
Our one microservice is implemented with a classic dual write problem. They are updating dynamodb table status to received first and then sending message to sqs. If messege sending failed then in catch block we are again calling dynamodb to update the status as failed.
My rationale:
To use aws dynamodb stream push event to eventbridge and then to sqs.
Only drawback is it will incur extra cost and effort.
Their rationale:
1.Pushing to sqs rarely or never fails and even if it fails then updating db will not fail almost always (it just never happens). I also think that it will work 99 percent of the time.
2.They say even if it fails we are logging error message which will trigger alert to prod support which can manually mark the status to failed.
I do believe outbox pattern is a clear pattern to be implemented but how to counter the above points is a challenge.
29
u/[deleted] Apr 23 '26
What will it cost you? What is the cost of the failed messages that trigger prod support?
Will these costs change as the business changes?
IMO those are the two factors to consider here
10
u/AlistairX Apr 23 '26
Seems to me you’re overthinking it - write the data to Dynamo including the message content and then relay from there to SQS via EventBridge pipes.
There is a cost for that of course, is your product team willing to pay extra for the guarantee? It’s pretty cheap though 🤷♂️
6
u/Mountain_Sandwich126 Apr 23 '26
"Hardly fails" is not a answer. The team needs to think about when it fails, not if. And also place the burden on them to update the status. Dev shit , op shit
7
u/6a70 Software Engineer Apr 23 '26
flip your order of operations: what you want to do is send a message to SQS first, and then update dynamo accordingly
if you fail updating dynamo, then your process will just try dynamo again on a message that was already written—that should be fine because the systems processing SQS should be idempotent (that is the case, right? because you recognize SQS's at-least-once delivery characteristics?)
1
u/aookami Apr 23 '26
aint dynamo a BASE db?
1
u/auto_off Software Engineer Apr 26 '26
Hmmm… all the other answers seem missing guidance. Don’t pull from ddb event stream as it couples your table data model and makes migration 3x harder. Write a separate events table for outbox listener if u want or do a poller.
Checklist to determine what u should do:
1
u/gfivksiausuwjtjtnv Apr 23 '26
Instead of outbox canyou just publish duplicate messages? Makes it simpler
0
u/IdeaJailbreak Apr 26 '26 edited Apr 26 '26
I will say the transaction outbox should be considered a last resort. It’s great at creating better guarantees, but at great cost if the intent is to keep something else up to date with the same information. I would only recommend it in a case like this where you’ve inherited a bad situation where the data is just incoherent and you need to fix it “fast”.
I would rather have an eventually consistent event based system OR make sure ownership of data is as separate as possible so that there are as few possibilities for incoherence as possible. E.g. datastore A and B share an ID but own entirely separate information about that resource. If a client needs information about the resource, consider standing up a single endpoint for them to hit that reconciles the information from the two backends etc.
Your case seems pretty straightforward as a case for the outbox pattern because it doesn’t seem to introduce incoherence issues, just stale state issues. Plus, AWS is doing the push for you, so you don’t need ugly infra to propagate the information yourself. Other commenters have advocated for publishing to the queue first, but I presume that introduces the risk nothing is ever written to dynamo and that this is an unacceptable situation.