Code Monkey home page Code Monkey logo

gcounter-crdt's Introduction

gcounter-crdt

GCounter CRDT Cluster implemented in Go & Docker

Introduction

CRDTs (Commutative Replicated Data Types) are a certain form of data types that when replicated across several nodes over a network achieve eventual consistency without the need for a consensus round. GCounters abbreviated as grow-only counters are CRDT counters modified to only increment the count in it and becomes consistent across nodes in a cluster having replicated the counter.

Example

After building a cluster of GCounter nodes we can now increment counts to either one or many nodes in the cluster.

$ curl -i -X GET localhost:8080/gcounter/increment
$ curl -i -X GET localhost:8081/gcounter/increment

When looking up the total count in the counter they then sync up with each other and thus return consistent values every time from any node in the cluster

$ curl -i -X GET localhost:8081/gcounter/count
{
    count: 2
}

The values remain consistent for nodes in the cluster that have never incremented the count value in it

$ curl -i -X GET localhost:8082/gcounter/count
{
    count: 2
}

Steps

After cloning the repo. To provision the cluster:

$ make provision

This creates a 3 node GCounter cluster established in their own docker network.

To view the status of the cluster

$ make info

Now we can send requests to increment, and get the total cluster count of any peer node using its port allocated.

$ curl -i -X GET localhost:<peer-port>/gcounter/increment
$ curl -i -X GET localhost:<peer-port>/gcounter/count

In the logs for each peer docker container, we can see the logs of the peer nodes getting in sync during read operations.

To tear down the cluster and remove the built docker images:

$ make clean

This is not certain to clean up all the locally created docker images at times. You can do a docker rmi to delete them.

References

gcounter-crdt's People

Contributors

el10savio avatar

Watchers

 avatar  avatar

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.