1. What is hierarchical architecture

The system is divided vertically into several layers, with each layer having independent functions and multiple layers cooperating to provide complete functions

Common layered models

The name of the Implementation details The picture
MVC Model View Controller
web+service+dao Presentation layer: display user instructions

Logical layer: The concrete implementation of complex business

Data access layer: Handles interactions with storage

Examples of layering

The name of the Implementation details The picture
OSI 7-layer network model TCP/IP 4-layer protocol Network layer: responsible for end-to-end addressing and establishing connections

Transport layer: End-to-end data transfer

Two adjacent layers have data interaction isolation concerns, with different layers focusing on different things
Linux file system VFS: a virtual file system that hides differences between systems

A hierarchy is an abstraction of the different implementations at a lower level

2. Advantages and disadvantages of stratification

Advantages of layering Disadvantages of stratification
Layering simplifies system design, with different people focusing on one level

Technology market: API, Mid-platform, infrastructure
Increase the complexity of your code

Simple queries that require data transfer between each level
Layering can be highly reusable

Central, Biz – Lib, BIZ -common
Each layer is deployed separately to increase network interaction
Layering makes it easy to scale horizontally

Extend for bottlenecks at one level
CPU usage (adding machines), slow disk read/write (SSD)….

3. How to layer

The boundaries of stratification need to be considered clearly

Due to changes in requirements and business complexity, layering becomes blurred

Terminal display layer: the layer where the end templates render and perform display. Currently, Velocity rendering, JS rendering, JSP rendering, mobile terminal display, etc.

Open interface layer: encapsulates Service layer methods as open interfaces, and implements gateway security control and flow control.

Web layer: it mainly forwards access control, verifies all kinds of basic parameters, or simply deals with services that do not reuse.

Service layer: business logic layer.

Manager layer: Common business processing layer. This layer has two main functions. First, you can sink some of the common capabilities of the original Service layer into this layer, such as the interaction strategy with cache and storage, middleware access. Second, you can also encapsulate calls to third-party interfaces in this layer, such as payment services, auditing services, etc

DAO layer: Data access layer, which interacts with MySQL, Oracle, and HBase at the bottom.

External interface or third party platform: including RPC open interface of other departments, base platform, HTTP interface of other companies

The Manager layer provides the atomic Service interfaces (the results of multiple calls are consistent), and the Service layer is responsible for orchestrating the atomic interfaces according to the business logic.

4. To summarize

Layered architecture is the external embodiment of software design thought and is a way of implementation.

Single principle: Each layer has a single responsibility

Demeter’s law: data interaction cannot be carried out across layers, but must be carried out between adjacent layers

Open and close principle: the abstraction layer is separated from the implementation layer. The abstraction layer is the summary of the common characteristics of the implementation layer (not modifiable), and the concrete implementation is infinite expansion (optional replacement).

When the complexity of a layer becomes too high, it is split into multiple layers