Sharing sessions between microservices

Hello,

I’m using official Mongo Driver for dotnet core 3.2.

Anybody have idea if this below is possible?

I want have two Microservices. The first, initiate a Session and Transaction, insert one record in Collection A and publish event in Message Bus with Session metadata (id, …) . The second, listen event from Message Bus, initiate Session again (with metadata), alter one record in Collection B and commit Transaction.

I want implement my Microservices using Domain Driven Design and Clean Architecture. Suppose that I have three Microservices, Product, Stock and Order. The Product only changes Product Collection. The Stock only changes Stock Collection. The Order only changes Order Collection. To perform sale, then get products, change stock and create order. If Mongo Transaction have ID and Mongo Driver allow initiate instance with this ID, then I communicate this ID between Microservices and ensure segregation responsibility between Bounded Contexts.
The transaction timeout configuration is intersting in this scenario.
If this is possible, I programm Microservices in different languages and use Mongo Driver to facilite this.

I think this is a potencial feature. What you say?

Hi @Osvaldo_Bay_Machado, welcome!

Currently there is no ability to pause a transaction and resume it from another server/instance.

I would strongly recommend to reconsider the architecture design. If you separate the micro-services by objects, you would encounter lots of complex interleaving relationships between the services. This may take away some benefits of micro-services design. i.e. scalability.

Instead of separating the micro-services by objects, you should try to separate them by the task responsibilities. For example, one to process product sales and another to serve product views. You may find this video Document Databases, Domain Driven Design, and Microservices at Travellers Insurance from MongoDB World 2018 useful.

As you reconsider the architecture, you may also gain some benefits in reconsidering your data patterns/schema. Please see also Building With Patterns: A Summary for more information.

Regards,
Wan.

@Osvaldo_Bay_Machado , Sorry to ask this, but how did you solve this problem.
Actually I am also facing exact same problem but I cannot reconsider my architectural design, so sharing session between microservices is the only way.
Will be glad if you can share you experience.:smiley:

Hi @Osvaldo_Bay_Machado I don’t know if it already solved your problem, probably yes. If you don’t strongly recommend giving this one a read. link