当前位置:网站首页>Second understanding microservice

Second understanding microservice

2022-06-21 22:24:00 Digital China cloud base

Cloud primordial is the present IT Technical hotspots in the field , Different organizations have different opinions on its definition , However, in these different definitions, microservices are indispensable .

Cloud primordial with different opinions

so , To understand cloud nativity, you must understand microservices . What is a micro service , Now let's find out .

Computer history

Talking about microservices , Let's take the time machine first , Back in the days when there were no so-called micro services at all , Back in the days when computers were big enough to fill a room . Scientists who operate computers need to go to a huge machine , Give instructions to the computer , The computer then accepts the instructions , Execution instruction .

The first electronic computer in the world

Fast forward to the era of desktop computers , The program still runs on the desktop , The application contains all the instructions it needs to execute . People write applications , Then the code is compiled , The compiled files will be installed on the computer at one time , And it will always be on the same computer .

The desktop era

You can see , This history has greatly influenced the way applications are developed .

Traditional application development

In traditional application development , Writing an application requires starting a new code project , Then write a series of code in the project to realize various functions , Then build it as a whole , Deployed on the user's machine .

Traditional application development : code 、 structure 、 Deploy

The more functions the application needs , You need to write and add more code . So the amount of code in the project will gradually increase over time . Initially, a small code base may be used over time , Become a large and complex code base . A lot of code is stacked together , Finally, it becomes a mess of code base , Managing code has become a headache .

Unmanageable code base

Modular application development

Then people realized , There are better ways to handle large projects . Developers break a huge project into small modules , Instead of putting everything together , Become a mess of code bases . Create smaller modules , These modules are then combined to produce an application . These modules are independent of each other , Focus on some functions . Besides , These modules are reusable , So you can simply add a module to another project to help another application .

Modular code structure

Just like traditional application development , The developer writes the code , Then build the code as a whole , Deploy it all on the user's machine .

Modular application development

One thing to note here is that , When writing an application , The code structure is modular , It is an independent function module , Together, these modules make up the application . Although the code structure is modular , But what you end up doing is still combining them into one application . When you build and run it , All the modules are mixed into a huge and inseparable program , Then it is deployed on the machine . No matter how modular developers are and how they combine their source code , The last executable has only one , All the modules are mixed together .

Most of the time , Developers are happy to develop and deploy applications in this way . But then two things happened , This situation has been completely changed , Changes the way we build applications .

Web The emergence of applications

First of all Web The emergence of applications , People are starting to move from desktop applications that need to be deployed on user machines to Web Applications , these Web The application is installed on a remote server somewhere on the network .

Web Applications come out

stay Web In the application , The user accesses the remote server through the browser , The server starts with HTML Return the results required by the user in the form of a file . The application is not actually deployed on the user's machine , It is deployed somewhere on the server , The user only uses the browser , The user's request is forwarded to the server , Then the server returns a response .

Web How the application runs

Web How did the emergence of applications change the situation ?

At first it didn't make any waves , The only change is the way the program is deployed . Developers no longer install applications on every user machine , Instead, install it on a server , All users access the server through a browser . Besides , In such a deployment mode , The code is still a clear and organized modular organization , But in the end, these modules are mixed together to form an application . But it was originally mixed on the user's machine , Now it is mixed on a server .

To really turn the tide , It has to be combined with another level of reasons , namely Web The explosion of application complexity .

Web The explosion of application complexity

Another shift has taken place in applications over the years ,Web Applications become extraordinarily complex over time . The original Web The application only has very simple functions , But over time ,Web Applications are starting to get better 、 Bigger 、 faster 、 More complicated . For example, some search engines can make us in a few milliseconds , Find what we want from the whole Internet .

Web Applications are growing rapidly

However, behind these great feats is extremely complex code , This complexity is not just reflected in the code itself , It is also reflected in construction and deployment . The complexity that has become increasingly difficult to maintain has led to a series of troublesome problems . In short ,Web The emergence of applications , And its increasing complexity , Making it no longer possible to deploy a single application .

Monomer architecture no longer works

This way of deploying a single application is called a monolithic architecture . In this new situation , Monomer architecture is not feasible because of its exposed shortcomings . What are the shortcomings of the single architecture ?

Disadvantages of monomer Architecture

  1. It's hard to deploy

