Code Monkey home page Code Monkey logo

file-index-lookup-engine's Introduction

Distributed file server & text search engine

A distributed file server based on the raft algorithm. Content of the uploaded files is mapped and stored in the form of an avl tree distributed amongst the peers, assuring efficient lookup & updates. The system is eventually consistent in the event of network partitions.

Running the services

docker-compose up --build --remove-orphans

This will launch 5 instances of the service as independent containers. An ingress nginx container acts as a load balancer to the services, exposing a single external port for client interactions.

The services are interlinked via Http + gRPC over internal docker networks.

Raft algorithm

  • To elect a leader, the primary source for search queries.
  • followers start elections if the leader fails / does not send expected heartbeats.
  • upload & search queries can be forwarded to any on the peer.
    • upload is processed locally by the receiving service
    • search is forwarded by all followers to the leader, which then concurrently queries the remaining followers.

Upload '.txt' files

curl --location --request POST 'localhost:80/service/upload' --form 'files=@"./sample.txt"' --form 'files=@"./sample2.txt"' 

Search for a word from the uploaded file(s)

curl --location --request GET 'localhost:80/service/search?word=foo'

Get details (raft-state, raft-term, raft-leader, hostname, ports)

curl --location --request GET 'localhost:80/raft/details'

Simulating a network partition

Once the services are up and running, a network partition can be simulated through docker.

  • A call to /raft/details prior to network partition will list the current leader's container-name.
  • To simulate a network partition with the leader, the command docker pause $container-name can be used, along with the respective name.
  • A subsequent call to /raft/details (after the heartbeat timeout of 10s) would now list a new leader.

Further, the command docker unpause $container-name will reconnect to container of the old leader to the network. On re-joining, it will eventually become consistent with the cluster and become a follower by virtue of receiving a higher term id.

Stop the services

docker-compose down && docker-compose stop

Docker Image

docker pull ishan27g/fsi-raft-service:v0.2

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.