Principle #12: Admin Processes
Goal: Run administrative or maintenance tasks as one-off processes in the same environment as your application, using the same codebase and configuration.
What It Means
- One-off tasks: Admin processes are temporary jobs such as database migrations, data cleanup, or maintenance scripts.
- Same environment: These tasks should run in the same environment and with the same configuration as the app, ensuring consistency.
- Use app’s code: Reuse existing application code for admin tasks instead of creating separate scripts with their own logic.
- Ephemeral: Admin processes are short-lived and not part of the regular running services.
Why It Matters
- Consistency: Ensures admin tasks behave exactly like the application in production.
- Reliability: Reduces the risk of environment-specific bugs.
- Efficiency: Reuses tested and maintained code instead of duplicating logic.
- Safety: Runs in a controlled environment, lowering the chance of introducing errors.
Example
A Rails application needs to update its database schema:
- The developer runs
rake db:migrate
in the production environment. - The command uses the same database connection settings and code as the live application.
- Once the migration finishes, the process exits.
Best Practices
- Run admin processes as separate, short-lived jobs.
- Use the same environment variables and configurations as the app.
- Reuse application code for consistent behavior.
- Keep admin scripts version-controlled with the app.
- Ensure admin tasks can be run on-demand without special setup.
Takeaway: Treat admin processes as one-off tasks that run in the same environment and with the same code as the application, ensuring consistent, reliable, and safe operations.