redisdistributedregionroaming

Redis Cache Share Across Regions


I've got an application using redis for cache, it works well so far. However we need spread our applications to different regions(thru dynamic DNS dispatcher via user locations, local user could visit nearest server). Considering the network limitation and bandwith, it's not likely to build a centralised redis. So we have to assign different redis for different regions. So the problem here is how can we handle the roaming case. User opens the app in location 1, while continuing using the app in location 2 without missing the cache in location1.


Solution

  • You will have to use a tiered architecture. This is how most CDNs like Akamai, or Amazon Cloudfront work. Simply put, this is how it works :

    1. When a object is requested, see if it exists in the redis cache server S1 assigned for location L1.

    2. If it does not exist in S1, check whether it exists in caching servers of other locations i.e. S2,S3....SN.

    3. If it is found in S2...SN, store the object in S1 as well, and serve the object.

    4. If not found in S2...SN as well, fetch the object fresh from backend, and store in S1.

    If you are using memcached for caching, then facebook's open-source mcrouter project will help, as it does centralized caching.