To make good use of microservices, first clarify the relationship between distributed and microservices

Time:2022-5-6

1、 Definition of distributed and microservice architecture

Distributed application scenarios cover a wide range of areas. What I understand is:

  • Communication between different processes,
  • Called between distributed objects of different hosts,
  • Distributed file system for big data storage,
  • A naming service for mutual recognition between networks,
  • A centerless peer-to-peer model for computing or storage in a cluster,
  • Distributed transactions,
  • Replication of data copies in a distributed environment,
  • Cloud computing services,
  • On demand and transmission of audio and video in network
  • ….

The purpose of microservice architecture is to decouple the originally too large and heavy cloud application services by means of reasonable business module disassembly. The granularity of disassembly is often mastered by architects to realize fine-grained services, and services form a distributed state in the cloud.

Then microservices have some distributed application scenarios, such as calling between distributed objects of different hosts. In the past, EJB used RMI (remote method call), but now microservices often use RPC (remote procedure call); Another example: the naming service used for mutual recognition between networks. In the past, EJB was a JNDI naming service. Now, euraka of spring cloud is used for micro service registration and discovery. It is also a distributed naming service.

How to understand “distributed system” popularly, what problems it solves, and what are its advantages and disadvantages?

Understand what happened to distributed systems

The above is my other answer. It describes in detail the comparison between EJB and spring in the past, as well as the comparison between distributed and single applications. At that time, EJB represented distributed services and spring represented single services.

To make good use of microservices, first clarify the relationship between distributed and microservices

The figure above simply depicts the process of disassembling the simplest single service into micro service. Of course, the challenges faced by microservices are not so simple. This is just an initial state of microservices.

2、 What problems do distributed and microservices solve

Distributed computing is the form and state of communication and cooperation among computing, service and storage in the network

What does distributed solve?

To make good use of microservices, first clarify the relationship between distributed and microservices

The figure above is a typical distributed computing. A large file is cut into four parts, MapReduce is divided into four tasks (processes), and then data processing is carried out on the same host, different processes or different hosts, and finally converged to a consolidated task through the network. At this time, distributed tasks are parallel, which solves the efficiency problem of single task.

To make good use of microservices, first clarify the relationship between distributed and microservices

The above figure is a typical distributed state coordination and management diagram. It is the HA high availability architecture of Hadoop HDFS cluster. The primary and secondary namonode nodes must be alive. When it is judged that the primary node is hung, the secondary node must be on top. At this time, the cluster composed of three ZKS (zookeeper) acts as the coordinator of the primary and secondary nodes to monitor the heartbeat of the namoenode and issue switching commands through the zkfc process.

In addition, the cluster formed by the three journalnode nodes is the place where namonode distributed state data is saved. When the primary namonode hangs, all States must be quickly restored to the secondary namenode. Therefore, the journalnode must continue to synchronize state to meet the rapid recovery of HDFS cluster state

Then, a very key application scenario in distributed – cluster. The above Hadoop HDFS cluster needs to have one or more roles (zookeeper, journalnode) as the coordinator and manager of the cluster state. Sometimes this state management is peer-to-peer (glusterfs), and sometimes this state management is centralized (as is the case with Hadoop).

What problems does microservice solve?

If you are raising the distributed advantage of microservices at this time, it is not an end, but a means. Microservices only achieve their own goals with the help of distributed architecture. Therefore, microservices are not the problem of infrastructure technology, but the architecture of upper application.

To make good use of microservices, first clarify the relationship between distributed and microservices

The above example is a simple single application of internet medical service. At this time, consultation, medicine, order and instant messaging are the core businesses of Internet Medical. The purpose of information push is to push, publish and exchange all kinds of information of internet medical platform on Internet information service platform, so as to achieve the purpose of self promotion.

However, the update degree of information push service is very high. Because the Internet service platform that needs to be connected to the outside world is complex, and new service platforms will be included in the scope of modules, there is such a deployment problem as a single application. Each time a new information push function is updated, the overall service needs to be redeployed. Then this impact has caused great trouble to the core service. At this time, patients The business impact of doctors and hospitals is large-scale.

To make good use of microservices, first clarify the relationship between distributed and microservices

