Giter VIP home page Giter VIP logo

maxi_taxi's Introduction

MaxiTaxi

MaxiTaxi is a very simple application:

  1. Taxis send their location information to MaxiTaxi.
  2. Customers can order a taxi and use it to get from A to B.

The system will track:

  1. The last known position of each taxi.
  2. Whether a taxi is occupied or not.

The following operations will be supported:

  1. Update the location of a taxi.
  2. Search for a nearby taxi that is unoccupied.
  3. Enter a taxi.
  4. Leave a taxi.

Tutorial

The tutorial is split into 4 branches:

  • exercise_1
  • exercise_2
  • exercise_3
  • exercise_4

You can start with exercise_1. If you have completed the exercises, then you can continue in that branch with your own solutions, or you can choose to switch to the exercise_2 branch to continue.

The topics covered are:

  1. libcluster & :rpc
  2. Distributed location database
  3. Horde
  4. Horde partition tolerance

1a. libcluster

Install libcluster in the application.

Configure libcluster using the guide in the README (Cluster.Strategy.Epmd) to connect nodes [email protected] and [email protected].

Start the nodes:

iex --name [email protected] -S mix
iex --name [email protected] -S mix

Confirm that the nodes are connected:

iex([email protected])1> Node.list()
[:"[email protected]"]

1b. using :rpc

We will distribute the location database to all nodes in the cluster. We will use :rpc.call/4 for this.

  1. Send updates to all nodes in the cluster using :rpc.call/4.
  2. Implement a TTL of 2s on updates to prevent stale information from being served (in case of a netsplit for example).

optional 1c. using send/2

Use send/2 instead of :rpc.call/4. This will help us avoid bottlenecks in :rpc.

Reminder: {name, node}.

2. distributed location database

Now we have a "distributed location database", but there is no way for nodes to recover if there is a conflict.

  1. Use delta_crdt to make the database eventually consistent.

Note: information on nodes can still be out of date, but after a netsplit the database will globally converge.

3. distributed taxi state

A taxi can be entered and exited, but we can't allow more than one customer to enter a taxi.

We will use Horde (docs) to distribute taxi processes among the nodes in the cluster. We will register and access the taxi processes using Horde.Registry. Horde.Registry will also keep them unique.

Horde.DynamicSupervisor will ensure that if a node goes down, that the taxi processes are restarted on another node.

  1. start taxi state processes using Horde.DynamicSupervisor
  2. register processes with Horde.Registry

4. handling network partitions

  1. read the docs of Horde and figure out how to handle registry conflicts.

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.