Middle+
Are you familiar with the 12-Factor app design concept?
sobes.tech AI
Answer from AI
Yes, familiar. The 12 Factor app methodology is a set of principles for building SaaS applications aimed at increasing portability, scalability, and flexibility.
Main principles:
- Codebase: One codebase tracked in version control, many deploys.
- Dependencies: Explicitly declare and isolate dependencies.
- Config: Store configuration in the environment, not in the code.
- Backing services: Treat backing services (databases, message queues, etc.) as attached resources.
- Build, release, run: Strictly separate stages of build, release, and run.
- Processes: Execute the app as one or more stateless processes.
- Port binding: Export services via ports, self-contained.
- Concurrency: Horizontal scaling via the process model.
- Disposability: Fast startup and graceful shutdown for resilience.
- Dev/prod parity: Maximize similarity between development, staging, and production environments.
- Logs: Treat logs as a stream of events sent to stdout.
- Admin processes: Run administrative and migration tasks as one-off processes.
These principles help create applications that are easy to deploy and scale in modern cloud environments.
// Example of storing configuration in the environment
// package main
// import (
// "fmt"
// "os"
// )
// func main() {
// dbHost := os.Getenv("DATABASE_HOST") // Read environment variable
// if dbHost == "" {
// dbHost = "localhost" // Default value
// }
// fmt.Printf("Using database host: %s\n", dbHost)
// }