Take another look at the microservice architecture. If the information push service exists as a separate microservice, other microservices can only remotely call the content that needs to be pushed to the Internet service platform, or even package it into messages in the way of message center to realize message event drive, so that the deployment of external publishing services will not interfere with other core services, so as to minimize the impact of the overall platform due to deployment and publishing. Does this method look much more comfortable, which is very conducive to deployment and release, and even enhances the robustness of the overall system.

Of course, there are still many problems solved by microservices, such as the fine-grained division of labor, the improvement of iteration speed, easier small-scale reconfiguration, conducive to continuous integration (Devops), and so on. I won’t describe them one by one in detail, but only take out the parts with great characteristics.

3、 Advantages and disadvantages of these architectures

Distributed corresponds to a single machine. Its advantages are described in the previous section, which will not be repeated, and its disadvantages are also great
Deployment and operation and maintenance are not simple
Network bottlenecks and failures can have an important impact,
If a node fails, there must be a detection and hot replacement mechanism,
Consistency issues, such as distributed transactions, have always been a worldwide problem,
We should not only consider load balancing, but also consider the effect of load balancing.
For distributed storage of data, the problem of data skew should be considered in some peer-to-peer modes.
In addition to the disadvantages 6 of distributed storage, the first five disadvantages of microservice are basically perfectly inherited.

4、 Technical debt caused by improper utilization

Let’s talk about the troublesome problem of improper design of micro services

(1) After the micro service is decoupled, some business programs will change from the original database query mode to remote object call. I mentioned this process in the original answer, which is anti human. The complexity of formation and the interfaces that need to be agreed bring more workload than SQL query. Moreover, the more anti human way is that the database is also divided along with the micro service. What data needs redundancy and what data can maintain the database paradigm can basically annoy the elevation people.

(2) Inexperienced microservice architects are easy to cut microservices too thin. If a single body is cut into 1000 microservices, and remote object serialization and deserialization are used between microservices, then this will become a dead end! Because once the entity object of a microservice is adjusted, how many associated microservices are polluted, it is necessary to constantly locate the dependencies of other microservices and republish them. This workload has exceeded the workload of solving business problems.

Therefore, we must pay attention to the division of microservices, and the object transfer between RPCs should be done with a simple and loose structure as far as possible. The degree of microservice division varies according to different businesses. There is an agreement that a microservice needs a week for large-scale reconstruction as the microservice granularity standard.

5、 The direct use of microservice architecture in the project is based on the consideration of the future?

The consideration of microservice architecture should not be about the future, but a kind of architecture reconstruction after the problems of single application in the past. The reconstruction process can be seen from the figure in Section 1. In the example of Internet medicine, the reconstruction of microservice further tends to be message driven and event driven.

From the experience and lessons learned from the previous implementation of microservices, if you are an architect of a new project, you can first choose a single application, and then iterate and reconstruct it to microservices according to the business development. Even if the architecture of microservices in the process is not so pure, and even if single applications and microservices coexist for a long time, you should carefully design microservices directly from the new project.

Because no one is a fortune teller. If you can estimate the day, level and scope of your business system, you must need microservice decoupling. Only when the system is running to that stage, can it be easier for architects to make reasonable microservice service decisions. Of course, some people will have doubts. If the system is designed as a single body, who still wants to continue to reconstruct microservices, it would be easier to directly make a microservice architecture. What I want to say is that if there is no reconstruction, don’t think of microservices.

6、 What are the differences and connections between k8s and spring cloud?

Spring cloud is a specific implementation framework to implement the microservice architecture, including springboot as an independent running container of microservices, euraka as the registration and discovery of microservices, zuul service gateway, and others. In fact, I prefer openresty as the gateway.

K8s is just an arrangement framework for containers. Managers have a large number of docker containers, but now k8s does not integrate dockers, so I feel dizzy!

As a container of micro services, docker provides separate infrastructure such as network, file system and process management for each micro service, so that the status and operation log of each micro service can be better monitored and managed. In addition, the container makes the deployment process simple and promotes the popular management mode of Devops development, release and deployment. The containerization of micro services is actually a natural couple.

7、 Ending

When we understand the existence form of various scenarios under distribution and the distributed scenario of microservices, we can make better design decisions of microservices.

Go to read bytes – learn more about big data

Official account “read bytes” distributed, big data, depth of software architecture, professional interpretation