• Stars
    star
    508
  • Rank 86,941 (Top 2 %)
  • Language
    Erlang
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Erlang implementation of RAFT from WhatsApp

WhatsApp Raft - WARaft

WARaft is a Raft library in Erlang by WhatsApp. It provides an Erlang implementation to obtain consensus among replicated state machines. Consensus is a fundamental problem in fault-tolerant distributed systems. WARaft has been used as consensus provider in WhatsApp message storage, which is a large scale strongly consistent storage system across 5+ datacenters.

Features

  • Full implementation of Raft consensus algorithm defined in https://raft.github.io/
  • Extensible framework. It offers pluggable component interface for log, state machines and transport layer. Users are also allowed provide their own implementation to customize .
  • Performant. It is highly optimized for large volume transactions user cases. It could support up to 200K/s transactions with in a 5 node cluster.
  • Distributed key value store. WARaft provides components needed to build a distributed key-value storage.

Get Started

The following code snippet gives a quick glance about how WARaft works. It creates single node WARaft cluster and write a record.

The example directory contains a generic key-value store built on top of WARaft.

% Cluster config - single node. table name test, partition 1
1> Spec = wa_raft_sup:child_spec([#{table => test, partition => 1, nodes => [node()]}]).

% Start raft processes under kernel_sup as supervisor. It's for demo purpose only. An app supervisor should be used for a real case
2> supervisor:start_child(kernel_sup, Spec).
{ok,<0.140.0>}

% Check raft server status
3> wa_raft_server:status(raft_server_test_1).
[{state,stalled},
 {id,nonode@nohost},
 {partition,1},
 {data_dir,"missing/test.1/"},
 {current_term,0},
 {voted_for,undefined},
 {commit_index,0},
 {last_applied,0},
 {leader_id,undefined},
 {next_index,#{}},
 {match_index,#{}},
 {log_module,wa_raft_log_ets},
 {log_first,0},
 {log_last,0},
 {votes,#{}},
 {inflight_applies,0},
 {disable_reason,undefined},
 {config,#{version => 1}}]

% Promote current node as leader
4> wa_raft_server:promote(raft_server_test_1, 1, true, #{version => 1, membership => [{raft_server_test_1, node()}]}).
ok

5> wa_raft_server:status(raft_server_test_1).
[{state,leader},  % leader node
 {id,nonode@nohost},
 {partition,1},
 {data_dir,"missing/test.1/"},
 {current_term,1},
 {voted_for,undefined},
 {commit_index,1},
 {last_applied,1},
 {leader_id,nonode@nohost},
 {next_index,#{}},
 {match_index,#{}},
 {log_module,wa_raft_log_ets},
 {log_first,0},
 {log_last,1},
 {votes,#{}},
 {inflight_applies,0},
 {disable_reason,undefined},
 {config,#{membership => [{raft_server_test_1,nonode@nohost}],
           version => 1}}]

% Write {key, 1000} to raft_server_test_1
6> wa_raft_acceptor:commit(raft_acceptor_test_1, {make_ref(), {write, test, key, 1000}}).
{ok, 2}

% Read key
7> wa_raft_acceptor:commit(raft_acceptor_test_1, {make_ref(), {read, test, key}}).
{ok,{1000,#{},2}}

% Stop raft
8> supervisor:terminate_child(kernel_sup, wa_raft_sup).
ok
9> supervisor:delete_child(kernel_sup, wa_raft_sup).
ok

License

WARaft is Apache licensed.

More Repositories

1

stickers

This repository contains the iOS and Android sample apps and API for creating third party sticker packs for WhatsApp.
Java
2,711
star
2

proxy

This repository contains the WhatsApp proxy implementation for users to host their own proxy infrastructure to connect to WhatsApp for chat (VoIP is not currently supported)
Shell
1,163
star
3

eqwalizer

A type-checker for Erlang
Erlang
477
star
4

erlfmt

An automated code formatter for Erlang
Erlang
391
star
5

WhatsApp-Business-API-Setup-Scripts

The scripts related to setting up WhatsApp business API
373
star
6

erlt

Early prototype of ErlT, an experimental Erlang dialect with first-class support for static typing.
Erlang
127
star
7

StringPacks

Extracts localized strings from an Android app and stores it in a much more efficient format.
Java
124
star
8

erlfuzz

erlfuzz is a fuzzer for the Erlang ecosystem
Rust
112
star
9

WhatsApp-Nodejs-SDK

The official Meta Business Messaging WhatsApp Cloud API Node.js SDK.
TypeScript
102
star
10

erlang-language-platform

Erlang Language Platform. LSP server and CLI.
Rust
77
star
11

power_shell

Erlang shell with advanced features: evaluating non-exported functions and shortcuts for frequently used functions.
Erlang
74
star
12

tree-sitter-erlang

Tree-sitter Grammar for Erlang
C
65
star
13

WADebug

WhatsApp Debug - A command-line tool that will be used to troubleshoot installation of WhatsApp Business API.
Python
30
star
14

whatsapp-business-api-deployment-templates

This repo hosts the cloud templates which enable one-click deployment of their WhatsApp Business Platform On-Premise API on different cloud platforms with stable high messaging throughput.
HCL
24
star
15

erldist_filter

erldist_filter NIF for filtering and logging Erlang Dist Protocol messages
C
13
star
16

WhatsApp-OTP-Sample-App

Sample app that integrates with WhatsApp OTP (One-Time Password) copy code and "one-tap" autofill features. This project shows how to send and receive OTP code from WhatsApp and best practices around integration.
Swift
10
star
17

WhatsApp-Android-OTP-SDK

WhatsApp Android OTP SDK helps you integrate with one-time password solution provided by WhatsApp.It provides handy functions that simplifies the integration work.
Java
4
star
18

WhatsApp-Flows-Tools

Tools and examples to help you create WhatsApp Flows https://developers.facebook.com/docs/whatsapp/flows
1
star