Is it difficult to be a web full-stack engineer? That's it for the most difficult server architecture

I. Introduction

Web development has always been a popular development direction for programmers, especially full-stack engineers are paid very well. Recently, many friends asked me questions about Web development. The most common ones are "Is it difficult to develop?" and "Learning." What language is good for web development to find a job".

As a teacher who has been teaching web development offline for many years, today I will use a relatively easy-to-understand way to tell you the most important thing about web development-the principle of server architecture. You can give your own answers through this introductory explanation. Everything depends on the essence.

The old rules, first talk to you about the technical knowledge points, and then give you the dry goods you have collected, I hope you can help those in need.


Two, the principle and technology of server framework

First of all, let's look at a schematic diagram of the server framework for web development, we start to understand from here:

For the time being, I will not do a detailed analysis of the sections inside. The article will explain in detail later, let's first sort out the principle of the server framework of web development.

From the white arrows in the figure, we can see that the server's response process can be roughly divided into two processes:

Request data process: client→web server→business server→cache server→database

Return data process: database → cache server → business server → web server → client

For example, a student named Wang Ermazi wants to check his English Test Band 4 scores on the computer. At this time, when he logs in to the query page on the computer, he is on the client. When he clicked the query button after inputting personal information on the client, the client started to send Wang Ermazi's data request to the web server. The web server instructed the business server to verify and process the cache server, and the cache server took Wang Ermazi with him. The data will go to the database to retrieve the data.

After the database retrieved Wang Ermazi's data, it immediately told the cache server, and the cache server ran to tell the business server. The business server gave Wang Ermazi's data to the web server, and the web server waved his hand. , The terminal silently presented Wang Ermazi's data. When Wang Ermazi looked at the data, he might curse: "XX, I have to retake the exam again!"

The process is just such a process. Although it seems troublesome to run around, it is not troublesome. The computer can handle tens of millions of Wang Er pock every minute.


Three, explain each section of the server

(1) Client

Currently, the main client types for web development are IOS, Android, PC (computer) and mobile (mobile phone, etc.) four types of clients. I won’t talk about this much. In general, every user’s interface is a client. To present data such as pictures, text, and videos for users to view.

 

(Two) web server

There are two main functions of the web server: load balancing and static resource server.

 

(1) Load balancing

What is load balancing? Let's look at a picture first:

This is the simplest server architecture. It does not have a web server, it only consists of a client, a business server, and a database. In the case of a small amount of data, it can run normally.

If a business server can support 5000 client visits, as long as no more than 5000 devices visit, it is OK, but what if it exceeds 5000 client visits? Then there are only two methods left. One is to refactor the business server to improve its performance by changing the development language, which involves the performance of the development language, we will talk about it later; the second is to increase the number of business servers to ensure a large number of users Normal access, increasing the load capacity, this is also a more commonly used method.

So the question is, increase the number of business servers, but they all "look" the same, the client is very depressed, which server should I visit?

Therefore, a web server is needed to coordinate the allocation, allocate which business server the client should access, and allocate resources reasonably to avoid causing the client to uniformly access a certain business server and causing the load to exceed the core. This is the load balancing function of the web server.

(2) Static resource server

Not all data requests need to access the database. We mentioned earlier that we run from the client to the database step by step to request data and return dynamic data requests, and some data is stored on the web server, and the data can be obtained to the user without accessing the database, which is called a static request. .

For example, some texts, pictures, videos, etc. that do not change frequently on some web pages are basically fixed in a certain place for display, and the developer will not update the one if they do not adjust it. Stay there quietly and display it when they enter the page. After that, the data is stored on the web server without a database, so that it can be displayed to the client more quickly.

 

(3) Business server

The main functions of the business server are: accept data, process (query, write) data, and return data.

(1) Agreement

At present, the server's data transmission and processing mainly follow two protocols: http/https and socket request. The http protocol belongs to the application layer, and the socket is relatively native, which is the so-called TCP/IP layer, which belongs to the network layer. I won't go into details about these two, I will learn in this aspect.

(2) Development language

The development language of the server can be regarded as contending, you can use C, C++, Java, PHP, Python, Ruby and other languages ​​to develop, but there are still differences in terms of performance and cost performance.

