Understand streams, push vs pull consumers, KV store, delivery guarantees, and how JetStream extends core NATS with persistence and acknowledgement.
0 / 5 completed
1 / 5
How does NATS JetStream differ from core NATS Pub/Sub?
JetStream vs core NATS: core NATS is extremely fast but ephemeral — if no subscriber is listening, messages are lost. JetStream persists messages to disk/memory streams, tracks consumer positions, and supports acknowledgements. This makes JetStream suitable for work queues, event sourcing, and audit logs while retaining NATS's low-latency characteristics.
2 / 5
What is a NATS JetStream stream and how are subjects mapped to it?
JetStream stream: a stream named ORDERS with subjects ["orders.>"] captures orders.created, orders.updated, and orders.shipped in one store. Retention policies control eviction: MaxAge: 7d deletes old messages, MaxBytes: 10GB caps storage. Streams can have replicas across NATS cluster nodes for fault tolerance.
3 / 5
What is the difference between push and pull consumers in NATS JetStream?
Push vs pull consumers: push consumers are simple but can overwhelm slow subscribers. Pull consumers are preferred for work queues — multiple instances call Fetch(batch) and only receive what they can process, with the server balancing work across pullers. Pull consumers also work well behind load balancers and in Lambda-style functions.
4 / 5
What is the NATS JetStream Key-Value store and how is it implemented?
NATS KV:js.CreateKeyValue(nats.KeyValueConfig{Bucket: "config"}) creates a KV bucket. kv.Put("feature_flag", []byte("true")) stores a value. kv.Watch("feature_flag") returns a watcher that delivers updates in real time — useful for distributed configuration management. History depth preserves past values for audit or rollback.
5 / 5
What delivery guarantees does NATS JetStream provide and how are they controlled?
JetStream delivery guarantees: at-least-once: consumers acknowledge with msg.Ack(); unacknowledged messages are redelivered after AckWait timeout. Exactly-once: publishers send with a Nats-Msg-Id header; JetStream deduplicates within a window. Consumers implement idempotent processing. The combination prevents both message loss (at-least-once) and duplicate processing (idempotent consumer).