We have two application server.One is App server and other one is API server. Both have different caching system.If one change the DB other does not get known.Below is the Image for our architecture and we have used spring framework (Ehcache) for caching.
We also have entity listener in our project. If one flow change the DB So other flow does not get affected. How can we sync both Application Server and caching? Please help on this.
I can think of a couple of approaches to do this.
1. Cluster with replication: If you want to go with the out of the box cache provider from Spring i.e Ehcache, it would essentially mean yours is a node level cache and would need replication. Check the following link for configuring ehcache cluster using Terracotta http://ehcache.org/documentation/2.6/configuration/distributed-cache-configuration
2. Centralized Cache server My personal choice would be a centralized cache that would provide out of the box support for horizontal scaling with their own clustering if need be. This would involve removing caching from the node level and instead having it centralized on a cache server. So essentially your cache server sits between your DB and your application nodes. You could look at Memcached, Aerospike and Redis.