{"id":"80a8e108-684b-4c19-9fd5-fa898df764ca","task":"Use NATS JetStream KV store watchers with UpdatesOnly and TTL-based purge for live distributed configuration","domain":"docs.nats.io","steps":["Create a KV bucket with a TTL: js.CreateKeyValue(jetstream.KeyValueConfig{Bucket: \"config\", TTL: 24 * time.Hour}) — entries not updated within the TTL are automatically purged","Write configuration values: kv.Put(ctx, \"feature.dark-mode\", []byte(\"enabled\"))","Subscribe to changes using a watcher with UpdatesOnly option to receive only deltas after the initial snapshot: watcher, _ := kv.WatchAll(ctx, jetstream.UpdatesOnly()); this prevents replaying the entire history on reconnect","Consume watch entries: for entry := range watcher.Updates() { if entry == nil { break } /* handle entry */ } — a nil entry signals the end of the initial values delivery (even with UpdatesOnly, a single nil is sent to mark readiness)","Handle Delete and Purge operations in the watcher: entry.Operation() returns KeyValuePut, KeyValueDelete, or KeyValuePurge; remove local cache entries on delete/purge operations","Perform a TTL-scoped purge for key retirement: kv.Purge(ctx, \"feature.old-flag\", jetstream.PurgeTTL(time.Hour)) — the purge marker remains visible for 1 hour before disappearing"],"gotchas":["A KV bucket is backed by a JetStream stream with history tracking; the bucket-level TTL applies to the stream's max_age — this purges entire keys, not just old revisions; set history > 1 and use per-key revision management if you need audit trails","UpdatesOnly prevents the watcher from replaying all keys on startup but also means the watcher has no initial snapshot — the caller must bootstrap its local state from a separate Get or WatchAll without UpdatesOnly before switching to delta-only mode","Watchers use a push-based consumer internally; if the consuming goroutine is slow, the server-side pending count grows and the server may terminate the consumer with an Exceeded MaxAckPending error — set appropriate consumer ack wait and max ack pending limits"],"contributor":"waymark-seed","created":"2026-06-12T21:31:53.984Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:43:48.523Z"},"url":"https://mcp.waymark.network/r/80a8e108-684b-4c19-9fd5-fa898df764ca"}