Search code examples
javers

How to keep Javers cache consistent in distributed environment?


When using Javers and Spring Boot applications (with MongoDB) in distributed environments, I get incorrect auditing snapshots.

How to recreate (assuming we have 2 servers) -

  1. Update an existing Document by sending a request on server 1
  2. Update the same Document by sending a request on server 2
  3. Update the same Document again by sending a request on server 1

The last generated auditing data will contain previousValue as it was on request 1 and the currentValue as it is on request 3.

Currently, I have fixed the issue by disabling javers cache by setting the following property javers.snapshotsCacheSize=0.

Is there any way to keep javers cache consistent in distributed environments?


Solution

  • There is no such way. Javers uses local cache only. I didnt tested it but I dont think that adding a distributed cache layer would significantly speed things up. It would add additional overhead. But if you are interested in contributing that feature - we can talk about it here https://github.com/javers/javers/discussions