java - maintaining cache state in different servers -


this may dumb question, not getting google even. have server fetches data db, caches data , when ever request involves data, data fetched cache instead of db.there reducing time taken serve request. cache can modified, i.e may key can added or deleted or updated. change occurs in cache happen on db. problem due heavy rush in traffic want add load balancer infront of server. lets add 1 more server. 2 servers have 2 different cache. if thing gets added in first server cache, how should inform second server cache refreshed??

if decide move cache outside main webserver process, take @ consistent hashing. alternative replicated cache.

the problem replicated caches, scale inversely proportional number of nodes participating in cache. i.e. performance degrades add additional nodes. work fine when there small number of nodes. if data replicated between n nodes (or need send eviction messages n nodes), every write requires 1 write cache on originating node, , n-1 writes other nodes.

in consistent hashing, instead define hashing function, takes key of data want store or retrieve input, , returns id of server in cluster responsible caching data key. each caching server responsible fraction of overall keys, client can determine server contain sought data without lookup, , data , eviction messages not need replicated between caching servers.

the "consistent" part of consistent hashing, refers how hashing function handles new servers being added or removed cluster: re-distribution of keys between servers required, function designed minimize amount of such disruption.

in practice, not need dedicated caching cluster, caches run in-process in web servers; each web server being able determine other webserver should store cache data key.

consistent hashing used @ large scale. might overkill @ stage. aware of scalability bottleneck inherent in o(n) messaging architectures. replicated cache possibly idea start with.

edit: take @ infinispan, distributed cache indeed uses consistent hashing out of box.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -