Distributed Systems · Dr. Abdalkarim Awad · Birzeit University. Theory as step-by-step simulations, then a live cluster on this laptop that your phones will join.
Today, as subjects
Subscribe with talk.> to get all of it.
talk.intro.whyWhy a messaging layerwiring services, what NATS is
talk.core.*Core NATSsubjects, wildcards, three ways to talk
talk.consensus.raftFailures and consensusclusters, JetStream, Raft, majorities
talk.edge.leafnodeThe edgekeeps working offline
talk.live.>Live on this laptopwe crash servers; your phones join
talk.wrap.questionsKafka, RabbitMQ, takeawayswhen to pick NATS
Services have to find each other
Small program, whole messaging system
Open source (Apache 2.0), written in Go, a Cloud Native Computing Foundation project.
15.8 MBthe whole serverone file, nothing else to install
26 MBmemory, idle serversmall enough for a Raspberry Pi
40+client languagesGo, Python, Java, JS, C, Rust…
Sizes measured on our demo laptop: nats-server 2.15.3, macOS arm64. The live slide later shows the memory of each running server.
originCreated by Derek Collison as the messaging system of Cloud Foundry, first written in Ruby.
rewriteRewritten in Go for speed. The protocol stays plain text you can type by hand.
2021JetStream (v2.2) adds storage, replication and Raft to the same binary.
2025A dispute over the project's licence ends with NATS staying open source in the CNCF.
todayMaintained mainly by Synadia. Used for microservices, IoT and edge systems.
Messages go to subjects, not to machines
Three ways to talk, all on subjects
Core NATS forgets. JetStream remembers.
Clients don't care which server they reach
A stream is a log, copied to three servers
Raft: who leads, and what happens when it dies
No majority, no writes
The edge keeps working when the link doesn't
Live: five acts, real servers
1
Publish-subscribe and wildcardsnats sub "campus.>" nats sub "campus.*.temp"
nats pub campus.lab1.temp "23.5"
2
Queue group: three workers share nine jobsnats sub jobs --queue workers nats pub jobs "job {{Count}}" --count 9
3
Request-replynats reply svc.time "it is {{Time}}" nats request svc.time ""
4
JetStream: store 3 copies, then crash the leadernats stream add SENSORS --subjects "campus.>" --replicas 3 --defaults
./scripts/sensors.sh ./scripts/kill-leader.sh
5
Edge: cut the cable, buffer, sync./scripts/start-edge.sh ./scripts/edge-link.sh down … up
Your phone is now a sensor
Live experiments with your phones
1
Everyone: tap “Send reading” a few timesEach phone shows the sequence number the stream gave it.
2
We crash the leader while you keep tapping./scripts/kill-leader.shFor a few seconds your phone says “waiting for a leader”, then it is stored.
3
Tap “Join the workers”, then we send 30 jobsEach job goes to exactly one phone. Count yours.
4
We crash a second server: no majority./scripts/kill-node.sh n1Your phone keeps retrying. Nothing is stored, nothing is lost.
5
We restart both servers./scripts/start-node.sh n1 ./scripts/start-node.sh n2The retried readings go through.
How NATS compares
NATS
Apache Kafka
RabbitMQ
Model
Subjects, plus optional stored streams
A partitioned, replicated log
Exchanges that route into queues
Routing
Subject hierarchy with wildcards
Topic, then partition by key
Bindings and routing keys
Storage
Optional, per stream
Always: the log is the product
Optional, per queue
Replication
A Raft group per stream
Leader with in-sync replicas; Raft (KRaft) for metadata
Raft in quorum queues
Runs as
One small binary
Java brokers
Erlang runtime
Best at
Microservices, IoT and edge, request-reply
Very high-volume event pipelines and analytics
Task queues with complex routing rules
When NATS fits, and when it doesn't
A good fit when
services need simple, fast communication
devices sit at the edge on unreliable links
one tool should cover messaging, streams and key-value
a small team has to run it
Look elsewhere when
you keep years of events and analyse them with a big ecosystem: Kafka
you need windows and joins over streams: Flink
you depend on AMQP or elaborate routing rules: RabbitMQ
Takeaways
Subjects decouple services: send to a name, not to a machine.
JetStream + Raft: a write counts once a majority has it, and nothing else does.
No majority, no writes: consistency is chosen over availability.
The edge keeps working offline and syncs when the link returns.
Questions?
we have time for a few
Sources · docs.nats.io · raft.github.io (D. Ongaro and J. Ousterhout, “In Search of an Understandable Consensus Algorithm”, 2014) · CNCF and Synadia announcements on NATS licensing, 2025 · our own measurements, nats-server 2.15.3 · GIFs via GIPHY · demo code: ~/Documents/nats-demo