Package: geo-cache-client
Geo Distributed LRU CacheDependencies (server)This application heavily relies onDockerfor 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:DatabaseCouchbase Server6.5.0 EnterpriseAPIPythonv3.7Couchbase C Clientv2.10.5Couchbase Python Clientv.2.9.5You can also check the Dockerfile scripts underbackend/for installation steps.Dependencies (client)pipinstallgeo-cache-clientAlternatively, you can make http requests as described ingeo_cache_client/cache_client.pyInstallation (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:gitclonehttps://github.com/timbo-rafa/geo-cachecdgeo-cache# set credentialsexportCB_REST_USERNAME="Administrator"exportCB_REST_PASSWORD="password"bashscripts/deploy-database.shbashscripts/deploy-api.shIf you'd like to see a dashboard, couchbase provides one athttp://localhost:8091/ui/index.htmlNext, to install the client:pip install geo-cache-clientThe programs under the folderexamplesprovides some sample usage:pythonexamples/replication.py
pythonexamples/concurrency.pySolutionIn 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 theCouchbase 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 sectionFeatures.Couchbase stores data through a conceptBuckets.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.Features1 - Simple integrationpip install geo-cache-client2 - Resilient to network failures and crashesThese 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.Seebucket-createorbucket-edit.Data persistenceCouchbase buckets are written to disk by setting--bucket-type couchbase.
For more information, please seebucket-create.Automatic failoverFailover is a process whereby a failed node can be taken out of a cluster with speed.For more information, please seeFailoverandauto-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 throughXDCR.4 - Data consistency across regionsAchieved throughXDCR.
You can assure consistency by passing theCASvalue from a previous operation to acache.setassignment.5 - Locality of reference, data should almost always be available from the closest regionSupported withXDCR.
You can connect to the closest server by usingGET /closest/<lat>/<long>6 - Flexible SchemaThe 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 expireOn bucket creation or editing, we can specify the maximum TTL (time-to-live) for all documents in a bucket in seconds.Please seebucket-create.8 - LRUCouchbase default ejection policy for persistent storage isvalueOnly, which keeps only keys in memory. With that in mind, memory eviction uses a simplified version of LRU,not recently used (NRU).Future ImprovementsFine-grained credentialsGeolocation processingNon-default cb portsettings.pyfor cache_couchbaseCheck if node is up before returning closestSelect fastest ping db cluster instead of closest (?)