I. What is architecture and architecture essence
In the software industry, there is a lot of debate about what architecture is, and everyone has their own interpretation. The structure that you speak of and the structure that you understand are not necessarily the same thing. Therefore, before we discuss architecture, we first discuss the conceptual definition of architecture. Concept is the basis for people to know the world and the means to communicate. If the understanding of the concept of architecture is not the same, the communication is naturally not smooth.
Linux has an architecture, MySQL has an architecture, the JVM also has an architecture, the use of Java development, MySQL storage, running on Linux business system also has an architecture, which should be concerned about? To clarify the above issues, we need to comb through several related and similar concepts: system and subsystem, module and construction, framework and architecture:
**1.1. Systems and subsystems **
System
System: Generally refers to a group of related individuals, operating according to certain rules, capable of doing work that individual components cannot do independently.
Subsystem: Also a system composed of a group of related individuals, most often part of a larger system.
**1.2. Modules and Components **
It's all part of the system, just taking it apart from different angles. A module is a logical unit and a component is a physical unit.
The module is to decompose the system logically, that is, divide and rule, and simplify complex problems. The granularity of a module can be large or small, it can be a system, several subsystems, a service, a function, a class, a method, a functional block, and so on.
Components can include application services, databases, networks, physical machines, and technical components such as MQ, containers, and Nginx.
**1.3. Framework and architecture **
Framework is the specification of component implementation, such as: MVC, MVP, MVVM, etc., is to provide basic functions of the product, such as open source framework: Ruby on Rails, Spring, Laravel, Django, etc., which can be used directly or on the basis of secondary development.
A framework is a specification and an architecture is a structure.
I redefine architecture here: Software architecture refers to the top-level structure of a software system.
Architecture is the most reasonable decision under the constraints of existing resources after systematic thinking and weighing advantages and disadvantages, and the final clear system skeleton: including subsystems, modules, and components. And the relationships between them, the constraints, the guidelines. And use it to guide everyone in the team to be aligned on a mental level. It involves four aspects:
- Rational decision-making of systematic thinking: such as technology selection, solution, etc.
- Clear system skeleton: Clarify what parts of the system are made up of.
- System collaboration relationships: How the various components work together to fulfill business requests.
- Constraint specifications and guiding principles: ensure orderly, efficient and stable operation of the system.
Therefore, the architect has the ability to: ** understand the business, control the whole situation, select the right technology, solve key problems, and guide the implementation of research and development **.
The essence of architecture is to restructure the system in order to meet the current business development, and can be rapidly expanded.
What kind of system to consider architecture design technology does not come out of nowhere and self-driven development, and the development and requirements of the architecture are based on business drivers.
Architecture is all about the business,
- The requirements are relatively complex.
- Non-functional requirements play an important role in the whole system.
- Long system life cycle and scalability requirements.
- The system is based on component or integration needs.
- The need for business process reengineering.
II. Architectural layering and classification
Architecture can be subdivided into business architecture, application architecture, technology architecture, code architecture, and deployment architecture
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122585 "what is the real architecture design?" )
Business architecture is strategy, application architecture is tactics, and technology architecture is equipment. Among them, the application architecture connects the top and bottom, on the one hand, to undertake the landing of the business architecture, on the other hand, affects the technology selection.
Get familiar with the business, form the business architecture, make the corresponding application architecture according to the business architecture, and finally implement the technical architecture.
How to choose the right application architecture for the current needs, how to face the future and ensure the smooth transition of the architecture, this is a problem that software developers, especially architects, need to think deeply about.
**2.1. Business Architecture (Overhead architecture) ** :
Including business planning, business modules, business processes, the business of the whole system is divided, the domain model is designed, and the real business is transformed into abstract objects.
There is no optimal architecture, only the most suitable architecture, all system design principles should be to solve business problems as the ultimate goal, from the actual business of the technical feelings of the framework will often bring the system into the pit, any not based on the business to do whimsical architecture is a rogue.
The premise of all the problems is to understand how much business we are facing today, what is the growth trend, and the process of solving high concurrency must be a gradual process. A reasonable architecture that can anticipate business development 1 to 2 years in advance is appropriate. This can pay a more reasonable price in exchange for the real effect of technology-led business growth.
Take a look at Jingdong business structure (online share picture) :
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122586 "what is the real architecture design?" )
**2.2. Application Architecture (Profile architecture, also known as logic architecture diagram) ** :
Hardware-to-application abstraction, including abstraction layers and programming interfaces. Application architecture and business architecture are mutually reinforcing. Every part of the business architecture has an application architecture.
Similar:
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122587 "what is the real architecture design?" )
Application architecture: As an independent deployable unit, an application divides a clear boundary for the system and profoundly affects the functional organization, code development, deployment, and operation and maintenance of the system. The application architecture defines which applications are in the system and how they work together. The so-called application here is the various logic modules or subsystems.
There are two key points in the application architecture diagram:
Division of responsibilities: Clear application (each logic module or subsystem) boundaries
- Logical layering
- Subsystem and module definition.
- Key class.
- Collaboration between responsibilities:
- Interface protocol: indicates the output interface of the application.
- Collaboration: indicates the calling relationship between applications.
There are two ways to apply layering:
One is horizontal (horizontal), according to the functional processing order to divide the application, such as the system is divided into web front-end/intermediate services/background tasks, which is a business-oriented depth of division. The other is vertical division (vertical), according to different business types of application, such as the purchase, sales and inventory system can be divided into three independent applications, which is oriented to the breadth of business division.
Application cooperation reflects how applications cooperate to complete complex business cases, which is mainly reflected in the communication mechanism and data format between applications. The communication mechanism can be synchronous call/asynchronous message/shared DB access, etc., and the data format can be text /XML/JSON/ binary.
The division of the application is biased towards the business and reflects the business architecture, while the combination of the application is biased towards the technology and affects the technical architecture. The business complexity is reduced, the system is more ordered, and the technical complexity is increased, the system is more disorderly.
The essence of application architecture is to balance business and technical complexity through system fragmentation to ensure that the system is not dispersed.
What kind of application architecture the system adopts is affected by the complexity of the business, including the development stage and business characteristics of the enterprise; IT is also affected by technical complexity, including the stage of IT technology development and the level of internal technical personnel. Service complexity (including large service volumes) inevitably leads to technical complexity. The application architecture aims to solve the service complexity while avoiding too much technical complexity and ensuring the implementation of the service architecture.
**2.3. Data architecture **
Data architecture guides database design. Consider not only the database and entity model involved in the development, but also the design of the data storage in the physical architecture.
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122590 "what is the real architecture design?" )
**2.4. Code Architecture (also called Development architecture) ** :
Subsystem code architecture mainly provides practical guidance for developers, if the code architecture design is insufficient, it will cause the architecture design that affects the whole world. For example, different development teams within the company use different technology stacks or components, and the result is that the overall architectural design of the company can get out of control.
Code architecture main definitions:
①. Code unit:
- Configuration design
- Framework, class library.
②. Code unit organization:
- Coding specifications, coding conventions.
- Project module division
- Top-level file structure design, such as mvc design.
- Dependency
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122588 "what is the real architecture design?" )
**2.5. Technical Architecture **
Technical architecture: Determine the actual running components that make up the application (lvs, nginx, tomcat, php-fpm, etc.), the relationships between these running components, and the strategy for deploying them to hardware.
The technical architecture mainly considers the non-functional characteristics of the system, and makes system-level grasp of the system's high availability, high performance, expansion, security, scalability, simplicity, etc.
The design of system architecture requires the architect to have a solid knowledge of the functionality and performance of software and hardware, which is the most difficult part of the architecture design work.
**2.6. Deployment topology Diagram (actual physical diagram) ** :
Topology architecture, including the deployment of several nodes of the architecture, the relationship between nodes, the high availability of servers, network interfaces and protocols, etc., determines how the application runs, the performance of the operation, maintainability, scalability, and is the basis of all architectures. This figure is the main focus of O&M engineers.
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122589 "what is the real architecture design?" )
The physical architecture mainly considers hardware selection and topology, software-to-hardware mapping, and the interaction between hardware and software.
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122591 "what is the real architecture design?" )
III. Architecture level
We use the architectural level of the pyramid to illustrate that the upper level contains the lower level:
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122592 "what is the real architecture design?" )
- ** System-level ** : that is, the relationship between the parts of the whole system and how to govern it: Stratification
- ** Application level ** : that is, the overall architecture of a single application, and its relationship with a single application in the system.
- ** Module level ** : that is, the internal module architecture of the application, such as the modularization of code, data and state management.
- ** Code level ** : That is, from the code level guarantee architecture implementation.
** Strategic design and Tactical design **
Based on the architecture pyramid, we have the perfect combination of strategic design and tactical design of the system architecture:
- ** Strategic Design ** : Business architecture is used to guide the architect on how to design the system architecture.
- ** Tactical Design ** : Application architecture should be designed according to business architecture.
- ** Tactical implementation ** : After the application architecture is determined, it is the technology selection.
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122594 "what is the real architecture design?" )
- Evolution of application architecture
Business architecture is productivity, application architecture is production relations, and technology architecture is production tools. The business architecture determines the application architecture, and the application architecture needs to adapt to the business architecture and evolve with the business architecture. At the same time, the application architecture relies on the technology architecture to finally land.
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122593 "what is the real architecture design?" )
Architecture evolution path: Single application → distributed application service → Microservice
**4.1. Single application **
At the beginning of the enterprise, the business is relatively simple, only a simple scenario is applied, and the application service supports data addition, deletion, modification and check and simple logic. Single application can meet the requirements.
Typical three-level architecture, front-end (Web/ mobile) + intermediate business logic layer + database layer. This is a typical Java Spring MVC or Python Django framework application. Its architecture diagram is shown below:
! [What is real architecture design?] (https://segmentfault.com/img/remote/1460000023122595 "what is the real architecture design?" )
Approaches for monomer applications, non-functional requirements:
- Performance requirements: Use caching to improve performance
- Concurrency requirements: Use clusters to improve concurrency
- Read/write separation: read/write separation of the database
- Use reverse proxies and cdn acceleration
- Use distributed files and distributed databases
Monolithic applications are easier to deploy and test, and work well in the early stages of a project. However, as demand continues to increase and more and more people join the development team, the codebase is also expanding rapidly. Slowly, the single application becomes more and more bloated, the maintainability and flexibility are gradually reduced, and the maintenance cost is becoming higher and higher. Here are some disadvantages of monolithic applications:
- ** High complexity ** : Taking a single application of millions of lines as an example, the entire project contains very many modules, the boundaries of modules are fuzzy, the dependencies are not clear, the code quality is uneven, and the confusion is piled together. As you can imagine, the whole project is very complicated. Every time you change the code, even adding a simple feature, or fixing a Bug will introduce an implicit flaw.
- ** Technical debt ** : As time goes by, requirements change and personnel change, the technical debt of the application will gradually form and accumulate. "Don't break, don't fix", this is very common in software development, and this idea is even more common in monolithic applications. A used system design or code is difficult to modify because other modules in the application may use it in unexpected ways.
- ** Low deployment frequency ** : As the code increases, the build and deployment time increases. In monolithic applications, each feature change or bug fix results in the need to redeploy the entire application. Full deployment takes a long time, has a large impact, and is high in risk. As a result, single application projects are rarely deployed online. The low deployment frequency leads to a large number of functional changes and bug fixes between releases, and the error rate is relatively high.
- ** Poor reliability ** : An application Bug, such as a dead loop or memory overflow, may cause the entire application to crash.
- ** Limited expansion ability ** : A single application can only be expanded as a whole, and cannot be scaled according to the needs of the business module. For example, some modules in the application are computationally intensive and require a powerful CPU. Some modules are IO intensive and require more memory. As these modules are deployed together, compromises have to be made in the choice of hardware. ** Hinder technological innovation ** : Single applications often use a unified technology platform or solution to solve all problems, every member of the team must use the same development language and framework, it is very difficult to introduce a new framework or a new technology platform.
**4.2. Distributed **
With the deepening of the business, the business requires more and more product functions, and the logic of each business module becomes more complex, and the depth and breadth of the business increase, making the single application become more and more bloated, the maintainability and flexibility gradually reduce, the development cycle of adding new functions becomes longer and longer, and the maintenance cost becomes higher and higher.
At this time, it is necessary to split the system according to business function modules, and turn each module into a distributed system. Service modules are deployed on different servers and communicate with each other through interfaces.
Compared with the single architecture, this architecture provides the ability of load balancing, greatly improves the system load capacity, and solves the needs of high concurrency of the website. There are also the following features:
- ** Reduces the coupling degree ** : Split the module, use interface communication, reduce the coupling degree between the modules.
- ** Clear responsibility ** : Divide the project into several sub-projects, with different teams responsible for different sub-projects.
- ** Easy to expand ** : Only need to add a subproject when increasing the function, call the interface of other systems can be.
- ** Easy deployment ** : Flexible distributed deployment.
- ** Improve code reusability ** : For example, if the Service layer does not adopt the distributed rest Service architecture, a service layer logic will be written on each end of the mobile Wap mall, wechat mall, PC, Android and iOS. The development is large and it is difficult to maintain and upgrade together. At this time, distributed rest service mode can be adopted. Share a service layer.