<commit_before># raft-consensus-algorithm

```text
*** THE REPO IS UNDER CONSTRUCTION - CHECK BACK SOON ***
```

_A simple example of distributed consensus using Hashicorp raft,
an asymmetric consensus algorithm where an elected leader issues
commands to its followers._

Documentation and reference,

* [Hashicorp Raft](https://github.com/hashicorp/raft)
  at github

[GitHub Webpage](https://jeffdecola.github.io/my-go-examples/)

## PREREQUISITES

```bash
go get -u -v github.com/hashicorp/raft
go get -u -v github.com/hashicorp/raft-boltdb
```

## SOLVING DISTRIBUTED CONSENSUS - A BRIEF HISTORY

Consensus is having all the Nodes/Servers in a distributed system
agree on a Value/State. This is more easily said than done because
how do you insure everyone does the correct things.

**Blockchains** are consensus since they run calculations to agree on
the state of things.

The **Paxos** algorithm has been wildly used in the 90's, early 2000's
but is very difficult to use.

**Raft** came along to help makes this consensus easier.

## RAFT

Raft uses asymmetric consensus, meaning there is one leader who tells the other
follower Nodes what to do.

Like otherRaft solves the failures issues such as dead Nodes
(**fail-stop**) or bad Nodes (**Byzantine Failure**).

Once a leader is chosen, we need to handle "log" (state information)
replication. Each Node/Server has a list of logs.
A committed log is when it is a majority of servers.

The client only talks to the leader and the leader in tern
tells all the followers what to do.

## HASHICORP RAFT

Their are many version of RAFT written in many languages.
This example is using Hashicorp's RAFT.
The go library gives you a simple interface to use.  So lets use it.

## LETS CODE

This illustration may help,

![IMAGE - raft-consensus-algorithm - IMAGE](../../docs/pics/webserver/raft-consensus-algorithm.jpg)

## RUN

```bash
go run raft-consensus-algorithm.go \
    -dataDirectory ./node1 \
    -genesis \
    -loglevel debug \
    -nodehttpport 2000 \
    -nodeip 127.0.0.1 \
    -nodetcpport 3000
```<commit_msg>update pic<commit_after># raft-consensus-algorithm

```text
*** THE REPO IS UNDER CONSTRUCTION - CHECK BACK SOON ***
```

_A simple example of distributed consensus using Hashicorp raft,
an asymmetric consensus algorithm where an elected leader issues
commands to its followers._

Documentation and reference,

* [Hashicorp Raft](https://github.com/hashicorp/raft)
  at github

[GitHub Webpage](https://jeffdecola.github.io/my-go-examples/)

## PREREQUISITES

```bash
go get -u -v github.com/hashicorp/raft
go get -u -v github.com/hashicorp/raft-boltdb
```

## SOLVING DISTRIBUTED CONSENSUS - A BRIEF HISTORY

Consensus is having all the Nodes/Servers in a distributed system
agree on a Value/State. This is more easily said than done because
how do you insure everyone does the correct things.

**Blockchains** are consensus since they run calculations to agree on
the state of things.

The **Paxos** algorithm has been wildly used in the 90's, early 2000's
but is very difficult to use.

**Raft** came along to help makes this consensus easier.

## RAFT

Raft uses asymmetric consensus, meaning there is one leader who tells the other
follower Nodes what to do.

Like otherRaft solves the failures issues such as dead Nodes
(**fail-stop**) or bad Nodes (**Byzantine Failure**).

Once a leader is chosen, we need to handle "log" (state information)
replication. Each Node/Server has a list of logs.
A committed log is when it is a majority of servers.

The client only talks to the leader and the leader in tern
tells all the followers what to do.

## HASHICORP RAFT

Their are many version of RAFT written in many languages.
This example is using Hashicorp's RAFT.
The go library gives you a simple interface to use.  So lets use it.

## LETS CODE

This illustration may help,

![IMAGE - raft-consensus-algorithm - IMAGE](../../docs/pics/distributed-systems/raft-consensus-algorithm.jpg)

## RUN

```bash
go run raft-consensus-algorithm.go \
    -dataDirectory ./node1 \
    -genesis \
    -loglevel debug \
    -nodehttpport 2000 \
    -nodeip 127.0.0.1 \
    -nodetcpport 3000
```
{'fraction_non_alphanumeric': 0.08531602980052871, 'fraction_numerical': 0.010093727469358327, 'mean_word_length': 3.8227114716106603, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5522711', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1232, 'n_words': 549}