A file is uploaded. The user interface should immediately show that the upload is complete. In the background, a worker needs to generate a preview. Both tasks start with a message. The interface can reload its current state the next time it opens. The preview service must still receive its job if it happens to be restarting when the upload completes.
NATS is a lightweight messaging system. Services publish messages to named channels called subjects, and other services subscribe to the subjects they need. Core NATS delivers messages to connected clients. JetStream adds server-side storage so consumers can resume processing after an interruption. At ayedo, we offer NATS as a managed app on Kubernetes in Germany. Managed NATS at ayedo · JetStream documentation
Three tasks and their delivery models
| Task | Delivery model | What happens after an interruption |
|---|---|---|
| Tell the interface that the upload finished | Core NATS on media.live.uploaded |
Connected recipients get the notification. After an interruption, the interface reloads its current state from the API. |
| Generate a preview | JetStream with a durable pull consumer named preview-workers |
The consumer retains its progress. Multiple workers can share the jobs. |
| Record uploads for analytics | A separate JetStream consumer on the same stream | The analytics service reads events at its own pace and can replay them within the retention limits. |
For previews and analytics, the MEDIA stream can store messages published to media.events.uploaded. Each message contains an event ID, the object key, and the version of the source file. The file itself stays in object storage. Limits retention lets both consumers read independently and keeps events available for replay. The message age, count, and size limits determine how far back that replay can go. JetStream streams and retention
A worker can receive the same job more than once
The preview service fetches small batches from the pull consumer. It uses AckExplicit to acknowledge each message after saving the preview durably. If the acknowledgement does not arrive within the configured time, JetStream can redeliver the job. MaxAckPending limits outstanding acknowledgements across all workers sharing the same consumer. JetStream pull consumers
The critical test is the gap between saving and acknowledging. If a worker saves the preview and crashes before the ack, another worker can receive the same job. The service can derive the destination key from the source file, its version, and the preview format. On redelivery, it can recognize a completed preview. On the publisher side, use a stable Nats-Msg-Id when retrying after a dropped connection. JetStream deduplicates that ID within the configured window. The worker still needs its own protection against duplicate processing. JetStream headers and deduplication
For jobs that repeatedly fail, MaxDeliver limits delivery attempts. BackOff sets the delays when acknowledgement times out. A negative acknowledgement triggers immediate redelivery by default. The client can explicitly request a different delay. When the final attempt is exhausted, the message stays in the stream subject to its retention rules. Plan a separate path if those jobs need to go to an error queue. JetStream consumer configuration
Retention determines how long a service can be offline
An average of 200 events per second at 1 KiB per event produces about 16.5 GiB of payload data in 24 hours. With three full stream replicas, that comes to about 49.4 GiB across all replicas, before metadata, traffic spikes, and spare capacity.
Start by deciding how far behind the slowest consumer can fall. If MaxBytes is too small, DiscardOld can evict the oldest message before it reaches MaxAge. With DiscardNew, JetStream rejects new publishes when it hits a configured capacity limit. Choose based on whether the workload needs older events for replay or needs to keep accepting new ones during a backlog. Stream limits and discard policies
Configure the stream for Kubernetes operations
The ayedo Polycrate block documents how to configure NATS clustering and JetStream. Its example uses the memory store. For events that need to survive a full restart, use file storage on persistent volumes. Configure the number of stream replicas separately. A three-replica stream can maintain a majority with two replicas after one server fails. During the pilot, check that the replicas are placed so the failure you are testing affects only one of them. NATS in the ayedo Polycrate Hub · NATS clustering and replication
With Managed NATS, ayedo handles operations on Kubernetes in Germany. Your team decides which services can publish or subscribe on each subject, which events to store, and how long consumers need to catch up. Start with a message flow you can test during an outage. Stop the preview service, accept more uploads, and check after restarting it that every job completes within the expected time. Managed NATS at ayedo
Want to connect services with NATS or make jobs durable with JetStream? Talk to us about your message flow and the right operating model.