I am migrating a Grails (2.4.4) web application (Java based) on a Docker Swarm environment (3 nodes) with a MariaDB database outside the Swarm.
On its current version, the application is hosted on a single server and instanciates a few threads (~ 10) which all got a specific task to do, but are all manipulating data from the Database.
Now that the application will be replicated on the 3 nodes of the Swarm, I don't think there is a point in instanciating all the threads on each node, because they would do the same thing on the same data (located on the database machine outside the Swarm), and it probably won't work because of concurrent access and MySql transactions.
So, considering the fact that the threads cannot be redevelopped outside the application's source code as they rely on its model, my question is: what do you think would be the best solution for this use case ? I personnaly thought about two options, but I don't feel like I'm going in the right direction:
- Synchronize the threads at the begining of their process: it would only be the first thread of its kind to actually do the job, the 2 others would put themself back to sleep. I would do that with something like a lock mechanism in the database.
- Only instanciate the threads on one node: I think it should be possible, but I am really unsure about this one, as it would be extremely contradictory with the core principle and advantages of having a replicated & scalable application
So, happy to hear any advice on the matter ! Thanks