Must-know software architecture pattern

What is system architecture (Architecture)

Design is not just about look and feel, it also includes how it works. ——Steve Jobs

System Architecture and Soft Architecture are common terms in the IT field. Architecture design is an extremely critical part of the software system construction process.

Why is the system architecture important? What are the common architectural patterns? Follow [Code Gebyte] to understand the different design philosophies used in different architecture designs.

Let's take a look at the common architecture patterns: Client-Server, Peer to Peer, MVC, Layered, Distribute-Cluster, Micro-Service, Even-Source, Hexagonal and defeat them one by one.

Architecture, the original meaning of architecture, in fact, the concept of software architecture is derived from architecture. Architecture is the synthesis of art and technology related to building design and construction. Architecture is a discipline spanning engineering technology and humanities. It studies the available space of the building, the image that can be appreciated, and a series of issues surrounding the space and how the image is established, adjusted and beautified. And the object of research is not only the building itself, but more importantly, the research on people's requirements for buildings and how to meet them, and the corresponding planning, design and implementation in the process of building entities from scratch.

Architecture studies the planning, design and implementation of buildings. Software architecture studies the planning, design and implementation of software.

In the architecture design, the application system is divided into different parts according to factors such as business, technology, organization, flexibility, scalability, and maintainability, so that these parts can divide labor and cooperate with each other to complete specific requirements . The architecture runs through the entire process of system realization, is the main reference for the realization of the software system, and is the blueprint for the realization of the software system. The planning, design and implementation of the software system are organized and implemented according to the design of the architecture.

Why system architecture is important

We know Moore's Law—the capacity of computer hardware is developing at a rate that roughly doubles every two years. However, the software development process does not have such a speed-up process, and the development cost has not decreased. The design methodology and design mode of the system architecture are constantly changing, and this important process still does not have a completely reliable and once-for-all solution. why? What are the special problems in the software development process? There are the following points:

  1. Complexity

    Software can be said to be the most complex type of system created by humans. There are various explicit or implicit dependencies between the various modules of the software. With the growth of the system and the increase of modules, the number of these relationships often grows at a geometrical rate. The people who understand and use these complexities have not changed much.

  2. Invisibility

    Software engineers can directly see the source code, but the source code is not the software itself. Moreover, the static source code and the running system are different, and the complexity of the software operating environment also increases the unpredictability of the software system. The software system cannot be described in a simple way. Design documents, descriptions, flowcharts, and architecture diagrams are just to show the complex software system in a way that is easier to understand and communicate, but it still cannot fully describe the overall picture of the system.

  3. Changeability (Changeability)

    It seems easy to modify the software. It is much easier to modify the software than to modify the hardware. It is also much easier to modify the software system than to modify a towering building. So people naturally expect software systems to adapt to future changes. But changes are complicated, and the environment is also complicated. These complicated situations often make a thing that is easy to modify become an increasingly difficult thing.

  4. Conformity

    The software system cannot exist independently, it always runs on the hardware, and it always obeys the requirements of other components in the system, as well as the requirements of users and the industry.

The above characteristics of the software system make the design of the system architecture particularly important. The system architecture design solves the above software problems in the following ways:

  • abstract

    Abstraction is an important step in system architecture design. Abstraction is the simplification of complex concepts. At the highest level, the software system is abstracted into two high-level concepts : object and process . Objects can be different levels of concepts such as systems, components, interfaces, classes, methods, etc. The process is the way and flow of system operation. Abstraction conceptualizes concrete things to define boundaries, easy to understand, and easy to communicate.

  • break down

    Decomposition and combination interact. Decomposition is to decompose high-level abstract concepts into low-level abstract concepts. It is to divide entities into small parts or components. Among the many ways to deal with complexity, "divide and conquer" is a basic strategy, which keeps big problems going. Break down into small problems until every small problem can be solved.

  • Language

    The boundary of language is the boundary of the world. The field of language, language system is determined what, howand why. The language makes the system visible in the easy-to-understand levels of documents, design drawings, etc., and also makes the variability of the system regulated in a predictable and controllable range.

Several architectural patterns

Client-Server

cs

With the Internet, there is a client-server model. The client-server mode works in a request-response mode. The client sends request information, the server accepts the request, makes corresponding processing, and then sends back response information. All the Internet sites we visit have this structure. In an era when desktop programs are popular, the Internet is not as developed as it is today. Client-Server also only represents Desktop Client-Server mode, and the way of using a browser is called BS mode, that is, Browser-Server mode. Nowadays, Browser, Desktop Application, Mobile Application, Mobile Web, etc. are collectively referred to as Client.

Therefore, most of the websites we currently visit, such as news consulting sites, blog sites, etc. belong to this model.

Peer to Peer

p2p

