Tutorials Microservices Mastery
The 12-Factor App Methodology for Cloud-Native Apps
On this page
The 12-Factor App Methodology
Created by the engineers at Heroku, the 12-Factor App is a set of best practices for building modern, cloud-native applications that are portable, resilient, and ready to scale in environments like Azure, AWS, or Kubernetes.
1. Key Factors for .NET Developers
- Config: Store configuration in the **Environment**, not in the code. Never hardcode connection strings!
- Backing Services: Treat databases, caches, and message brokers as attached resources. Your app shouldn't care if it's talking to a local Docker DB or a Cloud-managed SQL.
- Statelessness: App processes must be stateless and share nothing. State belongs in a backing service (like Redis). If a server crashes, another should pick up without the user noticing.
- Port Binding: The app should be self-contained and export services via port binding (e.g., Kestrel listening on port 8080).
2. Dev/Prod Parity
Factor 10 states that your local environment should be as close as possible to production. This is why we use Docker Compose—to ensure the exact same DB version and OS version follow the code from the developer's laptop to the production cluster.
4. Interview Mastery
Q: "Why is 'Statelessness' the most important of the 12 factors for scaling?"
Architect Answer: "Because it allows for **Elasticity**. If your app stores user sessions in the RAM of the local server, you are stuck with that server. If you add a second server, the user might hit server B and 'lose' their login. By moving state to a backing service like Redis or a Database, any server instance can handle any incoming request. This allows you to scale from 1 instance to 10 instances in seconds without killing active user sessions."