Service Registration and Discovery Principles of Microservices

1 Introduction

In traditional development, since the address of the service is relatively static, we only need to find the developer of the corresponding service, and then learn the address of the corresponding service interface.

In the development process of the microservice architecture, if we need to call a RESTFul-style API interface, we need to know where the corresponding service is on the network, that is to say, we need to know the IP and port number of the server. In the microservice architecture or distributed environment, this problem is difficult to solve, so service registration and discovery technology is indispensable, which is also one of the core technologies that programmers must master on the way to advancement.

2. Architecture Evolution

Let's look at a question first. If we are going to do a mall project now, as an architect, how should we design the system architecture? You must be thinking in your heart: It’s not easy to just copy Taobao’s structure directly. But in a real entrepreneurial environment, a project may be close to death. If you invest a lot of manpower and financial resources at the beginning, once the project fails, you will lose a lot.

As an experienced architect, you need to combine the company's financial resources and human investment budget to choose the most suitable architecture is the kingly way. Large sites grow from small sites, and so does the architecture.

The architecture of any large website is not constant from the beginning, but is the result of continuous iterative evolution as the number of users and the amount of data continue to increase.

In the process of iterative evolution of the architecture, we will encounter many problems. The essence of technological development is to constantly discover problems and then solve them. After solving problems, we will discover problems.

2.1 Monolithic Architecture

At the beginning of the system establishment, there may not be a lot of users. All the business is packaged into an application package and run in the tomcat container, sharing a server with the database. This architecture is generally called a monolithic architecture.

In the early stage, the efficiency of this architecture is very high, and it can be quickly iteratively launched based on user feedback. But as the number of users increases, the memory and CPU of a service are tight, which can easily cause bottlenecks. How to solve new problems?

2.2 Application and Data Separation

As the amount of user requests increases, the memory and CPU of a server continue to soar, and the response time to user requests slows down. At this time, you can consider separating the application and the database and use a server for each.

Suddenly one day the sweeping aunt accidentally touched the wires, one of the servers lost power, and all requests from users reported errors, followed by a series of complaint calls.

2.3 Cluster deployment

A single instance can easily cause single-point problems, such as server failures or service capacity bottlenecks, what should I do? Smart, you must have thought of it, use clusters.

Cluster deployment refers to deploying applications on multiple servers or virtual machines. Users randomly access one of the instances through service balancing, so that the traffic of multiple instances is balanced. If an instance fails, it can be taken offline, and other instances are not affected. Impact can still provide services externally.

With the rapid increase in the number of users, the boss decided to increase investment to expand the team size. The efficiency of the development team has not been significantly improved after the development team has grown. In the past, a small team could iteratively go online once a week, but now it takes at least two to three weeks.

Business logic is becoming more and more complex, and the coupling between codes is very serious. Modifying a line of code may introduce several online problems. Architects recognize the need for architectural refactoring.

2.4 Microservice Architecture

When the monolithic architecture evolves to a certain stage, the complexity of development and testing will increase in cost, and the expansion of the team size will also make the coupling of their work more serious.

When the monolithic architecture encountered a bottleneck, the microservice architecture was born. Microservices are the former

Guess you like

Origin blog.csdn.net/my8688/article/details/131831600