Cluster web application synchronization

I have a cluster of web servers, each of which works with the same Java web application. All these web application instances have the same database (for storing data) and the same network file storage (where some of the required files are stored).

I need to sync instances of web applications. For example, one of the application instances receives a specific request from the client, performs some recalculations, and updates its internal cache. At this point, I need to update the internal caches for all other web applications in the cluster so that each of them runs on the same dataset.

What would be the best way to achieve this functionality? Of course, I can implement some kind of custom component that will periodically poll the shared resource (a flag in the database table or a file in the file storage) and initiate the required processing after the condition is met. But maybe there is already an existing library / component / application that I can use?

+6
source share
1 answer

There are many existing libraries and components. You can google about cache coherence. There are various ready-to-use solutions, Jboss cache, Oracle consistency, GridGain, etc.

If you want to write handwritten code, there are several ways you can do this. Each node in your cluster should know about other nodes (in the simplest case). Data can be replicated in different ways.

Synchronous Replication Recording is performed in the local cache only when records are sent to other nodes.

Asynchronous replication. Records are found in the local node and are later replicated to other nodes.

Invalid cache. When the data changes, all nodes receive a signal, cancel their data and re-read it from the database.

This can be difficult to implement, you need a special protocol (you can use JGroups ) that your nodes will use to exchange data. I suggest you find a ready-made solution

+3
source

Source: https://habr.com/ru/post/908509/


All Articles