📅  最后修改于: 2023-12-03 15:11:46.057000             🧑  作者: Mango
Introduction to Code's 12 Rules
Code's 12 Rules, also known as "The Twelve Factor App," is a methodology for building software-as-a-service (SaaS) applications. It was created by Adam Wiggins and derived from his experience working on a SaaS project. The methodology is designed to help developers build scalable, maintainable, and portable applications in the cloud.
Markdown Overview of the 12 Rules
- Codebase: One codebase tracked in revision control, many deploys.
- Maintain all software versions in a single codebase.
- Deploy only the necessary parts of the codebase each time.
- Dependencies: Explicitly declare and isolate dependencies.
- Declare and control external software libraries and other dependencies.
- Use containers to isolate dependencies and ensure compatibility.
- Config: Store configuration in the environment.
- Store configuration values such as API keys, credentials, and URLs in the environment.
- Avoid hardcoding configuration values in the codebase.
- Backing services: Treat backing services as attached resources.
- Treat supporting services such as databases, message brokers, and email services as external resources.
- Connect to backing services through a well-defined interface.
- Build, release, run: Strictly separate build and run stages.
- Separate the process of building the codebase from deploying and running it.
- Ensure that each stage has a well-defined interface.
- Processes: Execute the app as one or more stateless processes.
- Avoid storing session state on individual servers.
- Use shared storage to store session data or use an external state management system.
- Port binding: Export services via port binding.
- Use well-defined ports to expose the application's services.
- Avoid hardcoding network addresses in the codebase.
- Concurrency: Scale out via the process model.
- Use a process model to scale the application horizontally.
- Design processes to be stateless and scalable.
- Disposability: Maximize robustness with fast startup and graceful shutdown.
- Ensure that all processes can be started and stopped gracefully.
- Use tools such as container orchestration platforms to automate management.
- Dev/prod parity: Keep development, staging, and production as similar as possible.
- Ensure that the various stages of the application's lifecycle are consistent.
- Use standardized tooling and environments to ensure consistency.
- Logs: Treat logs as event streams.
- Use a centralized logging system to collect and analyze logs from all parts of the application.
- Store logs as event streams to enable searching and filtering.
- Admin processes: Run admin/management tasks as one-off processes.
- Treat administrative tasks as one-off processes rather than features of the application.
- Use the same tooling and environments as the application to avoid inconsistencies.
Conclusion
Code's 12 Rules provide a useful methodology for building cloud-based applications. By following these rules, developers can create software that is scalable, maintainable, and portable - all essential qualities for software-as-a-service applications.