NATS is a high-performance messaging system built for cloud-native + IoT scale. JetStream adds at-least-once delivery + persistence. Combined: a Kafka-like log with a ~1MB binary footprint and microsecond latency. Right for IoT, edge, and low-overhead microservices.
NATS vs Kafka in one sentence
Kafka: high-throughput log for analytics. NATS: low-latency pub/sub for real-time messaging. JetStream gives NATS log-like durability without giving up its speed. Both can coexist; they solve different problems.
Subject hierarchy
Hierarchical topics: sensors.living-room.temp. Wildcards: sensors.*, sensors.>. Devices subscribe by region/type without per-device config. Scales to millions of subjects per cluster.
JetStream guarantees
At-least-once delivery (consumer ACKs each message). Replication (3-node default, configurable). Retention by size, age, or count. Pull-based consumers (consumer asks for batch, ACKs, asks for next). Push-based for low-latency.
Edge deployment
Single binary (~20 MB). Runs on Raspberry Pi or beefier edge hardware. Leaf nodes connect to central NATS cluster, buffer locally on connection loss, replay on reconnect. Right for IoT fleets in spotty connectivity.
When to pick NATS over Kafka
Microsecond latency required. IoT/edge with intermittent connectivity. Many topics, low msg-per-topic rate (Kafka has overhead per topic; NATS doesn't). Service-to-service request/reply (NATS has it natively).