Skip to main content

A geo distributed cache

Project description

Geo Distributed LRU Cache

Dependencies (server)

This application heavily relies on Docker for speedy installation and deployment. All the dependencies are already met if you use the provided docker containers.

However, if you are unable to use Docker, the server has the following dependencies:

  1. Database

    1. Couchbase Server 6.5.0 Enterprise
  2. API

    1. Python v3.7

    2. Couchbase C Client v2.10.5

    3. Couchbase Python Client v.2.9.5

You can also check the Dockerfile scripts under backend/ for installation steps.

Dependencies (client)

pip install geo-cache-client

Alternatively, you can make http requests as described in geo_cache_client/

Installation (demo)

In an enterprise production environment, the different components of this application are likely to be deployed in different nodes and possibly machines. The final deployment is dependant on the back-end architecture and DevOps of a company. For demo purposes, we provide a sample application in which all components run under the same machine, as a starting point for developers.

To keep things simple, credentials are the same for all clusters and nodes, geolocations are stored in the settings, and we use docker to get the proper IPs. In a production environment, this kind of information could be processed differently.

To setup the demo back-end cluster, run:

    git clone
    cd geo-cache
    # set credentials
    export CB_REST_USERNAME="Administrator"
    export CB_REST_PASSWORD="password"
    bash scripts/
    bash scripts/

If you'd like to see a dashboard, couchbase provides one at http://localhost:8091/ui/index.html

Next, to install the client:

pip install geo-cache-client

The programs under the folder examples provides some sample usage:

python examples/
python examples/


In order to quickly come up with a scalable enterprise-level library, the optimal approach is to delegate as much features as we can to an already existing software package and use it as an underlying architecture.

Upon researching current technologies available, an ideal software seemed to be the Couchbase Server, a distributed multi-model NoSQL document-oriented database. Amongst the key features we have high availability, scale-out architecture, and a memory-first architecture, which is ideal for caches. Essential requirements for our application are detailed below on the section Features.

Couchbase stores data through a concept Buckets.

Couchbase Server keeps items in Buckets. Before an item can be saved, a bucket must exist for it. Each bucket is assigned a name at its creation: this name is referenced by the application or user wishing to save or access items within it.


1 - Simple integration

pip install geo-cache-client

2 - Resilient to network failures and crashes

These are achieved through 4 properties:

Data replication (within a cluster)

Replicas provide protection against data loss by keeping copies of a bucket’s data on multiple servers.

On bucket creation (or editing), it is possible to set the number of replicas. For our demo, we set --bucket-replica 1.

See bucket-create or bucket-edit.

Data persistence

Couchbase buckets are written to disk by setting --bucket-type couchbase. For more information, please see bucket-create.

Automatic failover

Failover is a process whereby a failed node can be taken out of a cluster with speed.

For more information, please see Failover and auto-failover command.

Cross Data Center Replication (XDCR)

Cross Data Center Replication (XDCR) allows us to continuously replicate data from a bucket on one cluster to another bucket in another cluster, possibly located in another geolocation.

3 - Near real time replication of data across Geolocation. Writes need to be in real time.

This requirement is achieved through XDCR.

4 - Data consistency across regions

Achieved through XDCR. You can assure consistency by passing the CAS value from a previous operation to a cache.set assignment.

5 - Locality of reference, data should almost always be available from the closest region

Supported with XDCR. You can connect to the closest server by using GET /closest/<lat>/<long>

6 - Flexible Schema

The cache stores a key-value pair of strings and it is agnostic to the actual data value. We can therefore "stringify" any object in a JSON-like manner, achieving a flexible schema.

Additionally, couchbase is a NoSQL document-oriented database and also has flexible schema, if needed be in further development.

7 - Cache can expire

On bucket creation or editing, we can specify the maximum TTL (time-to-live) for all documents in a bucket in seconds.

Please see bucket-create.

8 - LRU

Couchbase default ejection policy for persistent storage is valueOnly, which keeps only keys in memory. With that in mind, memory eviction uses a simplified version of LRU, not recently used (NRU).

Future Improvements

  1. Fine-grained credentials
  2. Geolocation processing
  3. Non-default cb port
  4. for cache_couchbase
  5. Check if node is up before returning closest
  6. Select fastest ping db cluster instead of closest (?)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geo-cache-client-0.1.2.tar.gz (5.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page