At present, Java and PHP are the most popular languages ​​for servers. Why? First, PHP is relatively simple and easy to get started. Second, Java can be developed in large-scale team collaboration, packaged into modules, and the code can be reused.

But there is still such a trend: more and more companies use C/C++ and Python for server development. Why?

Because the development period of many server development is a long time ago, ten or more than ten years ago, at that time, in order to quickly conquer the city, the company first started the business and chose a language with a short development cycle to do the server. The load is limited, but hardware can be used to supplement it. However, as the number of mobile phones and computers increases and the number of clients increases, if hardware is still used to supplement the load performance of the server, it will face many problems.

For example, the electricity bill problem has been encountered by Ali. The machine has to be kept on. As Ali's business volume increases, the electricity bills consumed by the hardware every day are a headache. Burning it day and night will only burn money. , The electricity expenses alone account for 10~30% of the company’s annual expenses, so what should I do? Then you can only start with the development of the server, and choose a higher-performance language to rebuild the server, and the performance will be improved. After some servers are rebuilt, the performance of a single server can be increased by 10 times.

Therefore, the machine language C/C++ has become the first choice for powerful enterprise development servers, so C/C++ will never be outdated.

For small and medium-sized enterprises, it is not recommended to use C/C++ for development servers. Although their performance is high, it is difficult to develop, and there are fewer programmers who really understand C/C++ on the market, so the salary paid is naturally high. Up. You can choose a scripting language to develop and let the business run first. When the bottleneck is reached, I believe that the company also has stable financial support. At this time, it is more appropriate to restructure the server.

I personally prefer to use Python for server development for small and medium-sized enterprises, why not other languages?

First of all, Python is an object-oriented scripting language with a small amount of code, concise syntax, and clear logic. In terms of beautiful code and team development, PHP is not as good as Python; Java is good, but heavier, such as doing one thing. C language requires 100 lines of code, so Java is about 50 lines, while Python only needs 10 lines.

I personally do not recommend using Ruby as a server. One is because Ruby is something made by the Japanese, with patriotism; the other is Ruby is a magic language, what does it mean? That is, you wrote a symbol or written an instruction, and he did a lot of things for you behind his back. You can’t see the bottom of this thing. The logic is not clear. Just write it casually. That is to say, you follow some of its special features. Symbol, it will bring you a lot of things. This kind of magic language is not suitable for team development. For team development, everyone has different levels, some people have mastered more magic grammar, some people do not master it, and it is not suitable for team development.

 

(4) Database and cache server

Friends who have carefully read the article may find that we have talked about the simplest version of the server architecture before. It can run normally without a cache server. Then the problem is that the business server needs data to go directly to the database to find it. Why add a cache server?

This is actually to reduce the load of the database and improve the experience of the client. The cache server is equivalent to a cache area and can cache data.

For example, if the read speed of the database is 4000 times/s, if there are 10,000 data online requests to access the database at this time, but the database is very busy for 1 second, and it is too busy, then the client side has to wait. , It takes more than 2 seconds for the database to give the data that the client wants. What if it is 100,000, 1 million, or 10 million? Wait 20s, 200s, 2000 seconds? Is this kind of user experience bad?

Therefore, a cache server is added, which can cache frequently used information there, and the reading speed is fast (how fast you can go to the Internet to check the speed difference between cache and memory), when the client requests again, there is no need to access the database. Just take the data in the cache server directly.

In terms of data storage, there is a more advanced distributed file storage system, which also solves the shortcomings of traditional databases, such as TDFS adopted by Ali and GDFS of Amazon. This is a relatively high-end technology. If there is a chance You can also find out.

The server architecture principle of web development is finished for everyone. It is not difficult to understand from the principle. If you choose a suitable language for web development, you will get twice the result with half the effort, especially Python for development. Many people have both front and back ends. It can be done, as such a full-stack engineer is very popular in the market.


Dear friends, my network disk data is getting more and more piles, especially for Xiaobai's Python entry. I don’t need it anymore. Now I’m going to share it with you, and take it away if you need it.

 

If necessary, you can add my assistant's WeChat account (pykf20). She has more time. Please note the "receiving information" so that she can know your intentions and give you things as quickly as possible. Please take a closer look at the picture below:

 

 

Guess you like

Origin blog.csdn.net/zhiguigu/article/details/114129995