The end-to-end service model (Peer to Peer, referred to as P2P), also known as the "point-to-point model", refers to a model that connects individuals to individuals via the Internet and bypasses the central platform to directly provide services and complete transactions. The early meaning of P2P is the "peer-to-peer network protocol" in the field of computer communication. It breaks the traditional Client/Server (C/S) model and makes thousands of computers connected to each other in a peer-to-peer position. Participants directly share part of their own hardware resources (including processing capabilities, storage capabilities, network connection capabilities, printers, etc.). These shared resources can be directly accessed by other peer nodes (Peer) through the Internet without going through a unified intermediate body. Participants in this network are both resource (service or content) providers (Server) and resource acquirers (Client).

The P2P model is popular in the fields of file sharing and downloading, computing and storage, instant messaging, and collaborative sharing.

MVC

mvc

Model-View-Controller, MVC architecture is a major advancement in object-oriented programming. The service divides the logic into three different components: Model-model, that is, data, usually stored in a database, and logical operations are performed in memory. View——User-visible components, used for user interaction and data display, such as Web GUI. Controller-logical operation, connect the components of Model and View, operate Model logic and View interactive display logic.

The MVC model is more popular in both the client and the H5 front end. It has always been a popular architecture pattern for the Web backend. The Web backend frameworks such as Struts and Spring MVC spawned in the Java Web field have turned the once complex Web development into a very simple development.

With the gradual separation of the front and back ends, the previous background MVC has completely handed over View to the front end, and the front and back ends communicate through related protocols to complete the transmission of View data.

Layered

Layered architecture is the most widely used architecture model. Almost every software system needs to isolate different concerns (Concern Points) through layers to deal with changes in different requirements, so that such changes can be carried out independently.

The single responsibility principle is an important principle for system design and development. The layered architecture always follows the single responsibility principle. Different levels are isolated from each other and assume different responsibilities.

Speaking of layered architecture, the most familiar one is the classic three-tier architecture. The classic three-tier architecture is composed of a user interface layer (User Interface Layer), a business logic layer (Business Logic Layer), and a data access layer (Data Access Layer) from top to bottom. The three-tier architecture is an upgrade of the simple Client-Server architecture.

three-layer

The classic and popular three-tier architecture, as well as the proximity of a large number of web back-end frameworks to the three-tier architecture, make web back-end development as simple as a developer who is just getting started can do web development. It is precisely because of this that the thinking of most web developers is limited by this, which has become the CRUD-Boy for everyone to ridicule. As the era of MIS systems fades away, the three-tier architecture has also begun to fail to become a "silver bullet" in some areas.

Remove the classic three-tier architecture. In domain-driven design, Eric Evans designed a classic four-tier architecture, which introduced a new layer between the user interface layer and the business logic layer, the Application Layer. The other layers have also been adjusted accordingly.

ddd

Distribute-Cluster

The architectures mentioned above are all under the monolithic architecture. Monolithic architecture and multi-service architecture are considered from the deployment mode and operation mode of the service.

The monolithic architecture has the following advantages:

  • Easy to develop: With the help of a development framework, the development of a single application is extremely simple, and developers rarely need to consider system, deployment, and network issues.

  • Easy to test: The single application is deployed in one process and the environment is simple. All functions can be tested as long as the service is started.

  • Easy to deploy: often only need to package the application into a simple package.

  • Easy to scale horizontally: You only need to deploy multiple services to the package.

Disadvantages of single application:

  • Increased maintenance costs: With the increase in demand, the single system will become more and more bloated, and the complexity of maintenance will also increase.

  • Long continuous interaction cycle: On the one hand, maintenance is difficult, and on the other hand, it is very difficult for monolithic applications to develop and test in parallel. Monolithic applications are not suitable for rapid iterative agile development.

  • Poor scalability: Due to a bloated system, system scalability will become difficult. System upgrades also need to be very careful.

  • Not friendly to newcomers.

Distributed system split:

service-scale

With the rapid development of the Internet, on the one hand, the level of access to Internet applications has increased greatly, and the amount of data has increased greatly. On the other hand, the iterative speed of applications is also getting faster. The single application model is no longer suitable for the rapid development of the Internet. In this way, the background distributed cluster architecture is becoming more and more popular.

Micro-Service

There is no strict definition of microservices. Here are the microservices described by Martin Fowler:

Microservice architecture is an architectural pattern that advocates dividing a single application into a set of small services, and the services coordinate and cooperate with each other to provide users with ultimate value. Each service runs in its own process, and a lightweight communication mechanism is used between services to communicate with each other (usually HTTP-based RESTful API). Each service is built around a specific business and can be independently deployed to the production environment.

