JPA/Hibernate 2nd Level Caching: How to avoid stale data?

Viewed 47
  1. As an example, say we have instances of a spring boot micro-service that uses 2nd level caching. Since the API requests can update the database through one App instance without the other instances knowing it, won't it cause the other instances serve stale data from their 2nd level caches? Apart from that, something like a background batch job could cause the same data inconsistency in the cache isn't it?

  2. If we assume that the database is updated only through the App, can a distributed cache that lives independently from instances like Redis solve the problem?

  3. When there is no guarantee that the database will be updated through the App, is Optimistic and Pessimistic locking the way to solve it?

0 Answers
Related