Global distributed transaction involving MongoDB and a RDBMS

Hi Team,

We have a use case in which we are considering MongoDB as a key value store and a RDBMS (we are considering PostgreSQL as RDBMS) as a read view. We have an event driven system which will process the event only if the event id of the event is not found in the Key Value store. Once the event is processed, we need to add the event ID to the key value store and the result of the process to the RDBMS in one transaction. We wanted the transaction to be atomic such that if any one of the process (storing event id in MongoDB and storing a read view in RDBMS) fails, we will abort the transaction and rollback any commit. I have read about the “session” and transactions in MongoDB, but I have only found the ACID transaction support at the level of replica set and sharded cluster.

Is it possible to achieve the global transaction with MongoDB as the key-value store?

Hi @Aman_Lonare ,

The real question is why do you need postgress? MongoDB is a general puprose database meaning that it can support Key-Value workloads as well as a read based view (fully indexable and filtering on various levels).

I wonder if doing all of this complex cross database transaction is just an overhead you can avoid by doing a correct MongoDB schema design that will support both you reads/writes. Then you will not need a transaction outside of MongoDB and moreover might not need transactions at all.

Can you describe your data concerns/design so I can help you use only MongoDB for this application?

Otherwise, the only method is to manage a two-phase commit when you write data to MongoDB then stream it to Postgress and only once they are both commited you mark them with a flag of data being consistent.


1 Like