Microservices usually have the following characteristics:

  • Single responsibility: business independence, team independence. A service with a single responsibility should have a core domain, high cohesion, low coupling, and a clear boundary with other systems and domains.

  • Lightweight communication: Communication should be simple and lightweight. It has nothing to do with language and platform.

  • Independence: independent development, independent testing and independent deployment.

All choices are a process of weighing . Microservices solve many problems of monolithic applications, and naturally bring corresponding problems. Distributed and clustered environments are complex, and the microservice architecture based on this will also have corresponding complexity.

With the popularity of microservices, many problems of microservices have been solved by more and more frameworks and services. Let's take the Spring Cloud technology stack as an example:

  • SpringBoot: Monolithic service, rapid project creation, rapid integration of various frameworks, easy to test and easy to deploy.

  • Feign: Microservices are deployed independently and communicate through related protocols. Feign is a simple declarative communication framework based on HTTP restful.

  • Eureka: There are more and more independent services, and more and more service instances. Service governance is a must. Eureka provides highly available service registration and service discovery functions.

  • Ribbon: Feign is only responsible for communication. Ribbon provides client load balancing, which is part of the system optimization.

  • Hystrix: Microservices will bring complex dependencies between services, and the complexity of distributed and clustering will also bring many unpredictable problems. In order to prevent a problem of a complex network and a complex system from causing an avalanche of the entire system, Hystrix is ​​an excellent circuit breaker in the Spring Cloud system, which can perform service degradation when the system fails to prevent the overall system from crashing.

  • Zuul: Unified gateway. The unified gateway adopts a facade model and provides friendly interfaces to the outside world. After microservices, more and more services will become more and more complex. In order to reduce the complexity of external system calls, the unified gateway is a common solution .

  • Config: The more services are divided, the more configurations will be. Spring cloud config provides unified configuration management.

  • Sleuth: Service monitoring and governance. Monitoring is a necessary infrastructure for complex systems. System perception, problem discovery, and performance positioning all require the blessing of monitoring.

micro-service

Even-Source

Event sourcing is the latest popular application architecture model. The event source models the state changes made by the application as an immutable sequence or "log" of events. Instead of modifying the state of the application in the field, the event source stores the event that triggers the state change in an immutable log and models the state change as a response to the event in the log.

event-source

The CQRS model is usually based on the event traceability model. In the traditional architecture, the same data model is used to query and update the database. This is very simple and very suitable for basic CRUD operations. However, in more complex applications, this method can become difficult to operate. For example, in terms of reading, the application may execute a large number of different queries and return data transfer objects (DTO) with different shapes. Object mapping can become complicated. In terms of writing, the model may implement complex verification and business logic. As a result, the model performs too many operations and is overly complex.

CQRS (Query responsibility separation Command Query Responsibility Segregation) read and write operations into different models, using the command to update the data, and use the query to read data.

Hexagonal

hexagonal

???? Hexagonal architecture, also known as "port and adapter mode", is an architectural style with symmetric features proposed by Alistair Cockburn. In this architecture, the system interacts with the outside through an adapter, encapsulating application services and domain services inside the system.

The hexagonal architecture consists of the following three components:

  • Ports: It can be divided into input terminal and output terminal, which is the interface between the system and other systems.

  • Adapters: The adaptation layer with other systems, on the one hand, prevents the core system and domain from being externally affected, that is, anti-corrosion; on the other hand, it is convenient for API use.

  • Domain: Applications and models are the core of the program.

The core concept of the hexagonal architecture is: applications interact with the outside through "ports". In the traditional layered architecture, it is easy to cross the boundary between layers and penetrate the business logic into other layers. The important thing about the hexagonal structure is the "boundary" and "domain." The original intention of the hexagonal architecture is to solve the problem of decoupling between technology and business systems, as well as the problem of decoupling between technology and technology. This architecture comes from the design pattern, starting from the entity services of the business, and will be specifically designed for the interface. The realization of the standardized port protocol and adapter, the service itself realizes independence and completeness.

reference:

"System Architecture-Product Design and Development of Complex Systems" Daniel Selva
"The Method of Construction-Modern Engineering" Zou Xin
"Microservice Architecture and Implementation" Wang Lei
"Domain Driven Design-The Way to Deal with the Core Complexity of Software "Eric Evans
, Realizing Domain-Driven Design", Vaughn Vernon,
"Spring Cloud Microservices in Action ", Zhai Yongchao,
"Engineering-Endless Frontiers", Ouyang Yingzhi,
"The Myth of the Moon" Frederick P. Brooks, Jr.

There is no way, but the technique can be achieved; if there is no way, it ends with the technique

Welcome everyone to follow the Java Way public account

Good article, I am reading ❤️

Guess you like

Origin blog.csdn.net/hollis_chuang/article/details/108505328