Prompt
My app keeps failing during deploys, how do I troubleshoot SaaS deployment issues?
Latest observation
Here’s a practical way to troubleshoot SaaS deployment issues without getting lost in the weeds.
1) Start with the exact failure point
Identify whether the deploy is failing in:
- Build: dependency install, compile, asset generation
- Test: unit/integration tests failing
- Release: migrations, startup checks, config validation
- Runtime: app deploys but crashes, returns errors, or behaves incorrectly
This narrows the problem fast.
2) Read the logs from the bottom up
Look for:
- The first real error, not just the final “deployment failed” message
- Stack traces, exit codes, missing env vars, permission errors, timeout errors
- Any differences between successful and failed deploys
Helpful patterns:
MODULE_NOT_FOUND/ missing packagepermission deniedfailed to connecttimeoutmigration failedexit code 1/137/139
3) Compare working vs failing deploys
Check what changed:
- Code commit
- Dependency updates
- Environment variables
- Secret rotation
- Platform/config changes
- Database schema changes
- Resource limits or scaling settings
A surprising number of deploy issues are caused by “small” config changes rather than code bugs.
4) Verify environment variables and secrets
Common SaaS deploy breakage comes from:
- Missing env vars in production
- Wrong secret values
- Stale rotated credentials
- Different values between staging and production
- Typos in variable names
Make sure your app validates required config at startup and fails loudly with a clear message.
5) Check infrastructure and platform limits
Look for:
- CPU/memory limits causing OOM kills
- Disk space exhaustion
- Concurrency or file descriptor limits
- Container image size issues
- Health check timeouts
- Cold start delays
If you see 137, that often points to memory-related termination.
6) Look at database and migration issues
Very common deploy failures include:
- Migration order problems
- Long-running migrations timing out
- Backward-incompatible schema changes
- Lock contention
- Permissions to run migrations
- App expecting a schema that doesn’t exist yet
Best practice:
- Use backward-compatible migrations
- Deploy code and schema in a compatible sequence
- Avoid destructive schema changes during the same release if possible
7) Reproduce locally or in staging
Try to make the issue happen in a controlled environment:
- Use the same build command
- Use the same runtime version
- Use production-like env vars
- Use a copy of the failing config
- Recreate the container/image if possible
If it only fails in SaaS production, focus on env/config differences and platform constraints.
8) Inspect release and startup health checks
If deployment succeeds but the app is marked unhealthy:
- Confirm health endpoint returns quickly and correctly
- Check app startup time
- Check dependency readiness on boot
- Ensure the health check doesn’t require auth or external services that may be unavailable at boot
9) Roll back if needed
If users are impacted:
- Roll back to the last known good version
- Stop automatic retries if they’re making things worse
- Preserve logs and artifacts before changes overwrite evidence
10) Add guardrails to prevent repeats
Useful improvements:
- CI checks for config validation
- Pre-deploy smoke tests
- Canary releases
- Feature flags
- Automated rollback on health check failure
- Better structured logging
- Alerting on deploy failures and startup crashes
Quick checklist
- Find build/test/release/runtime stage
- Read the first meaningful error in logs
- Compare changed code/config/secrets
- Verify env vars and secret values
- Check memory/CPU/disk/timeouts
- Review migrations and DB compatibility
- Reproduce in staging/local
- Roll back if production is affected
- Add checks to prevent recurrence
If you want, paste the deployment error logs or describe your stack (for example: Kubernetes, Vercel, AWS, Heroku, Docker, GitHub Actions), and I can help you narrow it down quickly.