Giter Club home page Giter Club logo

pycache's Introduction

PyCache

A distributed in memory key-value store in Python Flask.

How to setup and run

Prerequisites

The application uses docker containers and docker-compose to run multiple containers to simulate a cluster of nodes.

Steps

  1. Clone the repository
  2. Navigate inside the directory
  3. Copy the sample config to actual config by
    1. cp app/config.py.sample app/config.py
  4. Make sure docker is running
  5. Run docker compose to start the cluster
    1. docker-compose up

Tricky stuff

Often times, killing docker-compose and restarting it might fail, since Kafka is not able to create a resource in Zookeeper. For this, wait for 1 min, then kill and start docker compose again.

Or we can only restart kafka by: docker-compose restart kafka

Why does this happen?

When Kafka starts, it registers it’s own broker with Zookeeper, however, if we kill docker compose, Kafka misses the chance to de-register itself.

On the next start it tries to do the same thing, but fails. Zookeeper after a min cleans up any dangling registrations. Hence we can restart and things work again.

Covered Cases

Basic SET, GET and EXPIRE operations

The API requests can be made to the load-balancer which will route them in round robin fashion, or to the individual nodes as well.

Refer to API documentation for more details on both.

Set value on one node and read from another works.

Node failure

We can simulate a node failure, by killing a container using docker. In the default setup, 3 cache containers are running, which we are free to kill.

# List all running containers
docker ps

# Kill the container whose name has `cache`
docker kill <container_name>

After killing the node, the APIs should still work, as the load-balancer will route them elsewhere.

We can even kill all the containers, however, the APIs will stop at this point.

Node Reboot

We can simulate a node reboot/reattachment, by starting the container(s) using docker.

# List all containers, running and exited
docker ps -a

# Start the container whose name has `cache`
docker start <container_name>

The node, after startup, will replay all the data from the commit log and will be in sync with other nodes.

In production setup, we won't attach the node to the load-balancer until it has completed the sync (using readiness probe or something similar). However, in docker-compose there is no such option.

API Documentation

API documentation

System Architecture

System Architecture diagram

For details on the architecture, check the System Architecture documentation.

Code Architecture

For details on the code architecture, check the Code Architecture documentation.

pycache's People

Contributors

adityav-verma avatar

Stargazers

 avatar  avatar

Watchers

 avatar

pycache's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.