Skip to content

Admin Process for 12-factor in Java

The 12-Factor blog suggests an App should ‘Run admin/management tasks as one-off processes’.

What does that mean in the context of a Java/ Spring-boot application? Can I get an example.

https://12factor.net/admin-processes

Answer

The site does not suggest this. It says that developers may want to do this, and that if they do so, they should apply the same standards as other code:

One-off admin processes should be run in an identical environment as the regular long-running processes of the app. They run against a release, using the same codebase and config as any process run against that release. Admin code must ship with application code to avoid synchronization issues.

As an example from my application: Users may send invitations, to which the recipient must respond within 7 days or the invitation expires. This is implemented by having a timestamp on the invitation and executing a database query equivalent to DELETE FROM Invitations WHERE expiration < NOW().

Now, we could have someone log in to the database and execute this query periodically. Instead, however, this “cleanup” operation is built into the application at a URL like /internal/admin/cleanInvitations, and that endpoint is executed by an external cron job. The scheduling is outside the main application, but all database configuration, connectivity, and logic are contained within it alongside our main business logic.