Neo4J OGM cache/session strategy in a cluster


I have a cluster of 4 VPS running on ubuntu (latest v) in the context of a backend serving a RESTful API.
1 Neo4J Db dedicated server
1 Nginx load balancer server
2 nodes containing the same Java+OGM backend code

In order to avoid OGM caching different data on each nodes, what would be the best implementation?

Thank you.

If I understand your scenario correctly, I think that the very fresh blog post Michael wrote can help you with this.

Thank for the quick answer.

I don't think it solves my problem which i may have badly explained:

The load balancer is alternating between server A and B.
When a user modify for instance his "age", the first request goes to server A, calling a Java method that call a thus creating an OGM mapping context.

In the next modification, the same happens to server B, creating a mapping context on server B persisting data that doesn't correlate to what is in the mapping context of server A.

We have to distinguish here between mapping context and Neo4j-OGM session.
The mapping context itself is primarily something static that holds the meta-data describing the entities/relationships...
The session is the one with the cache. Ideally an OGM session's lifespan should map 1:1 to a transaction.
That means after the user changed the age, the transaction (and the session with its cache) is done, bookmarks should get shared (see the blog post) between the application instances and the other server would start its next operation based on the current bookmark in the system.

But assuming for now, that you are using a single instance, you would not even have to bother with the bookmarks. Maybe with a very high loaded multi-threaded application this could be the case but I assume that your pain point is somewhere else.