mongodbspring-bootdata-synchronization

How to sync in realtime a legacy system with a new one?


I have a legacy grails based system with a MySQL database. I rewrite incrementally the system in a modern Spring Boot 3 and MongoDB Atlas database. I can't just shutdown the legacy system and replace it and I want to rewrite only the write operations (create, update and delete) in the legacy system. So, I write a synchronization mechanism between the legacy system and the new system. To do this, I write a sync project and I use MongoDB Atlas triggers + functions.

For now, the process is as follow:

  1. I call the modern Spring project from the legacy project controller with a REST API call for all write operation (create, update and delete).
  2. I save the new entity in the new project database based on MongoDB Atlas.
  3. A trigger is executed on the entity write and execute a MongoDB Atlas function. This function sends the write event to a sync project.
  4. The sync project receives the write event, transform the new entity into MySQL insert, update or delete executed directly in the legacy database to update it. The sync project keeps also a Link between the legacy entity and the new entity for further calls.

With this mechanism I don't need to update any read operations in the legacy system because the legacy database is updated by the sync project. All the system works as expected but I must do a Thread.sleep in the legacy controller in order to wait the MongoDB Atlas trigger + function execution and the legacy database update.

This waiting is not really acceptable but I don't see what I can do to resolve the problem.

Do you have any idea?


Solution

  • I have resolved my problem with AOP instead of MongoDB Atlas function.