A geo distributed cache
Project description
Geo Distributed LRU Cache
Solution
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.
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, please install the following dependencies:
- Python v3.7
- Couchbase Server 6.5.0 Enterprise
- Couchbase C Client v2.10.5
- Couchbase Python Client v.2.9.5
You can also check the Dockerfile scripts for installation steps.
Dependencies (client)
pip install rtimbo-cache
Alternatively, you can make http requests as described in cache_client.py
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.
For the sake of simplicity, 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, that information could be processed differently.
To setup the demo back-end cluster, run:
git clone https://github.com/timbo-rafa/geo-distributed-cache
cd geo-distributed-cache
export CB_REST_USERNAME="Administrator"
export CB_REST_PASSWORD="password"
bash scripts/deploy-database.sh
bash scripts/deploy-api.sh
Then, to install the client:
pip install geo-cache-client
example.py
provides some simple usage.
Features
1 - Simple integration
pip install rtimbo-cache
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
- Fine-grained credentials
- Geolocation processing
- Add container-orchestration system (kubernetes)
- Non-default cb port
settings.py
for cache_couchbase- Check if node is up before returning closest
- Select fastest ping db cluster instead of closest (?)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.