software architecture is the basic structure of software.
The appropriate architecture is one of the most important factors for software success. Large software companies usually have a dedicated architect position (architect), which can only be held by senior programmers.
O&x27;Reilly has published a free booklet "Software Architecture Patterns" (PDF), which introduces the five most common software architectures. It is a very good primer.
The software architecture is the basic structure of the software. The essence of architecture is to manage complexity. If you think that the architecture is not important, it may be that you are not doing complex enough, or you have not managed the complexity well. Although there are many architectural patterns, after abstract precipitation, there are only a few:
1. Layered architecture (compared to the traditional monolithic architecture)
2. Event-driven architecture (generally applicable to local application scenarios, Used to achieve asynchronous decoupling)
3. Microkernel architecture (also known as plug-in architecture, which is difficult to develop, and is generally used for tool software development, such as Eclipse, which is not suitable for distributed business scenarios)
4. Microservice architecture (currently popular service-oriented architecture, which solves the problems faced by monolithic architecture, suitable for agile development and rapid iteration)
5. Cloud architecture (now called Cloud Native Architecture-Cloud Native, based on Docker, Kubernetes, Service Mesh cloud native architecture)
Based on the original text, the editor made minor adjustments according to his own ideas.
1. Layered architecture
Layered architecture (layered architecture) is the most common software architecture and the de facto standard architecture. If you don't know what architecture to use, use it.
This architecture divides the software into several horizontal layers, each layer has a clear role and division of labor, and there is no need to know the details of other layers. Communication between layers through interfaces.
Although there is no clear agreement on how many layers the software must be divided into, the four-layer structure is the most common.
- presentation: user interface, responsible for visual and user interaction
- business layer (business): implement business logic
- persistence layer ( persistence): Provide data, and SQL statements are placed in this layer
- database (database): save data
Some software is between the logic layer (business) and the persistence layer (persistence), plus A service layer (service) provides some common interfaces required by different business logic.
User's request will be processed through these four layers in turn, and no one of them can be skipped.
Advantages
- Simple structure, easy to understand and develop
- Programmers with different skills can divide the work and be responsible for different layers, which is naturally suitable for most software The company’s organizational structure
- can be tested independently at each layer, and the interfaces of other layers can be solved through simulation. Troublesome and time-consuming
- deployment is more troublesome, even if only a small place is modified, the entire software is often redeployed, which is not easy to doContinuous release (because it is a monolithic architecture)
- software upgrade, the entire service may need to be suspended
- poor scalability. When a large number of user requests increase, each layer must be expanded in turn. Since each layer is internally coupled, it will be difficult to expand (monolithic architecture, demand adjustment will run through each layer)
2. Events Drive architecture
An event is a notification sent by the software when the state changes.
event-driven architecture is a software architecture that communicates through events. It is divided into four parts.
Event-driven architecture core components:
- event queue: the entrance to receive events
- distributor ( event mediator: Distribute different events to different business logic units
- event channel (event channel): the communication channel between the distributor and the processor
- event processor (event processor): achieve business Logic, after the processing is completed, an event will be issued to trigger the next operation
For simple projects, event queues, distributors and event channels can be integrated, and the entire software is divided into two parts: event agent and event processor .
Advantages
- Distributed asynchronous architecture, highly decoupling between event processors, good software scalability
- Wide applicability, each Various types of projects can use
- with better performance. Because of the asynchronous nature of the event, the software is not easy to cause blockage.
- The event processor can be loaded and unloaded independently, and it is easy to deploy.
- involves asynchronous programming (remote communication, loss of response, etc. should be considered), and the development is relatively complicated. Distributed and asynchronous characteristics make this architecture difficult to test.
event-driven architecture is also widely used in communication products, such as state machine processing. Event-driven architecture is not suitable for top-level architecture, but it is suitable for partial implementation, which can be found in almost every corner of communication software.
3. Microkernel architecture
The microkernel architecture (microkernel architecture) is also called "plug-in architecture", which refers to the relatively small core of the software. The main functions and business logic are implemented through plug-ins.
The core usually only contains the minimum functions that the system runs. Plug-ins are independent of each other, and communication between plug-ins should be minimized to avoid interdependence.
Advantages
- Good functional extensibility (extensibility), what functions are needed, develop a plug-in to
- The functions are isolated, The plug-in can be loaded and unloaded independently, making it easier to deploy.
- is highly customizable and adapts to different development needs.
- can be developed progressively and gradually increase the function
disadvantage
- The scalability (scalability) is poor, and the kernel is usually an independentIt’s not easy to make distributed
- . The development difficulty is relatively high because it involves the communication between the plug-in and the kernel and the internal plug-in registration mechanism
. The design and development of the micro-core architecture is relatively difficult. This is destined to not be used much in enterprise products, although it has many advantages.
4. Microservice architecture
Microservices architecture is an upgrade of service-oriented architecture (SOA).
Each service is a separately deployed unit. These units are distributed, decoupled from each other, and connected through remote communication protocols (such as REST, SOAP).
The microservice architecture is divided into three implementation modes.
- RESTful API mode: Services are provided through APIs, and cloud services belong to this category.
- RESTful Application mode: Services are provided through traditional network protocols or application protocols, usually behind a multifunctional application , Common in the enterprise
- centralized message mode: the use of message broker (message broker) can achieve message queue, load balancing, unified log and exception handling, the disadvantage is that there will be a single point of failure, the message broker may be made into a cluster
There are many open source microservice frameworks, such as Spring Cloud, Dubbo, ServiceComb and so on.
Advantages
- Good scalability, low coupling between various services
- Easy to deploy, the software is split into multiple pieces from a single deployable unit Two services, each service is a deployable unit
- is easy to develop, each component can be developed continuously, can be deployed in real time, and can be continuously upgraded.
- is easy to test and can be tested individually Each service
Disadvantages
- Due to the emphasis on mutual independence and low coupling, the services may be divided very finely. This causes the system to rely on a large number of microservices, become messy and cumbersome, and have poor performance.
- Once the services need to communicate (that is, one service needs to use another service), the entire architecture becomes complicated. A typical example is some general utility classes. One solution is to copy them to each service and exchange redundancy for simplicity of the architecture. The distributed nature of
- makes it difficult for this architecture to achieve atomic operations and transaction rollbacks.
5. Cloud architecture (Cloud Native)
Cloud architecture (now called Cloud Native) mainly solves the problems of scalability and concurrency, It is the easiest architecture to expand.
Its high scalability is mainly due to the elastic scaling of computing resources based on the cloud. Then, the business processing capabilities are encapsulated into a processing unit (prcessing unit). When the traffic increases, a new processing unit (Docker container) is created; when the traffic decreases, the processing unit (Docker container) is closed. Since there is no central database, the biggest bottleneck of scalability disappears. Because the data of each processing unit is independently sub-database.
This model is mainly divided into two parts: processing unit and virtualized middleware.
- Processing unit: implement business logic (similar to the microservice architectureMicroservices)
- Virtual middleware: responsible for communication, maintaining sessions, data replication, distributed processing, and deployment of processing units.
Virtual middleware contains four more components:
- Messaging Grid: manages user requests and sessions, when a request comes in , Decide which processing unit to allocate;
- Data Grid: Copy data to each processing unit, that is, data synchronization. Ensure that a certain processing unit gets the same data;
- Processing Grid: optional, if a request involves different types of processing units, the middleware is responsible for coordinating the processing units;
- deployment middle File (Deployment Manager): Responsible for the startup and shutdown of the processing unit, monitoring the load and response time, when the load increases, the processing unit is newly started, and when the load decreases, the processing unit is closed.
With the rapid development of containerization technologies such as Docker and Kubernetes, the above description of cloud architecture is a bit old. The current latest cloud native architecture, with Docker+Kubernetes as the core, especially the container orchestration Kubernetes, has become the de facto industry standard.
Main features of cloud native architecture diagram:
- Microservice application operation support environment;
- takes the image of containerized applications as the delivery standard;
- Quickly apply and release resources through resource scheduling service;
- quickly expand applications through elastic scaling;
- status monitoring;
Main Goal:
1. Let developers focus on the realization of business logic, and leave the rest to the container cloud platform to complete;
2. Support rapid iteration of business systems, support rapid business changes and development;
3. Build a business center with a shared service system as the core;
The following is a cloud-native architecture diagram designed by Xiaobian for a new retail enterprise, which builds cloud-native applications based on cloud and microservice architecture. The cloud here can be public cloud, private cloud, hybrid cloud, etc.
The above is to classify the architecture from different perspectives. In actual applications, various architectures are not isolated, and various architectures can be integrated and grafted according to the business environment and business demands. Each architecture has its advantages and disadvantages. Needless to say the advantages, the disadvantages are almost always avoided by the ability of tool engineering (such as automated release tools, automated testing, etc.). Tool engineering is very important to software architecture.
Original link:
http://ruanyifeng.com/blog/2016/09/software-architecture.html