Production deployment is a system of frontend, API, database, DNS, secrets, migrations, and observability rather than one deploy button.
Course navigationPhase 34⌄
Production Deployment
Deploy the real topology—Next.js, NestJS image, Supabase services, migrations, domains/TLS/CORS, secrets, health checks, smoke tests, and rollback—as one release system.
Phase outcome and project increment
Learning outcome
Deploy the real topology—Next.js, NestJS image, Supabase services, migrations, domains/TLS/CORS, secrets, health checks, smoke tests, and rollback—as one release system.
Concrete deliverable
Staging and production deployment runbooks with release identity, environment matrix, smoke tests, and rollback procedure.
Principles to keep while coding
Apply database migrations in a controlled step before code depends on the new schema.
Use environment-specific configuration while keeping the same tested application artifact where possible.
Plan smoke tests and rollback before release so recovery is part of deployment design.
Guided phase lab
Do these in order. Each step should end with evidence before the next one starts.
- 01
Create separate staging/production environment matrices before entering any dashboard values.
- 02
Deploy Next.js from the intended monorepo root with public/server env vars separated.
- 03
Deploy the exact API container artifact and verify bind address, PORT, and readiness endpoint.
- 04
Apply database migrations as a controlled release step and document backward-compatibility assumptions.
- 05
Configure custom domains/TLS and the exact CORS/redirect origins for production.
- 06
Run a smoke-test checklist and practice rollback of code while reasoning about whether the database migration is reversible.
Failures you should know how to diagnose
Preview deployment points to production database
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Secrets copied into source or image
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Code deploy occurs before required migration or vice versa without compatibility plan
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Rollback plan assumes schema can always be downgraded
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Lessons
The source chapters come first. Every phase now ends with a guided build, a debugging workshop, and an independent challenge so reading turns into transferable skill.
Production Topology Environments and Release Identity
Production Topology, Environments, and Release Identity Use distinct local, staging, and production environments so a preview does not accidentally point at production data. Keep the deploym
Vercel Next.js Production Deployment
Vercel: Deploy the Next.js Application For the course topology, Vercel deploys the Next.js application natively from the verified repository commit. In a monorepo, point the Vercel project a
Railway NestJS API Deployment
Railway: Deploy the NestJS API from GHCR The API follows the build-once path from Phase 33: Railway pulls the exact GHCR image tagged with the Git SHA. When Railway uses a Docker-image sourc
Supabase Production Project and Database
Supabase Production Project and Database Configuration Create a production Supabase project separate from local/staging. Production schema changes come from version-controlled migrations; th
Environment Secrets Domains TLS and CORS
Environment Variables, Secrets, Domains, TLS, and CORS Configuration is environment-specific; secrets are never browser configuration. Both Vercel and Railway can provision HTTPS for custom
Supabase Auth Redirects Cookies and Sessions
Supabase Auth: Redirect URLs, Site URL, Cookies, and Sessions Authentication often breaks only after deployment because localhost redirect assumptions remain in the Auth project. Production
Migration Order Backward Compatibility and Release Sequence
Migration Order, Backward Compatibility, and Release Sequence Database deployment is where rollback gets difficult. Prefer expand-migrate-contract changes so the old application and the new
Health Readiness Zero Downtime and Graceful Shutdown
Health, Readiness, Zero-Downtime Promotion, and Graceful Shutdown A process can be alive but not ready. Deployment platforms should route traffic only after the new version is ready, and the
Storage Realtime and Production Service Configuration
Storage and Realtime Production Configuration The production Supabase project must carry the same security architecture already established for Storage and Realtime. Deployment is where loca
Post Deploy Smoke Tests and Observability
Post-Deploy Smoke Tests and Observability A platform saying "deployed" means the platform started the artifact. It does not prove TaskFlow works end to end. Every release therefore ends with
Rollback Recovery and Incident Decisions
Rollback, Recovery, and Incident Decisions A rollback plan must exist before the release. Roll back application code quickly when code/config is the cause; treat database/schema incidents se
Production Launch Runbook and Phase Exit
Production Launch Runbook and Phase Exit The final lab turns the deployment architecture into a checklist a team can actually follow. The release is complete only when application behavior,
Guided Build Lab
Purpose Deploy the real topology—Next.js, NestJS image, Supabase services, migrations, domains/TLS/CORS, secrets, health checks, smoke tests, and rollback—as one release system.
Debugging Workshop
Goal Learn to diagnose this phase's failures systematically instead of reinstalling packages, changing random configuration, or copying a fix without understanding it.
Phase Synthesis & Independent Challenge
Mission Rebuild the capability of Phase 34 without following the exact code line-by-line. The goal is transfer: can you use the ideas when the variable names, UI, or route shape changes?
Mastery Capstone Lab
Integrate Phase 34 without following a transcript.
Exercises that increase independence
Create separate staging/production environment matrices before entering any dashboard values.
Deploy the exact API container artifact and verify bind address, PORT, and readiness endpoint.
reproduce and diagnose — Preview deployment points to production database.
deliver Staging and production deployment runbooks with release identity, environment matrix, smoke tests, and rollback procedure.
Can describe the whole topology and Can separate environment configuration.
Do not leave the phase only because you reached the bottom
Phase exit criteria
Scenario and concept quiz
These questions test engineering choices rather than whether you remember a lesson title.
Reference files
Attempt the work first. Use snapshots to compare a checkpoint, not as a substitute for understanding.
reference/TaskFlow_Production_Deployment_Snapshot/DEPLOYMENT_RUNBOOK.md
# TaskFlow Production Deployment Runbook ## Preflight 1. Required CI checks are green for the exact release commit. 2. Verify production environment variables and secret scopes. 3. Verify Supabase production Site URL and redirect allowlist. 4. Confirm recovery posture: recent backup/PITR where required. 5. Review Prisma migrations for backward compatibility. ## Deploy 1. Run `prisma migrate deploy` as a one-off production migration job. 2. Promote the exact API image `sha-<commit>` to Railway. 3. Wait for `/health/ready` to pass. 4. Promote/deploy the matching verified web commit on Vercel. 5. Run smoke tests. 6. Observe 5xx, p95 latency, readiness, database signals, and Sentry. ## Rollback - If API code/config is broken, roll Railway back to the last known-good deployment/image and rerun smoke tests. - If web code/config is broken, promote a known-good previous Vercel deployment/commit.
reference/TaskFlow_Production_Deployment_Snapshot/PRODUCTION_ENV_MATRIX.md
# Production Environment Matrix | Variable | Web | API | Secret? | Notes | |---|---:|---:|---:|---| | NEXT_PUBLIC_SITE_URL | yes | no | no | Canonical web origin | | NEXT_PUBLIC_API_URL | yes | no | no | Public API origin | | NEXT_PUBLIC_SUPABASE_URL | yes | no | no | Public project URL | | NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY | yes | no | no | Browser-safe public key | | DATABASE_URL | no | yes | yes | Production Postgres connection | | SUPABASE_URL | no | yes | no | Production project URL | | SUPABASE_SERVICE_ROLE_KEY | no | yes | yes | Server only | | CORS_ORIGIN | no | yes | no | Exact production web origin | | SENTRY_DSN | as needed | as needed | treat carefully | Production telemetry | Never use `NEXT_PUBLIC_` for database credentials, service-role keys, registry tokens, or other secrets.
reference/TaskFlow_Production_Deployment_Snapshot/PRODUCTION_TOPOLOGY.md
# TaskFlow Production Topology - Web: `https://app.taskflow.example.com` -> Vercel (`apps/web`) - API: `https://api.taskflow.example.com` -> Railway Docker image service - Data/Auth/Storage/Realtime: separate production Supabase project ## Environment rule Local, staging, and production use separate configuration. Preview deployments must not receive production credentials merely for convenience. ## Release identity Use the same Git commit SHA in API image tags, release notes, error monitoring, and deployment records.
reference/TaskFlow_Production_Deployment_Snapshot/README.md
# TaskFlow Production Deployment Snapshot This snapshot is a study/reference package for Phase 34. Replace `taskflow.example.com`, project references, image paths, and secrets with real environment values. Primary course topology: - Next.js -> Vercel - NestJS/Fastify -> Railway from GHCR SHA image - PostgreSQL/Auth/Storage/Realtime -> Supabase production project Render is documented as an API-host alternative.
reference/TaskFlow_Production_Deployment_Snapshot/SOURCES.md
# Source Notes Current source basis verified during Phase 34 generation: - Vercel environment configuration and deployment protection guidance. - Railway Docker-image sources, GHCR private registries, deployment health checks, domains, rollback behavior. - Render Docker web-service and HTTP health-check documentation as the API-host alternative. - Supabase production checklist, shared responsibility model, maturity model, Auth redirect URLs, and security configuration guidance. The course topology and release decisions remain TaskFlow architecture choices; provider behavior should be rechecked before a future production launch because cloud platforms evolve.
reference/TaskFlow_Production_Deployment_Snapshot/SUPABASE_PRODUCTION_CHECKLIST.md
# Supabase Production Checklist for TaskFlow - Use a production project separate from local/staging. - Set Auth Site URL to the canonical production web origin. - Add exact production Auth redirect paths. - Review Security Advisor and Performance Advisor. - Apply schema through version-controlled migrations. - Verify indexes and connection topology under expected load. - Configure private Storage bucket rules used by Task attachments. - Deploy Realtime Broadcast triggers and authorization policies. - Review backups/PITR and access controls appropriate to the business.
reference/TaskFlow_Production_Deployment_Snapshot/apps/api/main.production.example.ts
// Production binding example - adapt to the existing TaskFlow main.ts. const host = '0.0.0.0'; const port = Number(process.env.PORT ?? 3001); await app.listen(port, host);
reference/TaskFlow_Production_Deployment_Snapshot/apps/api/railway.production.env.example
NODE_ENV=production # PORT is injected by Railway. The app must listen on 0.0.0.0:$PORT. DATABASE_URL=replace-with-production-connection SUPABASE_URL=https://PROJECT_REF.supabase.co SUPABASE_PUBLISHABLE_KEY=replace-with-public-key SUPABASE_SERVICE_ROLE_KEY=replace-with-server-only-secret CORS_ORIGIN=https://app.taskflow.example.com # SENTRY_DSN=...
reference/TaskFlow_Production_Deployment_Snapshot/apps/web/vercel.production.env.example
NEXT_PUBLIC_SITE_URL=https://app.taskflow.example.com NEXT_PUBLIC_API_URL=https://api.taskflow.example.com NEXT_PUBLIC_SUPABASE_URL=https://PROJECT_REF.supabase.co NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=replace-with-public-key # SENTRY_DSN=...
reference/TaskFlow_Production_Deployment_Snapshot/infra/railway-service-notes.md
# Railway API Service - Source: Docker Image - Image: `ghcr.io/<org>/<repo>-api:sha-<full-commit>` - Healthcheck: `/health/ready` - Public domain: `api.taskflow.example.com` - Keep GHCR pull credentials read-only. - Do not use `:latest` for production application releases. - Railway health checks gate new deployments before traffic promotion.
reference/TaskFlow_Production_Deployment_Snapshot/infra/render-alternative.md
# Render Alternative for the API Render can host the NestJS Docker web service as an alternative to Railway. Configure the service to listen on `0.0.0.0` and the platform port, set an HTTP health-check path such as `/health/ready`, and attach the custom API domain. Render uses health checks when deciding whether a new web-service deployment can receive traffic. Keep the same application-level architecture and production environment separation regardless of platform.
reference/TaskFlow_Production_Deployment_Snapshot/tests/production-smoke-tests.ps1
param( [string]$Web = "https://app.taskflow.example.com", [string]$Api = "https://api.taskflow.example.com" ) $ErrorActionPreference = "Stop" Write-Host "Checking API liveness..." Invoke-WebRequest "$Api/health/live" -UseBasicParsing | Out-Null Write-Host "Checking API readiness..." Invoke-WebRequest "$Api/health/ready" -UseBasicParsing | Out-Null Write-Host "Checking web sign-in route..." Invoke-WebRequest "$Web/sign-in" -UseBasicParsing | Out-Null Write-Host "PASS: unauthenticated production smoke checks" Write-Host "Run the authenticated smoke flow separately with a controlled test identity."
reference/TaskFlow_Production_Deployment_Snapshot/tests/production-test-matrix.md
# Production Verification Matrix | Check | Expected | |---|---| | Web custom domain | HTTPS + expected production app | | API `/health/live` | 2xx | | API `/health/ready` | 2xx when DB is available | | Auth sign in | Session established | | Auth confirmation/reset | Returns to production domain | | GET /tasks as member | Only authorized rows | | Cross-workspace ID | 403/404 according to policy | | Create/update test Task | Persists after reload | | Attachment flow | Private upload/download works | | Realtime flow | Authorized peer receives refresh signal | | 5xx / Sentry | No unexpected release regression | | Rollback rehearsal | Known-good version restored |