Deployment Recipe: Vercel (Optional Target)
Support Tier: Tier 1 — Officially Tested & Supported Adapter
Target Platform: Vercel Serverless Edge Platform (Node.js runtime)
Overview
Vercel provides a low-friction deployment target for Next.js applications. The application architecture treats Vercel as an optional adapter rather than an architectural default: all core business logic, ORM access, validation, and storage mechanisms remain provider-agnostic and avoid vendor lock-in.
1. Database Provisioning & Connection
Serverless environments require connection pooling to prevent exhausting PostgreSQL client connection limits.
Recommended Providers
- Neon Serverless PostgreSQL: Provides native connection pooling (
@neondatabase/serverlessor PgBouncer mode). - Supabase PostgreSQL: Use Supabase Transaction Pooler (port
6543). - AWS Aurora Serverless v2 / RDS Proxy: Configure RDS Proxy for connection pooling.
Connection Configuration
In prisma.config.ts, datasource.url is bound to DATABASE_URL and datasource.shadowDatabaseUrl is bound to POSTGRES_URL_NON_POOLING (used by local prisma migrate dev). Because npx prisma migrate deploy always reads DATABASE_URL, store both pooled and direct connection strings in Vercel Environment Variables so the build command can explicitly override DATABASE_URL during schema migrations:
DATABASE_URL(Pooled Connection for Serverless Runtime):envDATABASE_URL="postgresql://user:pass@ep-example.us-east-1.aws.neon.tech/wedding_db?sslmode=require&pgbouncer=true"POSTGRES_URL_NON_POOLING(Direct Connection for Shadow DB & ExplicitDATABASE_URLMigration Override):envPOSTGRES_URL_NON_POOLING="postgresql://user:pass@ep-example-direct.us-east-1.aws.neon.tech/wedding_db?sslmode=require"
2. Vercel Environment Variables & Serverless Secrets
For the complete environment variable matrix, defaults, and persisted prisma/schema.prisma entity rules, refer to the Application Runtime Contract. Configure the following Vercel-specific settings in Vercel Project Settings > Environment Variables (Production and Preview):
- Database Pooling & Build-Time Migration URLs: Set
DATABASE_URLto your pooled PostgreSQL connection string (datasource.urlinprisma.config.ts) and setPOSTGRES_URL_NON_POOLINGto your direct PostgreSQL connection string (datasource.shadowDatabaseUrlinprisma.config.ts) so the Vercel build command can explicitly overrideDATABASE_URLduringnpx prisma migrate deploy. - Production Auth & Host Security: Set
ADMIN_PASSWORD(scrypt:[saltBase64]:[keyBase64]),ALLOWED_HOSTS(your custom domain plus*.vercel.app),TRUST_PROXY=1(for single-hop Vercel edge ingress, or2behind an external CDN/proxy),GUEST_PASSCODE, andGUEST_SESSION_SECRET(32+ characters, distinct fromGUEST_PASSCODE; Vercel setsNODE_ENV=productionautomatically). - Serverless Object Storage & Scheduled Cron:
- Because Vercel Serverless Functions cannot persist files to local disk, configure
S3_BUCKET,S3_REGION,S3_ACCESS_KEY_ID, andS3_SECRET_ACCESS_KEY(plus optionalS3_ENDPOINTandS3_PUBLIC_URL) for file upload features. - Set
CRON_SECRETso Vercel Cron (vercel.json) automatically attachesAuthorization: Bearer <CRON_SECRET>when invoking/api/cron/broadcasts, and optionally setSTRIPE_SECRET_KEY,NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY, andSTRIPE_WEBHOOK_SECRETfor online card checkout.
- Because Vercel Serverless Functions cannot persist files to local disk, configure
3. Migration Mechanism
Because Vercel serverless functions do not execute container entrypoint scripts, migrations are run during the Vercel deployment build step or via a pre-deployment GitHub Actions step.
Build Command Migration Setup
In prisma.config.ts, prisma migrate deploy reads DATABASE_URL (datasource.url), while POSTGRES_URL_NON_POOLING is bound to datasource.shadowDatabaseUrl (and Prisma 7 raises P3025 if both resolve to the same database URL). To bypass transaction-mode PgBouncer advisory lock limitations during schema updates, pass an explicit DATABASE_URL override and unset POSTGRES_URL_NON_POOLING for the migration subprocess in Vercel Project Settings > Build & Development Settings > Build Command:
DATABASE_URL="${POSTGRES_URL_NON_POOLING:-$DATABASE_URL}" env -u POSTGRES_URL_NON_POOLING npx prisma migrate deploy && next buildSupplying DATABASE_URL="${POSTGRES_URL_NON_POOLING:-$DATABASE_URL}" env -u POSTGRES_URL_NON_POOLING routes prisma migrate deploy directly to the unpooled PostgreSQL endpoint (while falling back to prisma.config.ts's placeholder shadow URL) and leaves the pooled DATABASE_URL intact for next build and serverless runtime invocations.
4. Asset Storage
Serverless execution environments have ephemeral local storage (/tmp only). All persistent media uploads are handled via the provider-agnostic S3 storage client (@aws-sdk/client-s3).
- Provision a bucket on Cloudflare R2, Google Cloud Storage (with S3 Interoperability enabled), or AWS S3.
- Configure the six
S3_*environment variables (S3_BUCKET,S3_REGION,S3_ACCESS_KEY_ID,S3_SECRET_ACCESS_KEY,S3_ENDPOINT, andS3_PUBLIC_URL) in Vercel Project Settings:- Cloudflare R2: Set
S3_BUCKET,S3_REGION=auto,S3_ACCESS_KEY_ID,S3_SECRET_ACCESS_KEY,S3_ENDPOINT=https://<ACCOUNT_ID>.r2.cloudflarestorage.com, andS3_PUBLIC_URL=https://assets.wedding.mydomain.com(an R2 Custom Domain or publichttps://pub-<id>.r2.devURL; private*.r2.cloudflarestorage.comendpoints requireS3_PUBLIC_URL). - Google Cloud Storage (S3 Interoperability): Enable Cloud Storage HMAC keys and set
S3_BUCKET,S3_REGION=us-central1(matching your bucket region),S3_ACCESS_KEY_ID,S3_SECRET_ACCESS_KEY,S3_ENDPOINT=https://storage.googleapis.com, and optionalS3_PUBLIC_URL. - AWS S3: Set
S3_BUCKET,S3_REGION,S3_ACCESS_KEY_ID, andS3_SECRET_ACCESS_KEY(withS3_ENDPOINTomitted andS3_PUBLIC_URLoptional for CloudFront).
- Cloudflare R2: Set
- Uploads streaming through
/api/admin/uploadand/api/guest/photos/uploadwrite directly to object storage and generate public CDN URLs.
5. Custom Domain & TLS
Vercel provides automated global CDN edge routing and SSL/TLS certificate management via Let's Encrypt / DigiCert.
- Go to Vercel Dashboard > Project > Settings > Domains.
- Add your custom domain (e.g.,
wedding.mydomain.com). - Set the DNS record at your domain registrar:
- For apex domains:
Arecord pointing to76.76.21.21. - For subdomains:
CNAMErecord pointing tocname.vercel-dns.com.
- For apex domains:
- Vercel issues SSL certificates automatically upon DNS verification.
6. Build & Deploy Commands
Automated Deployments via Git Integration
Connect your GitHub repository to Vercel. Pushes to the main branch trigger production builds automatically.
Manual Deployment via Vercel CLI
# Install Vercel CLI
npm install -g vercel
# Authenticate and link project
vercel login
vercel link
# Pull environment variables locally for testing
vercel env pull .env.production.local
# Deploy to production
vercel --prod7. Health Checks
Vercel Serverless Functions respond to HTTP requests routed to the /api/health endpoint.
- Endpoint Path:
https://wedding.mydomain.com/api/health - Probe Mechanism: Use external uptime monitors (BetterStack, Datadog, Healthchecks.io, or UptimeRobot) to send periodic GET requests.
- Expected Payload:json
{ "success": true, "data": { "status": "ok", "timestamp": "2026-09-30T14:30:00.000Z", "database": "connected" } }
8. Rollback Strategy
Vercel stores all historical deployment artifacts indefinitely.
Instant Rollback Procedure
- Navigate to Vercel Dashboard > Deployments.
- Locate the last known good deployment.
- Click the
...context menu and select Promote to Production. - Traffic is instantly switched to the selected build artifact in under 1 second.
Alternatively, execute via Vercel CLI:
vercel rollback [DEPLOYMENT_ID]9. Webhooks & Scheduled Background Jobs
Stripe payment_intent.succeeded Webhook
- Configure
STRIPE_SECRET_KEY,NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY, andSTRIPE_WEBHOOK_SECRET(whsec_...) in Vercel Project Settings > Environment Variables. - In Stripe Dashboard > Developers > Webhooks, register
https://wedding.mydomain.com/api/registry/webhook/stripe(matchingALLOWED_HOSTS) and subscribe topayment_intent.succeeded. src/middleware.tsexempts/api/registry/webhook/stripefrom session cookies while enforcingALLOWED_HOSTS, and the webhook handler verifiesstripe-signatureagainstSTRIPE_WEBHOOK_SECRET.
Vercel Cron for Scheduled Broadcasts (vercel.json & CRON_SECRET)
The repository includes a root vercel.json configuring Vercel Cron to invoke /api/cron/broadcasts:
{
"crons": [
{
"path": "/api/cron/broadcasts",
"schedule": "0 14 * * *"
}
]
}- Set
CRON_SECRET(at least 16 random characters) in Vercel Project Settings > Environment Variables (Production). Vercel Cron automatically attachesAuthorization: Bearer <CRON_SECRET>on scheduledGET /api/cron/broadcastsinvocations, whichsrc/app/api/cron/broadcasts/route.tsverifies with constant-time comparison. - Ensure your primary Vercel production domain (and
*.vercel.appif applicable) is listed inALLOWED_HOSTSsosrc/middleware.tspermits incoming Vercel Cron requests. - The default
0 14 * * *(14:00 UTC daily) schedule is compatible with Vercel Hobby accounts (which cap cron frequency to once per day); Vercel Pro / Enterprise deployments can tightenscheduleinvercel.json(e.g.,*/5 * * * *) for near-real-time broadcast dispatch.
10. Provider-Specific Limitations
- Function Execution Timeout: Serverless functions have execution timeout limits (10s on Free, 60s on Pro, 300s on Enterprise). Long-running scraper jobs or bulk exports must finish within these bounds.
- Connection Exhaustion: Connecting directly to PostgreSQL without connection poolers (PgBouncer/Neon) will quickly exhaust database connections under concurrent traffic. Always set up connection pooling.
- No Local State: Local file uploads and general 100 req/min in-memory rate-limit caches are not shared across serverless function invocations (authentication lockouts synchronize via PostgreSQL).
- Vendor Isolation Policy: To maintain vendor independence, do not import
@vercel/postgresor@vercel/blobSDKs in core business code; consume the shared standard Prisma and AWS S3 SDK abstractions instead.