Graceful Shutdown
Mishandling of Exceptional Conditions. Shutdown behavior and data safety for all background systems.
Systems
1. Trigger.dev (Background Jobs)
Shutdown: SDK registers SIGTERM + SIGINT automatically. When Vercel sends SIGTERM:
- Stops accepting new jobs
- In-progress jobs get grace period to complete
- Unfinished jobs marked for retry
Data Safety:
- Idempotent by design — safe to retry
- State in Trigger.dev cloud, not in-process
- Failed jobs auto-retry with exponential backoff
Risk: Minimal. Managed infrastructure handles this.
2. QStash (Delayed Messages / Webhooks)
Shutdown: Fully HTTP-based. No persistent connections. No in-process state.
- QStash sends HTTP POST
- Endpoint processes → response
- Unavailable = QStash retries automatically
Data Safety:
- At-least-once delivery guaranteed
receiver.tsverifies signatures before processing- Retry-safe idempotency checks in webhook/payment handlers
Risk: None. Retry + signature verification = inherently safe.
3. ️ Vercel Serverless Functions
Shutdown: Max execution (10s Hobby, 60s Pro, 900s Enterprise). On redeployment:
- Active requests complete (up to timeout)
- New requests route to new deployment immediately
- No
SIGTERMto individual functions — they complete or timeout
Data Safety:
- Drizzle transactions for multi-step operations
- Webhook idempotency via
webhook_logssuccess skip, active-processing skip, and failed/stale retry - Server Actions return
{ success: false }on timeout — no partial state
Risk: Low. Stateless = no in-process state survives between invocations.
4. ️ Database (Drizzle + PostgreSQL)
Shutdown: Connection pool via postgres driver:
- Pool drains active queries
- Idle connections closed
- Driver handles cleanup automatically
Data Safety:
- ACID transactions — partial commits impossible
- Pool exhaustion returns error, doesn't corrupt
- RLS enforces integrity regardless of connection state
Risk: Minimal. PostgreSQL ACID guarantees prevent corruption.
5. Supabase Realtime
Shutdown: Subscriptions are client-side (browser). Server maintains no persistent WebSocket connections.
Risk: None server-side. Client auto-reconnects via Supabase SDK.
Deployment Checklist
- Zero-downtime — Vercel handles blue-green deployments automatically
- Migrations — Run via
drizzle-kit pushbefore deploying new code - Env vars — Update in Vercel dashboard before deployment
- Feature flags — Gate new features via
lib/config.tsduring rollout
Monitoring
- Sentry — captures unhandled exceptions during shutdown
- QStash dashboard — delivery status + retry attempts
- Trigger.dev dashboard — job completion + failure rates
auth_events— security events with timestamps for post-incident analysis
Copyright © 2026 Vibe44. Built with ❤️ by Scale with Alap.