Skip to content

The Twelve Factor App Methodology πŸ”₯

Lyes Sefiane edited this page Jan 18, 2023 · 1 revision

Ref.: https://12factor.net/

1. Codebase

One codebase tracked in revision control, many deploys.
  • Spring Boot application in one single Git repository, compiled, packaged and then deployed to one or more environments based on Spring profiles.

2. Dependencies

Explicitly declare and isolate dependencies.
  • Spring Boot application dependencies can be done via pom.xml (Maven) or build.gradle (Gradle) file.

3. Config

Store config in the environment.
  • Configuration includes all values needed by the application, but specific to the environment.

  • With Spring Boot application, we can externalize the configuration using environment variables provided at runtime (configuration properties).


4. Backing services

Treat backing services as attached resources.
  • Changing the backing service implementations without major changes to the application (Example : swapping from in-memory database to an other remote one at runtime).

5. Build, release, run

Strictly separate build and run stages.
  • Easy to achieve with Spring Boot and containers development workflow (CI/CD).

6. Processes

Execute the app as one or more stateless processes.
  • Spring Boot application execute as a Java process on the host system or inside a container runtime environment like Docker.
  • The processes should be stateless and share nothing.
  • Data should be stored in a stateful backing service like a database.

7. Port binding

Export services via port binding.
  • Port binding is one of the fundamental requirements for microservices to be autonomous and self-contained.
  • With Spring Boot, we can configure the port by setting the server.port configuration property.

8. Concurrency

Scale out via the process model.
  • Horizontal scaling of processes to achieve concurrency instead of vertical scaling.

9. Disposability

Maximize robustness with fast startup and graceful shutdown.
  • Minimize the startup time (Lazy Initialization) and ensure that the application shuts down gracefully (error handling and crash protection).

10. Dev/prod parity

Keep development, staging, and production as similar as possible.
  • Don't allow a wide gap between environments (Difference between production code and development code is a few working features at most).

11. Logs

Treat logs as event streams.
  • Format all of logs output into json messages, so that a single entry log is a json message regardless of lines in that message.
  • Spring Boot logs only to the console by default and does not write log files. It is preconfigured with Logback.

12. Admin processes

Run admin/management tasks as one-off processes.
  • Treat administrative functions like any other application (as it own 12 factor application).
Clone this wiki locally