How to choose an application architecture?
Recently, the microservice architecture is very popular. A small company with 10 people is also required to make the microservice architecture a hard condition for a project. Web applications with daily visits of less than 1000 also require the microservice architecture. So, let me talk about it in a popular way. To understand this problem, we need to understand the following catchwords.
Cluster: in order to build a house, you need to build bricks. It’s too slow for one person to build bricks. You need 10 bricklayer colleagues to build bricks. This greatly improves efficiency. We say that these 10 people form a cluster. Cluster means that all people do the same thing, everyone does it together, and everyone is independent of each other. In our software production environment, cluster is to improve efficiency by stacking server hardware to do the same work.
Distributed, as the name suggests, is a concept of division of labor. Let’s take bricklaying as an example. When we build bricks, we need to move the bricks to the wall first. We need cement mortar, and then we can start bricklaying. If it’s done by the same person as cement mortar, brick moving and wall building, even if it’s 10 people, the efficiency may not be high, so it’s time for distribution. We can arrange 2 people to work with cement mortar, 2 people to move bricks under the wall and 6 people to build bricks. In this case, although the number of personnel has not increased, the efficiency will certainly be improved. It can be understood that a cluster is not necessarily distributed, but distributed is definitely a cluster. It requires multiple servers to work together. At this time, there will be another problem. If there is no cement mortar, the bricklayer needs to inform the bricklayer and suspend the cement mortar, and quickly transport the finished cement mortar to the wall. In reality, you can shout with your mouth, call with your mobile phone, and how the server notifies you at this time. This involves RPC (remote process communication),Let’s talk about this briefly. We can discuss it in depth next time.
Microservice is a kind of architecture. Its principle is very similar to that of distribution. Its granularity of splitting is so fine that everyone only does one indecomposable thing, and not all these subtle things are placed on different servers. One server can put many microservices, such as a service, B service, C service, and another server can put B service, C service, and D service. It is worth noting that all services need to be notified to a place called the registration center. It can be understood that this is the project manager, who is responsible for unified coordination and management.
If your business is simple, you have few visits, then all applications can run smoothly even if they put one server. At this time, even the cluster is not needed.
If your traffic is small, but your business is complexFor example, take e-commerce as an example. In the process of placing an order, you need to submit the order and pay. Colleagues need to check whether the warehouse has inventory, and then send the address to the third party logistics to place an order. If these things are done together, it takes 30 seconds. Users need to wait 30 seconds to see whether they have successfully purchased. This experience is very bad. Even if your platform only has 100 transactions a day, and the number of visits is very small, the user experience is still not good. At this time, you can use distributed to solve this problem, split payment, inventory checking, notification of third-party logistics into five or more tasks. In this way, the user experience is greatly improved, and a shopping can be completed in a few seconds.
If you have a large number of visits, each process step is very complexAt this time, you can distribute the steps and allocate more server clusters. At this time, the microservice architecture is more suitable. According to the previous experience of operating apps, the daily visits are several million, and each interaction is an application within 2 seconds. As long as the bandwidth is sufficient, the separation of web and database and a redis cache are added, two mainstream servers are enough.
Creation is not easy, welcome to discuss, thank you for your support!