distributedcounter

command module
v0.0.0-...-5b1701d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

Distributed Likes Service

Hello world of distributed systems. Yes, we are talking about distributed counter. 😛 Attempt to write the distributed counter in go using CRDTs, because otherwise it would be even harder. This repo is just for learning purpose and not as a production ready code, but will try to achieve as close to it as possible. Plan to use this repository to learn multiple tools and ideologies such as distributed tracing, observability etc.

CRDTs are conflict free replicated data types, and this is an eventual consistent system. Where a like just landed on a post might not reflect to everyone instantly but will appear eventually. This uses gset CRDT which is grow only set written sometime before by me here also in go. So you must have already guessed it, yep it doesn't allow you to take back your like or dislike.

Use makefile to run the kubernetes cluster locally, considering you have minikube installed on your local system. Ships the dockerfile with the repo by default. The default goal for makefile is help which returns something like this- make help

To run the cluster use-

make run

then use minikube service distributed-likes-service-cluster to get an IP for your likes cluster service. It will open a url in the browser by default, that url endpoint sort of acts like heartbeat but returns the node name as well in the response, so you can track every request doesn't land to the same node.

Also the endpoints to register the like and get the likes are

curl -XPOST -H "Content-Type:application/json" -d '{"post":"abcd","user":"some"}' /like
curl -XGET likes\?post=abcd
curl -XGET likes\?post=abcd\&detail=true

In the example below if you see the request to like landed up at some worker but quickly got propagated and your get request can land at any of the pod afterwards, for example- some other worker or master and you get the updated likes.

example

Progress

  • Working
  • Orchestrated
  • Globally Available Git Hooks(Lefthook)
  • Distributed Tracing
  • Unit Tests
  • Integration Tests
  • Helm Charts

Documentation

Overview

Distributed like service with in memory database. Anyone can create a post, and anyone can like a post. Request to like might land on any instance of the service running, therefore we will gossip the like to reach every node. This is going to be eventually consistent. And getLikes() might not implement serializability. For serializability you might want to do something like writing the like to a quorum of nodes and then reading it from the quorum of nodes. But this writes just to a single node on which the request lands, and then it's the responsibility of the node to gossip the like to the rest of the nodes. Because this does not require stronger consistency, and is just for a practice and using CRDTs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL