Lesson 9 of 9 · 25m
Production Operations: Releases, Observability, and Failure Drills
The deployment checklist, migration discipline, logging, metrics, and recovery habits that keep a Laravel application boring in production.
A production Laravel application should be boring. Boring means deploys are repeatable, workers restart cleanly, migrations are backwards-compatible, logs answer questions, and failed jobs are visible before customers email you. Most of that is not heroics; it is a checklist you follow every time.
Deploy as a repeatable pipeline
php artisan down --render=errors::503 || true
git pull --ff-only
composer install --no-dev --prefer-dist --optimize-autoloader
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan queue:restart
php artisan upIn a zero-downtime deployer the exact order changes, but the constraints do not: dependencies are deterministic, caches are rebuilt, migrations run deliberately, and workers reload code. Never edit production files by hand unless you are already in incident mode.
Migrations must respect running code
The dangerous migration is not the one that fails loudly; it is the one that succeeds while old application instances are still running. Use expand-and-contract changes:
- Add the new nullable column or table.
- Deploy code that writes both shapes and reads the new one when present.
- Backfill in chunks.
- Enforce constraints.
- Remove the old shape in a later deploy.
Dropping a column in the same deploy that introduces its replacement is how rolling deploys produce five minutes of 500s.
Logs should answer questions, not collect noise
Log::warning('Stripe webhook signature mismatch', [
'webhook_id' => $request->header('Stripe-Signature'),
'remote_ip' => $request->ip(),
]);Log identifiers, states, and decisions. Do not log passwords, tokens, full card payloads, or entire serialized users. Use structured context consistently so grep and log aggregation can do their job. Configure config/logging.php channels for application logs and slow but useful audit trails.
Metrics beat vibes
Track queue depth, failed jobs, job runtime, HTTP latency, error rate, database connections, and cache hit rate. Laravel Pulse is useful for application-level visibility; Horizon gives Redis queue depth and worker health. External uptime checks cover the user-facing path. A graph you never look at is decoration, so wire alerts to thresholds that require action.
Practice the failure modes
- What happens when Redis is unavailable for ten minutes?
- What happens when migration 42 fails halfway through deploy?
- How do you retry only the failed webhook jobs?
- How do you prove workers are running the new release?
- Who can rotate a leaked API key, and where is that documented?
If the answers depend on one person's memory, you do not have operations; you have folklore.
Field notes
composer installbelongs in deploy,composer updatebelongs in development and CI. Production should install the lockfile.php artisan aboutis a fast sanity check for environment, cache, queue, and driver state.- Telescope and debugbar are development tools. Do not expose them on production; they leak request data and internal paths.
- Write the rollback plan before you need it. Some migrations are irreversible because data is destroyed, not because Laravel cannot roll them back.
Was this lesson helpful?