Overview
calado batches in memory and flushes every 5 seconds on a timer. Serverless runtimes freeze between invocations, so that timer often never fires and events get stranded in a dead queue. The fix is to callcalado.flush() before your handler returns. How you do that depends on the runtime.
Next.js App Router
Use Next’safter() helper. It runs after the response is sent, so the user doesn’t wait on the flush.
Vercel Edge / Next.js Edge runtime
Usectx.waitUntil so the platform keeps the worker alive until the flush resolves.
AWS Lambda
Flush in afinally block so it runs on both success and error paths.
Cloudflare Workers
Same pattern as Vercel Edge. Workers providectx.waitUntil on the request handler’s second argument.
Long-running Node processes
If your server stays warm between requests (Express, Fastify, a worker process), the default 5-second flush timer handles everything. You don’t need to callflush() manually.
On graceful shutdown, call await calado.shutdown() to flush and clear timers.
Tuning batch size and flush interval
If you’re sending many events and want lower latency, lower the batch size or flush interval.flushInterval: 0 to disable the timer entirely. Use this in serverless setups where you always flush manually.
See Node.js SDK → Init options for the full list.