0%
Vibe44 Logo

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:

  1. Stops accepting new jobs
  2. In-progress jobs get grace period to complete
  3. 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.

  1. QStash sends HTTP POST
  2. Endpoint processes → response
  3. Unavailable = QStash retries automatically

Data Safety:

  • At-least-once delivery guaranteed
  • receiver.ts verifies 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:

  1. Active requests complete (up to timeout)
  2. New requests route to new deployment immediately
  3. No SIGTERM to individual functions — they complete or timeout

Data Safety:

  • Drizzle transactions for multi-step operations
  • Webhook idempotency via webhook_logs success 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:

  1. Pool drains active queries
  2. Idle connections closed
  3. 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

  1. Zero-downtime — Vercel handles blue-green deployments automatically
  2. Migrations — Run via drizzle-kit push before deploying new code
  3. Env vars — Update in Vercel dashboard before deployment
  4. Feature flags — Gate new features via lib/config.ts during 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.