12-Factor App Principle #12: Admin Processes




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

  1. Run admin processes as separate, short-lived jobs.
  2. Use the same environment variables and configurations as the app.
  3. Reuse application code for consistent behavior.
  4. Keep admin scripts version-controlled with the app.
  5. 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.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *