Guide language as the Internet industry is now a more popular concept, micro services. Combined with the concept of self-sufficiency of resources on the web, there will be new technology-based articles in the future. First of all, before understanding the microservice architecture, we need to understand the concepts of distribution, cluster, etc. Here is a summary from the perspective of the architecture. So let’s start with the monomer architecture.

1. Monomer architecture

1. Single architecture

Unitary architecture is also called unitary system or unitary application. It is an architecture mode in which all functions and modules in a system are coupled in an application. In a simple way, the entire application, including applications and databases, is on the same server. Distributed from a simple point of view is to separate the application and data to different servers, and then for the application and database performance optimization in different directions and so on.

2. Single architecture features

Once deployed, the application is packaged as a separate unit (the import is called a JAR package or a WAR package) and runs as a process

Advantages and disadvantages of a single architecture

advantages

Easy project management

The deployment of simple

disadvantages

High cost of testing

Poor scalability

Poor reliability

Iterations difficult

Poor across languages

Teamwork is difficult

Second, micro-service architecture

1. What are microservices

Microservice is an architectural style. A large and complex software application is composed of one or more microservices. Each microservice in the system can be deployed independently and is loosely coupled. It takes a complex software system and disintegrates it inhumanely, but after disintegrating it, the complex application system becomes more efficient.

2. Architectural style

An architectural style is a design pattern for a project. There are four common programming patterns. A detailed comparison of the pros and cons of each pattern follows.

Common architectural styles

Client and server: includes C/S and B/S, but B/S is special.

Component Model-based Architecture (EJB)

Layered Architecture (MVC)

Service-oriented Architecture (SOA)

3. Features of micro-services

(1) The system is composed of multiple services

(2) Each service can be deployed independently

(3) Each service is loosely coupled. The internal service is highly cohesive, while the external service is low coupling, which is also in line with the principle of software design. High cohesion means that the internal relationship of each service is very close, and each service only focuses on one function.

4. Advantages and disadvantages of microservices

advantages

The test is easy to

High scalability

reliability

The cross-language level will be more flexible

Easy teamwork

Easy system iteration

disadvantages

The operation and maintenance cost is high and the number of deployments is large

Interface compatible with multiple versions

The complexity of distributed systems

Distributed transaction

3. Differences between MVC, RPC, SOA and microservices architectures

# # # 1. MVC architecture

MVC is essentially a design pattern, a single architecture. Representative technologies: Struts2, SpringMVC, Spring, Mybatis, Hibernate and so on.

# # # 2. RPC architectures

Remote Procedure Call (RPC) is a protocol for Remote computer requests over a network without understanding the underlying network technology. Stands for technology, Thrift, Hessian, etc

# # # SOA architecture

Service Oriented Architecture (SOA)

Enterparise Service Bus (ESB) : Enterprise Bus service, service mediation. It mainly provides interactions between services.

The ESB includes functions such as load balancing, flow control, encryption, service monitoring, exception handling, monitoring warnings, and so on.

Representative technologies: Mule, WSO2, etc

Microservices Architecture

Microservices is a lightweight service governance solution that represents technologies: SpringCloud, Dubbo, etc

How to design microservices and their design principles

1.AKF splitting principle

2. Front end and back end separation principle

3. Stateless service

RestFul traffic style

1.AKF splitting principle

The industry has a naive concept of scalable system architecture that solves capacity and availability problems by adding machines. So if one machine is not enough, use two machines.

This concept is widely recognized in today’s society where the concept of “cloud computing” is wildly popular. For a rapidly growing system, the most discussed issues are capacity and performance. However, with the advancement of time and the growth of system scale, in addition to the problems of performance and capacity, we also need to face the problems of system complexity caused by the increase in the number of functions and modules, as well as the problems of providing differentiated services caused by business changes. However, many system redesign did not fully consider this problem, resulting in system reconfiguration has become the norm, thus affecting the business delivery ability, but also a waste of human and financial resources! In this regard, the book “The Art of Extensibility” proposes a more systematic extensibility model — AKF Extensibility Cube. The cube is XYZ along the three axes.

Y-axis (function)

Y-axis scaling increases the fragmentation of a large overall application into multiple services. Each service implements a set of related functions, such as order management, customer management, and so on. A common solution in engineering is service-oriented architecture (SOA). For example, for an e-commerce platform, we can split it into different services to form the following architecture:

But looking at the figure above, it is easy to see that as the number of services increases, the service invocation relationship becomes more complex. Add a new function to the system, and the number of services to be called becomes uncontrollable, causing chaos in service management. Therefore, in general, it is necessary to adopt the mechanism of service registration to form a service gateway for service governance, and the architecture design of the system will be as follows:

X axis (horizontal extension)

The X-axis extension is oriented toward the front of the simple idea is consistent, through absolutely equal service replication services with data, one solves the problem of capacity and availability. In fact, it is the mode of cluster plus load balancing by using multiple instances of micro-services.

In order to improve the availability and capacity of individual services, each service is divided on the X axis.

Z-axis (Data partitioning)

Z-axis scaling usually refers to the partitioning of the system based on the unique requirements of the requester or user, so that the subsystems divided are isolated from each other but complete. Take the factory producing cars as an example: In order to develop business in China or take advantage of cheap labor in China, Ford company establishes a complete sub-factory in China, which is responsible for complete car production just like the American factory. This is the Z-axis expansion.

There are two common z-axis extension schemes in the engineering field:

Unit Architecture In distributed service design, a Cell is a self-contained closed loop that satisfies all business operations of a partition. For example, with the Y-axis extension SOA architecture we mentioned above, the client’s selection of service nodes is generally random. However, with the Z-axis extension, the selection of service nodes is no longer random, but each unit is self-contained, as shown in the figure below

Data partition

For the sake of performance data security, we divide a complete data set into different subsets according to certain dimensions. A partition (Shard) is a subset of the overall data set. For example, users with the same tail number can be considered as a partition. Data partitioning generally includes the following data partitioning methods

Data type For example, business type

Data range such as time range, user ID

Data heat such as user activity, product heat

For example, product description, product inventory

2. Front end and back end separation principle

What is front-end and back-end separation! The front end and the back end are generally conceptually separate. This should start from JSP technology, fine division of labor can make a cake bigger, multiple field engineers had better not need to contact the knowledge of other fields under the condition of cooperation, it is possible to be more and more efficient. Maintenance will become easier and easier. Jsp template technology, the integration of HTML and Java code, making the traditional MVC development of front-end and back-end in the inseparable, the front end of the work is well done page, the back-end to the template, found that the problem solves in go to the front, the front and can’t read Java code, the purpose of the separation of front and back side is to break this embarrassing situation.

The principle of front-end and back-end separation, simply speaking, is the separation of front-end and back-end code, we recommend that the best way to deploy physical separation, to further promote a more complete separation, if you continue to directly use server-side template technology, such as JSP heap Java, JS, HTML, CSS into a page, Slightly more complex pages are impossible to maintain.

This separation has several benefits

Before and after the separation technology, can be caused by their own expertise to optimize the respective fields, so the front user experience optimization better separation mode, before and after the end of the interactive interface is clearer, leaves interface model, the backend interface profile, easier to maintain Front multi-channel integration scenarios are easier to implement, the back-end server without change, using the unified data and model, It can support multiple front ends, such as wechat H5 front end, PC front end, Android front end and IOS front end 3. Stateless service

For stateless services, let’s start with what state is: if a piece of data needs to be shared by multiple services in order to complete a transaction, that data is called state. Services that in turn depend on data in this state are said to be stateful services and stateless services

3. Differences between MVC, RPC, SOA and microservices architectures

1. The MVC architecture

MVC is essentially a design pattern, a single architecture. Representative technologies: Struts2, SpringMVC, Spring, Mybatis, Hibernate and so on.

2. The RPC architectures

Remote Procedure Call (RPC) is a protocol for Remote computer requests over a network without understanding the underlying network technology. Stands for technology, Thrift, Hessian, etc

SOA architecture

Service Oriented Architecture (SOA)

Enterparise Service Bus (ESB) : Enterprise Bus service, service mediation. It mainly provides interactions between services.

The ESB includes functions such as load balancing, flow control, encryption, service monitoring, exception handling, monitoring warnings, and so on.

Representative technologies: Mule, WSO2, etc

Microservices Architecture

Microservices is a lightweight service governance solution that represents technologies: SpringCloud, Dubbo, etc

How to design microservices and their design principles

1.AKF splitting principle

2. Front end and back end separation principle

3. Stateless service

RestFul traffic style

1.AKF splitting principle

The industry has a naive concept of scalable system architecture that solves capacity and availability problems by adding machines. So if one machine is not enough, use two machines.

This concept is widely recognized in today’s society where the concept of “cloud computing” is wildly popular. For a rapidly growing system, the most discussed issues are capacity and performance. However, with the advancement of time and the growth of system scale, in addition to the problems of performance and capacity, we also need to face the problems of system complexity caused by the increase in the number of functions and modules, as well as the problems of providing differentiated services caused by business changes. However, many system redesign did not fully consider this problem, resulting in system reconfiguration has become the norm, thus affecting the business delivery ability, but also a waste of human and financial resources! In this regard, the book “The Art of Extensibility” proposes a more systematic extensibility model — AKF Extensibility Cube. The cube is XYZ along the three axes.

Y-axis (function)

Y-axis scaling increases the fragmentation of a large overall application into multiple services. Each service implements a set of related functions, such as order management, customer management, and so on. A common solution in engineering is service-oriented architecture (SOA). For example, for an e-commerce platform, we can split it into different services to form the following architecture:

But looking at the figure above, it is easy to see that as the number of services increases, the service invocation relationship becomes more complex. Add a new function to the system, and the number of services to be called becomes uncontrollable, causing chaos in service management. Therefore, in general, it is necessary to adopt the mechanism of service registration to form a service gateway for service governance, and the architecture design of the system will be as follows:

X axis (horizontal extension)

The X-axis extension is oriented toward the front of the simple idea is consistent, through absolutely equal service replication services with data, one solves the problem of capacity and availability. In fact, it is the mode of cluster plus load balancing by using multiple instances of micro-services.

In order to improve the availability and capacity of individual services, each service is divided on the X axis.

Z-axis (Data partitioning)

Z-axis scaling usually refers to the partitioning of the system based on the unique requirements of the requester or user, so that the subsystems divided are isolated from each other but complete. Take the factory producing cars as an example: In order to develop business in China or take advantage of cheap labor in China, Ford company establishes a complete sub-factory in China, which is responsible for complete car production just like the American factory. This is the Z-axis expansion.

There are two common z-axis extension schemes in the engineering field:

Unit Architecture In distributed service design, a Cell is a self-contained closed loop that satisfies all business operations of a partition. For example, with the Y-axis extension SOA architecture we mentioned above, the client’s selection of service nodes is generally random. However, with the Z-axis extension, the selection of service nodes is no longer random, but each unit is self-contained, as shown in the figure below

Data partition

For the sake of performance data security, we divide a complete data set into different subsets according to certain dimensions. A partition (Shard) is a subset of the overall data set. For example, users with the same tail number can be considered as a partition. Data partitioning generally includes the following data partitioning methods

Data type For example, business type

Data range such as time range, user ID

Data heat such as user activity, product heat

For example, product description, product inventory

2. Front end and back end separation principle

What is front-end and back-end separation! The front end and the back end are generally conceptually separate. This should start from JSP technology, fine division of labor can make a cake bigger, multiple field engineers had better not need to contact the knowledge of other fields under the condition of cooperation, it is possible to be more and more efficient. Maintenance will become easier and easier. Jsp template technology, the integration of HTML and Java code, making the traditional MVC development of front-end and back-end in the inseparable, the front end of the work is well done page, the back-end to the template, found that the problem solves in go to the front, the front and can’t read Java code, the purpose of the separation of front and back side is to break this embarrassing situation.

The principle of front-end and back-end separation, simply speaking, is the separation of front-end and back-end code, we recommend that the best way to deploy physical separation, to further promote a more complete separation, if you continue to directly use server-side template technology, such as JSP heap Java, JS, HTML, CSS into a page, Slightly more complex pages are impossible to maintain.

This separation has several benefits

Before and after the separation technology, can be caused by their own expertise to optimize the respective fields, so the front user experience optimization better separation mode, before and after the end of the interactive interface is clearer, leaves interface model, the backend interface profile, easier to maintain Front multi-channel integration scenarios are easier to implement, the back-end server without change, using the unified data and model, It can support multiple front ends, such as wechat H5 front end, PC front end, Android front end and IOS front end 3. Stateless service

For stateless services, let’s start with what state is: if a piece of data needs to be shared by multiple services in order to complete a transaction, that data is called state. Services that in turn depend on data in this state are said to be stateful services and stateless services

The stateless service principle does not mean that stateless services are not allowed in microservices. What it really means is that all stateless business services should be changed into stateless computing services, and stateful data should be migrated to corresponding stateful data services accordingly.

Scenario Description: For example, the data cache and Session cache established in local memory should be transferred to distributed cache for storage in the current microservice architecture, so that the business service becomes a stateless computing node. After migration, dynamic scaling can be achieved on demand, and micro service applications can dynamically add and delete nodes at runtime, without considering how to synchronize cached data.

4.RestFul communication style

As a principle, it should be a “stateless communication principle”. Here is a direct recommendation for a preferred RestFul communication style in practice because it has many benefits:

Stateless protocol HTTP has inherent advantages and strong expansion capabilities. For example, secure encryption is required. The existing mature solution HTTPS can serialize JSON packets, which is lightweight and simple, readable by both human and machine, with low learning cost and irrelevant to search engine friendly languages. A more complete ecosystem than some other RPC frameworks.