3

I have a question about mongodb and outbox pattern (and i'm quite newbie in mongo).

I am working on application, that uses mongodb as primary database. I have some use cases, in which i need to save document to the database and then publish some event to message broker (RabbitMq). Saved document must be consistent with published event - this means that if I save document i MUST also send message (solution must be resilient to for example server shutdown between document save and message send) so I decided to use outbox pattern. In relational (sql) database this problem is trivial: I just start new transaction, then persist/change new object, then persist some kind of database scheduler record (that sends message to RabbitMq after transaction is committed), and then commit.

How do I achieve this in mongodb (once again with emphasis on no data loss and no 'phantom' message send). Should I use mongodb transactions (transactions are strongly disadvised in mongo community) or there are other, better solutions?

1 Answer 1

2

you can try mongodb change streams at a collection level. It is similar to triggers on the RDBMS world. You can then listen on that stream for events of your choice, in your case - an insert event, post which you can send that event to downstream systems.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.