Goals

Learn how total order broadcasting is used to implement state machine replication, and its relation to distributed ledger technology. Understand the fundamentals of blockchains, and how proof-of-work and proof-of-stake consensus mechanisms are used to implement a distributed and decentralized database. Understand how the Ethereum Virtual Machine is used to implement smart contracts, and implement a custom coin and voting contract.

Examples

Exercises

Introduction

Context

Replication

When data is replicated, we maintain a copy of the same data on multiple nodes, where each node is called a replica. The main reasons to replicate are to enhance reliability, improve the performance and security.

If one server fails or experiences a problem, the replicated data can still be accessed from other servers. By distributing workload across multiple servers, the system can handle more concurrent requests and provide faster response times. By replicating data geographically closer to users, it reduces network latency and improves user experience. Finally, by maintaining copies of data on multiple servers, organizations can recover quickly in the event of a disaster or data corruption.

Synchronous vs Asynchronous

When the replication is synchronous, the client only receives an answer after all data was successfully replicated. When it is asynchronous, the answer can be received immediately.

replication.svg

Broadcast

When data is broadcasted, it is typically sent to multiple nodes within a group, which is located anywhere on the internet using a point-to-point network connection (see Network Socket).

One node (A) sends a message, and all nodes in the group receive and deliver it. If a node is faulty, all other members carry on (kleppmann21).

group_communication.svg

Message Order

Since we use packet-switching networks, the sequence in which broadcast messages reach each node can differ. Various algorithms provide different levels of message ordering. The most stringent guarantee, known as total message ordering, ensures all nodes receive messages in the same sequence. Algorithms such as Paxos or Raft can guarantee this type of ordering.

Raft Consensus Algorithm

State Machine Replication

State machine replication (SMR) is a technique to provide fault tolerance and consistency. It involves replicating a state machine across multiple servers, where each server executes the same sequence of commands or operations in the same order, resulting in consistent state updates.

Finite-state machine

The inputs that lead to the next state are passed in via messages that arrive with total message ordering - the same order for every node:

state_machine_replication.svg

Consensus Mechanisms