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
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
Known 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
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp