Twelve factor principle and cloud native microservices dzone
2020-11-06 01:20:00 【On jdon】
One by 12 An application consisting of three factors is a way to build scalable and high performance , Methodology or set of principles for independent and most resilient enterprise applications . It establishes general principles and guidelines for creating robust enterprise applications .12 Feature application principles are very popular , Because it's consistent with microservice principles .
Here are 12 The element principle
- The code base （ A code base is tracked in revision control , A lot of deployment ）
- Dependency relationship （ Make clear and isolate dependencies ）
- Config（ Store the configuration in the environment ）
- Support services （ Process support resources as additional resources ）
- structure , Release and run （ Completely independent build and run phases ）
- process （ Execute the application as one or more stateless processes ）
- Port binding （ Export services through port binding ）
- Concurrent （ Extend through the process model ）
- One off （ Maximize robustness by fast start-up and normal shutdown ）
- Development / Product parity check （ Keep developing , Staging and production are as similar as possible ）
- journal （ Process logs as event streams ）
- Management process （ Will manage / Management tasks run as one-time processes ）
The code base （ A code base is tracked in version control , A lot of deployment ）
12 Element applications claim that each application should have its own code base （repos）. Multiple versions of multiple code bases must be avoided . Please note that , There are branches that can . That is, for all deployment environments , There should be only one repository , There should not be more than one .
Multiple applications sharing the same code violate 12 factors . ad locum , You should choose to join the shared library .
From with 12 An application perspective of three factors , Deployment means a running instance of the application , For example, production , On the stage , Quality inspection, etc . Besides , Each developer has a copy of the application running in their local development environment , Each copy also has the following conditions ： Deploy .
Multiple versions may be activated in different versions （ This version is like code changes that are available in one environment but not available in other environments ）.
Microservices ： In microservices , Each service should have its own code base . Having a separate code base can help you simplify the application's CI / CD technological process .
Twelve factor applications advocate not sharing code between applications . If you need to share , You need to build a library and make it a dependency , And through like maven Such a software package repository is managed .
Dependency relationship （ Make clear the declaration and isolation of dependencies ）
Discusses the use of dependency management tools to manage dependencies from outside , Instead of adding it to your code base .
from Java From the perspective of , You can use Gradle As a dependency Manager . You will be at build.gradle All dependencies are mentioned in the document , And your application will be from maven Download all the mentioned dependencies from the repository or other various repositories .
You also need to get from the operating system / The execution environment considers dependencies .
Microservices ： All application packages will pass through sbt,maven Wait for the package manager to manage .
- In a non containerized environment , You can use chef,ansible For configuration management tools to install system level dependencies .
- For containerized environments , have access to Dockerfile.
Config（ Store the configuration in the environment ）
Any change between deployment environments is considered configuration . This includes ：
- Database connections and credentials , System integration endpoint
- External service （ for example Amazon S3 or Twitter Or any other external application ） The credentials
- Application specific information , for example IP Address , Port and host name, etc .
You should not hard code any configuration values into constants in the code base . It's a direct violation of 12 Principle of element application .
12 Feature application principles recommend that configuration values be saved in environment variables .
It advocates strict code and configuration differentiation . Wherever you deploy your application , The code must be the same .
according to “ To configure ”, Environment specific environments must be moved to configuration and managed through environment variables .
Microservices ： Externalize the configuration from the application . In the micro service environment , From the source control （ Such as git（spring-cloud-config）） Manage application configuration , And use environment variables to maintain sensitive information in the source control .
Support services （ Use the processed resources as additional resources ）
according to 12 Element application principles , Backup services are applications that are consumed by applications over the network / service , It's part of its normal operation .
database ,Message Broker, Any other external system that the application communicates with is considered a supporting service .
12 Factor applications can automatically swap applications from one provider to another , Without any further changes to the code base . Let's say , You want to transfer the database server from MySQL Change to Aurora. So , You should not make any code changes to the application . Only configuration changes can solve this problem .
Microservices ： In the micro service ecosystem , Anything outside the service is considered an additional resource . Resources can be exchanged at any given point in time , It doesn't affect the service .
By following interface based programming , Providers can be exchanged dynamically without affecting the system . Plug in based implementations can also help you support multiple providers .
structure , Release and run （ Completely separate the build and run phases ）
The application must be building , There is a strict separation between the release and run phases . Let's look at each phase in more detail .
Construction phase ： Convert code to executable packages / Build packages .
Release stage ： Get build packages from the build phase , And combined with the configuration of the deployment environment , Make your application run .
Operation phase ： It's like running your application in an execution environment .
You can use CI / CD Tools come from automating the build and deploy process .Docker Images make it easier and more efficient for you to separate builds , Release and run phase .
process （ Execute an application as one or more stateless processes ）
The application is executed as a process in the execution environment . An application can have one or more instances / process , To satisfy users / Customer needs .
according to 12 Factor principle , Applications should not store data in memory , You have to save it to storage and use it from there . In terms of state , Your application should store the state in the database , Instead of being stored in the process's memory .
Avoid sticky conversations （httpsession Store user data in ）, Using sticky conversations violates 12 Element application principles . If you want to store session information , You can choose according to your needs Redis or Memcached Or any other cache provider .
By following these steps , Your application can be highly extended , And it doesn't have any impact on the system
Microservices ： By adopting REST The stateless nature of , Your service can be expanded horizontally according to your needs , And zero impact . If your system still needs to maintain state , Please use additional resources （Redis,Memcached Or data storage ） To store state , Not in memory .
Port binding （ Export services through port binding ）
Applications with twelve elements are completely independent , And it doesn't depend on injecting the runtime of network server into the execution environment to create the object for Web Service for .Web By binding to a port and listening for requests from that port , take HTTP Export as a service .
In short , This is about treating your application as a stand-alone application , Instead of deploying it to any external Web Server .
Microservices ： Spring Starting is an example of this . By default ,Spring Boot With embedded tomcat,jetty or undertow.
Concurrent （ Extend horizontally through process model ）
Here we discuss how to extend the application ： The twelve element application principle recommends that you consider applications as multiple processes / Instance operation , Instead of running in a large system . You can still choose to join threads to improve concurrent processing of requests .
In short , The twelve factor application principle advocates choosing to scale horizontally rather than vertically .
（ Zoom vertical - Add additional hardware to the system
Scale horizontally - Add another instance of the application ）
Microservices ： By adopting containerization , The application can be extended according to the level of demand .
Disposable （ Maximize stability by fast startup and smooth shutdown ）
The process of the twelve element application is one-off , This means that they can start or stop immediately . When the application is shut down or started , Instance should not affect application state .
Normal shutdown is very important . The system must ensure that the state is correct .
When you add a new instance or delete an existing instance as needed , The system should not be affected . This is also known as system resolvability .
For various reasons , The system did crash . The system should ensure that the impact is minimal , And the application should be stored in a valid state .
Microservices ： By using containerization in the deployment of microservices , Your application will follow this principle implicitly to the maximum extent .Docker Containers can be started or stopped immediately . The request , Storing state or session data in queues or other supporting services ensures seamless processing of requests in the event of a container crash .
Development / Product parity check （ Keep developing as much as possible , Stage and produce ）
The twelve factor methodology suggests that the gap between development and production environments be kept to a minimum . This reduces the risk of displaying errors in specific environments .
Microservices ： It's the inherent function of micro container technology to use .
journal （ As the processing log of the event flow ）
Logs are critical to solving production problems or understanding user behavior . Logs can view the behavior of running applications .
The application principle of twelve elements advocates separating the generation of log and the processing of log information . In the application , The log will be written as standard output , The execution environment is responsible for capturing , Storage , management , Archiving of such flows should be handled by the execution environment .
Microservices ： In microservices , Observability is a first-class citizen . By using APM Tools （ELK,Newrelic And other tools ） Or log aggregation tool （ for example Splunk, Log etc. ） To achieve observability .
By following these guidelines , All you need to do is debug the problem , That is, go to the tool's central dashboard and search .
Administrator process （ As a one-time process running Administrator / Management tasks ）
As part of the application deployment , There are several one-time processes , For example, data migration , Execute a one-time script in a specific environment .
The twelve element principle advocates keeping such management tasks in the repository as part of the application code base . such , One time scripts will follow the same process defined for your code base .
Make sure that one time scripts are automated , So you don't have to worry about manually executing builds before releasing them .
The twelve factor principle also recommends using the built-in tools of the execution environment to run those scripts on the production server .
Microservices ： Containerization can also help you run a one-time process as a task , And automatically turn it off during execution .
- C++ 数字、string和char*的转换
- Won the CKA + CKS certificate with the highest gold content in kubernetes in 31 days!
- C + + number, string and char * conversion
- C + + Learning -- capacity() and resize() in C + +
- C + + Learning -- about code performance optimization
C + + programming experience (6): using C + + style type conversion
Latest party and government work report ppt - Park ppt
Online ID number extraction birthday tool
Field pointer? Dangling pointer? This article will help you understand!
GVRP of hcna Routing & Switching
- LeetCode 91. 解码方法
- Seq2seq implements chat robot
- [chat robot] principle of seq2seq model
- Leetcode 91. Decoding method
- HCNA Routing＆Switching之GVRP
- GVRP of hcna Routing & Switching
- HDU7016 Random Walk 2
- [Code+＃1]Yazid 的新生舞会
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- HDU7016 Random Walk 2
- [code + 1] Yazid's freshman ball
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- Qt Creator 自动补齐变慢的解决
- HALCON 20.11：如何处理标定助手品质问题
- HALCON 20.11：标定助手使用注意事项
- Solution of QT creator's automatic replenishment slowing down
- Halcon 20.11: how to deal with the quality problem of calibration assistant
- Halcon 20.11: precautions for use of calibration assistant
- "Top ten scientific and technological issues" announced| Young scientists 50 ² forum
- Reverse linked list
- JS data type
- Remember the bug encountered in reading and writing a file
- Singleton mode
- 在这个 N 多编程语言争霸的世界，C++ 究竟还有没有未来？
- In this world of N programming languages, is there a future for C + +?
- js Promise
- js 数组方法 回顾
- ES6 template characters
- js Promise
- JS array method review
- 【Golang】️走进 Go 语言️ 第一课 Hello World
- [golang] go into go language lesson 1 Hello World