Back to docs
Recipe: Async stand-up update writer
Build a non-blocking update pipeline that writes stand-up snapshots to Upstash KV without blocking the request path.
Overview
When a user submits a daily stand-up, the write must land in KV before the next read. Blocking the HTTP response on that write adds latency the user feels. This recipe offloads the KVSETto a background queue drained by a single async worker, so the API returns instantly.
Architecture
- In-memory ring buffer holds pending writes (max 256 entries).
- Single worker goroutine drains the buffer every 50 ms.
- Exponential backoff with jitter on KV failures.
- Circuit breaker opens after 5 consecutive errors, auto-resets after 30 s.
Key decisions
At-most-once delivery is acceptable because the next stand-up submission overwrites the same key. No need for a persistent outbox.
No Vercel Edge — the worker runs in the Node.js runtime where Upstash Redis client keepalive works reliably.
Graceful shutdown drains the buffer on SIGTERM before the process exits.
Quick start
- Create
lib/update-writer.ts. - Import and call
enqueue(standup)from your API route. - Start the worker in
instrumentation.ts.