Five common software architectures

Insert picture description here

1. What is the concept of software architecture and the definition of architecture:

1. The software architecture is a sketch of a system.
2. The objects described by the software architecture are abstract components that directly constitute the system.
3. The connection between the components clearly and relatively detailed description of the communication between the components.
4. In the implementation phase, these abstract components are refined into actual components, such as a specific class or object.
5. In the object-oriented field, the connection between components is usually realized by interfaces.

2. Architects are subdivided, which can basically be divided into three categories:

System architect: server load, reliability, scalability, expansion, database segmentation, cache application, etc.
Application architect: understand business, sort out models, design patterns, interfaces, data interaction, etc.
Business Architect: It can also be called business domain experts, industry experts, product consultants, and senior consultants. Usually we call architects a combination of 1 and 2.

Three, five common software architectures

Software architecture is the basic structure of software.

The right 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.

1. 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, without knowing 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.
Insert picture description here

    表现层(presentation):用户界面,负责视觉和用户互动
    业务层(business):实现业务逻辑
    持久层(persistence):提供数据,SQL 语句就放在这一层
    数据库(database) :保存数据

Some software adds a service layer (service) between the logic layer and the persistence layer to provide some common interfaces required by different business logic.

The user's request will be processed through these four layers in turn, and no one of them can be skipped.
Insert picture description here

advantage

    结构简单,容易理解和开发
    不同技能的程序员可以分工,负责不同的层,天然适合大多数软件公司的组织架构
    每一层都可以独立测试,其他层的接口通过模拟解决

Disadvantage

    一旦环境变化,需要代码调整或增加功能时,通常比较麻烦和费时
    部署比较麻烦,即使只修改一个小地方,往往需要整个软件重新部署,不容易做持续发布
    软件升级时,可能需要整个服务暂停
    扩展性差。用户请求大量增加时,必须依次扩展每一层,由于每一层内部是耦合的,扩展会很困难

Two, event-driven 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.
Insert picture description here

    事件队列(event queue):接收事件的入口
    分发器(event mediator):将不同的事件分发到不同的业务逻辑单元
    事件通道(event channel):分发器与处理器之间的联系渠道
    事件处理器(event processor):实现业务逻辑,处理完成后会发出事件,触发下一步操作

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.

advantage

    分布式的异步架构,事件处理器之间高度解耦,软件的扩展性好
    适用性广,各种类型的项目都可以用
    性能较好,因为事件的异步本质,软件不易产生堵塞
    事件处理器可以独立地加载和卸载,容易部署

Disadvantage

    涉及异步编程(要考虑远程通信、失去响应等情况),开发相对复杂
    难以支持原子性操作,因为事件通过会涉及多个处理器,很难回滚
    分布式和异步特性导致这个架构较难测试

Three, micronucleus architecture

Microkernel architecture, also known as "plug-in architecture", refers to the relatively small core of the software, and the main functions and business logic are implemented through plug-ins.

The core usually contains only the smallest functions that the system runs. Plug-ins are independent of each other, and communication between plug-ins should be reduced to a minimum to avoid interdependence.
Insert picture description here

advantage

    良好的功能延伸性(extensibility),需要什么功能,开发一个插件即可
    功能之间是隔离的,插件可以独立的加载和卸载,使得它比较容易部署,
    可定制性高,适应不同的开发需要
    可以渐进式地开发,逐步增加功能

Disadvantage

    扩展性(scalability)差,内核通常是一个独立单元,不容易做成分布式
    开发难度相对较高,因为涉及到插件与内核的通信,以及内部的插件登记机制

Four, microservice architecture

Microservices architecture (microservices architecture) is an upgrade of service-oriented architecture (SOA).

Each service is an independent deployment unit (separately deployed unit). These units are distributed, decoupled from each other, and connected through remote communication protocols (such as REST, SOAP).
Insert picture description here

The microservice architecture is divided into three implementation modes.

    RESTful API 模式:服务通过 API 提供,云服务就属于这一类
    RESTful 应用模式:服务通过传统的网络协议或者应用协议提供,背后通常是一个多功能的应用程序,常见于企业内部
    集中消息模式:采用消息代理(message broker),可以实现消息队列、负载均衡、统一日志和异常处理,缺点是会出现单点失败,消息代理可能要做成集群

advantage

    扩展性好,各个服务之间低耦合
    容易部署,软件从单一可部署单元,被拆成了多个服务,每个服务都是可部署单元
    容易开发,每个组件都可以进行持续集成式的开发,可以做到实时部署,不间断地升级
    易于测试,可以单独测试每一个服务

Disadvantage

    由于强调互相独立和低耦合,服务可能会拆分得很细。这导致系统依赖大量的微服务,变得很凌乱和笨重,性能也会不佳。
    一旦服务之间需要通信(即一个服务要用到另一个服务),整个架构就会变得复杂。典型的例子就是一些通用的 Utility 类,一种解决方案是把它们拷贝到每一个服务中去,用冗余换取架构的简单性。
    分布式的本质使得这种架构很难实现原子性操作,交易回滚会比较困难。

Five, cloud architecture

Cloud architecture mainly solves the problems of scalability and concurrency, and is the easiest architecture to expand.

Its high scalability is mainly due to the fact that it does not use the central database, but copies all the data into the memory to become a reproducible memory data unit. Then, the business processing capabilities are packaged into a processing unit (prcessing unit). When the number of visits increases, a new processing unit is created; when the number of visits decreases, the processing unit is closed. Since there is no central database, the biggest bottleneck of scalability disappears. Since the data of each processing unit is in memory, it is best to perform data persistence.

This model is mainly divided into two parts: processing unit and virtualized middleware.

    处理单元:实现业务逻辑
    虚拟中间件:负责通信、保持sessions、数据复制、分布式处理、处理单元的部署。

Insert picture description here

Virtual middleware also contains four components.

    消息中间件(Messaging Grid):管理用户请求和session,当一个请求进来以后,决定分配给哪一个处理单元。
    数据中间件(Data Grid):将数据复制到每一个处理单元,即数据同步。保证某个处理单元都得到同样的数据。
    处理中间件(Processing Grid):可选,如果一个请求涉及不同类型的处理单元,该中间件负责协调处理单元
    部署中间件(Deployment Manager):负责处理单元的启动和关闭,监控负载和响应时间,当负载增加,就新启动处理单元,负载减少,就关闭处理单元。

advantage

    高负载,高扩展性
    动态部署

Disadvantage

    实现复杂,成本较高
    主要适合网站类应用,不合适大量数据吞吐的大型数据库应用
    较难测试

Guess you like

Origin blog.csdn.net/m0_46864744/article/details/111945149