I'm working on a project where DynamoDB
is being used as database and every use case of the application is triggered by a message
published after an item has been created/updated in DB. Currently the code follows this approach:
repository.save(entity);
messagePublisher.publish(event);
Udi Dahan has a video called Reliable Messaging Without Distributed Transactions
where he talks about a solution to situations where a system can fail right after saving to DB but before publishing the message as messages are not part of a transaction. But in his solution I think he assumes using a SQL
database as the process involves saving, as part of the transaction, the correlationId of the message being processed, the entity modification and the messages that are to be published. Using a NoSQL
DB I cannot think of a clean way to store the information about the messages.
A solution would be using DynamoDB
streams
and subscribe to the events published either using a Lambda
or another service to transformed them into domain-specific events. My problem with this is that I wouldn't be able to send the messages from the domain logic, the logic would be spread across the service processing the message and the Lambda/service
reacting over changes and the solution would be platform-specific.
Is there any other way to handle this?