Distributed systems with three boards lesson plan
Three ESP32-C3 boards on ESP-NOW: clocks, loss, retries, elections, consensus and partitions, ending in a counter that survives all of them.
Objectives and materials
By the end, students can
- Order events without a shared clock, and count what the network loses.
- Make retries safe, pick a leader, and agree on a value with a majority.
- Keep working through a partition and merge without losing a thing.
- One counter that rides out loss, crashes and partitions, and a write-up that proves it.
Materials for the whole unit
- ESP32-C3-DevKitM-1 x 3
- LED x 3
- Resistor x 3
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Time and messages
Order events without a shared clock, and count what the network loses.
| Lesson | Time | What students do |
|---|---|---|
| Clocks and orderThree boards, three clocks that disagree. Wall-clock stamps put a reply before its question; Lamport clocks put causes first, and a tie-break makes the order total. | 50 min |
|
| Messages and lossHeartbeats with sequence numbers: count what arrives, lose a quarter on purpose, spot the gaps, and learn why a silent node may be dead or just unlucky. | 50 min |
|
Materials
- ESP32-C3-DevKitM-1 x 3
- LED x 3
- Resistor x 3
Check for understanding
Each student finishes "Messages and loss" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Name the gaps".
Doing it once, and agreeing
Make retries safe, pick a leader, and agree on a value with a majority.
| Lesson | Time | What students do |
|---|---|---|
| Retries and idempotenceTwo clients add to a counter on node A with acks, timeouts and backoff. Lost acks make retries count twice, until the server remembers what it has already applied. | 40 min |
|
| Leader electionThe bully algorithm on three boards: heartbeats, timeouts, elections and terms, with the leader's lamp lit, and a stale leader that a term number teaches A to ignore. | 60 min |
|
| Consensus lightThree lamps agree on one value with ballots and votes. A value commits only with a quorum, so no lamp ever shows what was not agreed, and a majority keeps going when one board dies. | 50 min |
|
Materials
- ESP32-C3-DevKitM-1 x 3
- LED x 3
- Resistor x 3
Check for understanding
Each student finishes "Consensus light" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "What this leaves out".
When the network splits
Keep working through a partition and merge without losing a thing.
| Lesson | Time | What students do |
|---|---|---|
| PartitionsA visitor count gossiped between three boards. Split the network, count on both sides, heal it, and watch a naive merge forget people until a slot-by-slot merge (a CRDT) keeps them all. | 50 min |
|
Materials
- ESP32-C3-DevKitM-1 x 3
- LED x 3
- Resistor x 3
Check for understanding
Each student finishes "Partitions" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Consistent or available".
Boss: a fault-tolerant counter
One counter that rides out loss, crashes and partitions, and a write-up that proves it.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a fault-tolerant counterThe visitor counter, finished: a G-Counter gossiped between three boards that rides out loss, crashes and partitions, with an agreement lamp on each node and a read that knows when it might be stale. | 70 min |
|
Materials
- ESP32-C3-DevKitM-1 x 3
- LED x 3
- Resistor x 3
Check for understanding
Each student finishes "Boss: a fault-tolerant counter" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Write it up".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.