Home > front end >  Solving synchronization problems in asynchronous programs
Solving synchronization problems in asynchronous programs

Time:10-27

I am developing 2 projects using asynchronous technology Vert.x and Node.js and MongoDB. Both projects have the feature of booking airline tickets, there will certainly be cases where many people book the same ticket at the same time. sometimes, there will be data inconsistency problem. So I think the solution is to use synchronisation, but what I'm worried about is that using sync in an async application will cause performance issue where threads are blocked until processed, affecting user experience. So is there any way to achieve this? Is it good to use synchronization in this case? I would be very grateful and appreciated if someone share me a solution to this problem. Forgive me as this is my first time working with asynchronous applications. Thank you very much

CodePudding user response:

With Vert.x you could make use of the event bus. The send method will deliver a message to at most one handler registered on an address. That way you shouldn't need synchronization. When you mix in a node app, then you could make use of a similar system using a message queue where only one consumer would work on a booking.

There's also a vert.x event bus bridge for node that you could take a look at here.

CodePudding user response:

You can just use optimistic locking on Mongo side. More details: https://en.wikipedia.org/wiki/Optimistic_concurrency_control

  • Related