[SOA] From Monolithic Architecture to Distributed Microservice Architecture

foreword

In 2016, the first live broadcast of Station B of the bureau , due to the sudden influx of viewers, the live broadcast system of the website collapsed. The early Bilibili did not start with live broadcasting. At that time, the live broadcasting system was still a single architecture system written in php, that is, LAMP (Linux+Apache+MySql+PHP). Basically all modules were coupled together, like this:
insert image description here
done Everyone in a single project knows that as long as one of the submodules in the project goes wrong, it may bring down the entire system.
Here is a story I personally experienced:
When I was doing St. Regis takeaway (a SpringBoot+MySQL single project) I used Jmeter to open up 1000 threads to test the interface performance (without caching). As a result, the database hangs up halfway through the test case execution. Naturally, the functions of the sub-modules cannot take effect and the coupled modules fail. When the request to access the interface of other modules returns results like dominoes are all ERROR, the monolithic architecture appears pale and powerless when this happens.

img
Back to the topic, under such a sudden high concurrency situation, the sub-modules must not be able to withstand the pressure, so the live broadcast system of the entire station B collapsed~ It is also since then that station B has slowly changed from Php to Go, by The monolithic architecture has transformed into a microservice architecture. So, what is a monolithic architecture? Why did you use a monolithic architecture before? What is Microservice Architecture?

Monolithic Architecture System

All functional units of the entire system are deployed in the same process as a whole (all codes can be packaged into one or more files), we can call it a "single system"
such as (SSM+Tomcat+Mysql) business logic layer The service, controller and dao layer of the data access layer are packaged into a war package and deployed on Tomcat or Jetty or other containers. The
insert image description here
advantages of such a system are particularly obvious:

It is easy to develop, test, and deploy , and because the calling process of each function, module, and method is called within the process, there will be no inter-process communication, so the operating efficiency of the program is also higher than that of the distributed system. All code runs in the same process space, and all modules and method calls do not need to consider network partitions, object replication and other troublesome things, and do not worry about performance loss due to data exchange.

But the disadvantages are also very fatal:

When the business becomes more and more complex, the scalability of the single architecture is insufficient, and the cost of business expansion is increasing . There are more and more users, and the concurrency of the program is getting higher and higher. The concurrency capability of a single application is very limited, because all the codes share a process space. Once a memory leak, thread explosion, or blockage occurs during the running of the program , deadlock, infinite loop and other problems will affect the operation of the entire program, not just the normal operation of a certain function or module itself; and if some higher-level public resources are consumed, such as port occupation Too many or database connection pool leaks will also affect the entire machine, and even the normal work of other single copies in the cluster.
insert image description here
When I was studying Spring's IOC before, I mentioned its "decoupling" feature. IOC reduces the coupling between classes, but leaving the scope of classes, the coupling between modules in a single system is always guaranteed. less than lowered.

Microservice architecture system

The above-mentioned shortcomings drive the evolution of the architecture, from the initial horizontal architecture to the vertical architecture to the final distributed architecture... As a perfect solution for distributed architecture, "microservice" has become very popular in recent years.

As the name implies, microservices-split a system into several independent modules, which run in independent processes. Each sub-module is also called a "micro-service", and each service has its own database, which greatly reduces the probability of accidents.
insert image description here
In the monolithic architecture, all sub-modules are in the same process, and there is no call between processes. When a module wants to call another module, it directly injects the instance and calls the instance.

Service Governance

But for microservices, calls between modules span processes. If you want to get the target instance, you can’t directly inject it, so you need to register each sub-module, that is, the microservice to Nacos (registration & configuration center) and perform related configurations, and use Feign to implement remote calls between services, and use Gataway to do it. Authorization authentication. In order to ensure the high availability of messages between microservice modules and the speed of service response, the asynchronous communication tool MQ is used. These governance components are integrated by Spring, so SpringCloud is usually used as a service governance solution.

So, stop drawing "=" between SpringCloud and microservices!

Guess you like

Origin blog.csdn.net/weixin_57535055/article/details/128984358