The first drawback is in deployment . The larger the program deployed , More challenging to deploy . Every time you deploy a program , Because mistakes can be introduced anywhere , Developers have to test the entire program .

2. Expandability of

The second drawback is its scalability . Take a large online e-commerce website as an example , It has very unpredictable traffic peaks , During the promotion, a large amount of traffic flows to the website , After the promotion, the traffic slowed down . There are peaks and valleys in the flow . In response to this change in flow , Now there are elastic servers , When traffic surges , The number of application server instances will increase , When the flow returns to normal , Additional servers will be retired .

Now there is an e-commerce website deployed as a whole , This whole has the function of shopping 、 Return function and a series of other functions . Suppose the website shopping module has a traffic peak , The number of servers increases . The key point here is , In addition to the shopping module , Other function modules will also be expanded , Although no one uses them , But they must be scaled up , Because they exist as a whole when deployed . therefore , A large-scale e-commerce website is at the peak of traffic , More money must be spent to create these duplicate unnecessary modules , The modules that really need to be expanded only account for a small part of them .

In addition, there are a series of other disadvantages of the single architecture . In this situation , People think of a better way to deploy .

A better way to deploy

When deploying applications to user machines , We have to deploy the entire application to the machine , We have no other choice . But for the Web For applications , There can be other deployment methods , The application is actually deployed on the server . Users don't care where the application is 、 Deployment and implementation , They just need a portal to talk to the application . In this case , The new deployment method is , We don't mix the whole application into a whole and deploy it on one machine , Instead, the application is split into smaller Mini applications , Then deploy these mini applications on different machines , Then let them communicate with each other through the network 、 Coordinative operation , Eventually work as an application .

Take e-commerce applications for example , Developers can create a shopping directory application that only has the shopping directory function , And deploy it on a separate server , The order application is deployed on another server , The profile application is also deployed on other applications . Suppose the user wants to view the shopping catalog , The view application calls the catalog Application , Then the view application returns the results . Just like this. , Many applications call and communicate with each other through the network , To get whatever they want from each other .

The first benefit of this is to reduce the risk of deployment . When making changes to the mini application , Because it is a separate application , Just test the application separately , Instead of testing the rest of the application . The second benefit is the flexible extension . At the peak of traffic , Just extend the shopping catalog application , Deploy applications that require more replicas on more servers . And these mini 、 Applications that work independently and cooperatively with each other are called microservices .

Microservice architecture

Microservice is a new application architecture , It decomposes applications into applications that can run independently on different hardware or servers , These independent applications communicate with each other and work together , Finally get the application that users need . In the framework of microservices , In addition to being able to realize the independence of each module in code writing , When the program is deployed, it can also realize the mutual independence of each functional module . No need to build and deploy an application , Instead, there will be several applications , Each application implements some small functions independently , Work together at runtime , So as to form a complete practical application .

Advantages of microservices

  1. Flexible deployment : The advantage of microservices lies in the flexibility of deployment , Different teams can create and apply microservices independently , They can put them on different servers .

2.  Flexible technology : Microservices can even be built in different languages or platforms . Because microservices communicate with each other , So the language actually used doesn't matter , Developers do not need to use a unified language and platform .

3.  Expand flexibility : Microservices can also be extended independently , During peak shopping traffic , They can also be extended separately , Just extend the most commonly used microservices , Other micro services will not be affected .

The problems brought about by microservices

Microservice architecture brings a lot of problems as well as great benefits .

  1. Division problem : It used to deal with an application , Now it has to deal with dozens or hundreds of mini applications in the form of microservices . When separating applications into microservices , How to separate them , Is a key issue . When we don't want to change a feature , Ten different microservices need to be modified , So we need to consider how to separate the program well .

2.  Communication problems : Another problem is , How to ensure that microservices can discover each other , Mutual invocation .

Whether it is single architecture or micro service architecture , They are neither good nor bad , Only fit not fit . These different architectures have their own advantages , The key to the problem is to select the appropriate architecture for specific problems . No matter how popular the microservice architecture is , This does not mean that the microservice architecture is suitable for all application development , There are many applications that are more suitable for building with a single frame . In the age of cloud primordial , Due to the maturity of container and other technologies , Microservice architecture has been widely used in software development , Play a huge role .

原网站

版权声明
本文为[Digital China cloud base]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206212021299414.html