Some summaries and experience talks about microservices, let’s see if you understand them all

Talk about the understanding of microservices

1. What microservices?

  • Microservice is a software development technology - a variant of the Service-Oriented Architecture (SOA) architectural style, which advocates dividing a single application into a set of small services, and the services coordinate and cooperate with each other to provide users with final value.

  • Each service runs in its own independent process, and services communicate with each other using a lightweight communication mechanism (usually an HTTP-based RESTful API).

  • Each service is built around a specific business and can be independently deployed to production environments, production-like environments, etc.

  • A unified and centralized service management mechanism should be avoided as far as possible. For a specific service, an appropriate language and tool should be selected to build it according to the context.

2. Microservice system

  1. service description
  • Documentation for similar services, simple but indispensable. For example, the first problem to be solved in service invocation is how to describe the service to the outside world. You provide a service to the outside world, so what is the service name of this service? What information do I need to provide to call this service? What is the format of the result returned by calling this service? These are the questions that service descriptions address.
  1. registration center
  • The next problem to be solved is the publication and subscription of services, that is, you provide a service (Provider), how to let the outside (Consumer) know about it to those who want to call your service. At this time, a role similar to the registry is needed . The service provider registers the services and addresses it provides to the registry, and the service consumer queries the address of the service to be called from the registry, and then initiates a request.
  1. service framework
  • Through the registration center, the service consumer can obtain the address of the service provider, and can initiate a call after having the address. But you still need to solve the following problems before initiating the call. What protocol does the service communicate with? Is it RESTful API or gRPC? What format is used for data transmission and what format is used for data compression? These are usually integrated into our service framework.
  1. service monitoring
  • Once the service call can be initiated normally between the service consumer and the service provider, you need to monitor the call to know whether the service is normal. Generally speaking, service monitoring mainly includes three processes, indicator collection, data processing, and data display. Monitoring is to find problems and exceptions. If you want to further track and locate problems, you need to further understand service tracking.
  1. Service Tracking
  • In addition to monitoring service calls, you also need to record each layer of links that service calls pass through, so as to track down and locate faults, and finally achieve the goal of getting closer to the problem. Service monitoring and tracing can be combined, but the respective responsibilities are different.
  1. Service Governance
  • Service monitoring can find problems, service tracking can locate problems, and solving problems depends on service governance. Service governance is to use a series of means to ensure that service calls can still be carried out normally under various unexpected circumstances.

3. Advantages of Microservices

  1. Ease of development and maintenance

  2. start faster

  3. Local modification is easy to deploy

  4. Technology stack is not limited

  5. Scale on demand

4. Disadvantages of Microservices

  1. High operation and maintenance requirements

  2. distributed complexity

  3. Interface adjustment costs are high

  4. repetitive work

5. What is gRPC?

  • It is Google's open source RPC framework.
  1. What problem is the technology designed to solve?

    • It solves the problems of simplicity, generality, efficiency and security of multilingual data transmission.
  2. Its calling process?

    • Take the client calling the add function of the server as an example.

    • Client: gRPC Server

    • Server: gRPC Stub

    • The interaction process is that the client sends a request to the server, the server processes the request and sends the result back to the client.

  3. Processing request process:

    • The client serializes the requested parameters. The serialization is encoded through the ProtoBuf protocol [protobuf]. After encoding, the request is sent to the server. The request crosses the network and is based on the HTTP2.0 protocol.

    • At this time, the server receives the request. The server also decodes and deserializes through the ProtoBuf protocol. It finds that there is an add function locally, serializes the result, encodes it with the ProtoBuf protocol, and sends it to the client through the network. The client passes the ProtoBuf protocol. Deserialize and use the result of the response in the client's program code.

    • After analyzing the process, gRPC will not sing a one-man show alone, it must be combined with the ProtoBuf protocol to be effective.

6. What are the benefits of the ProtoBuf protocol?

  • Cross-platform - easy to transfer data

  • Cross-language——easy to parse data and parse it into the grammatical structure of your own language

  • Smaller and faster than json, xml

7. What is the connection between gPRC and ProtoBuf?

To achieve cross-platform + cross-language + serialization and deserialization for gRPC, the ProtoBuf protocol must be used to achieve it.

2 Combing the learning process of this microservice project

  1. Starting from the introduction of microservices, explain the principle of the transport communication layer grpc of go-micro. And the principle of grpc data transmission serialization and deserialization protobuf

  2. Take the user module with the simplest business as an example, connect gorm and other knowledge in series, and understand how to develop and package the module.

  3. Introduce the basic principles of the Consul component in go-micro to implement the registration center and configuration center. Use Docker to quickly install Consul, introduce the experience in actual work, and connect it to the project.

  4. Introduce the principle and function of the Jaeger component in go-micro. Integrate the link tracking function for the project and complete the link observatory

  5. Fusing, current limiting, and load balancing are the three swordsmen for microservice stability. Introduce the principle and function of hystrix-go components, and introduce the basic use of the code package uber/ratelimit for current limiting problems

  6. Microservice Goification is generally because of performance, so performance monitoring is very important. Use Docker to quickly complete the installation of promethues+grafana, and connect to the project to complete the performance monitoring platform

  7. Use the zap tool to record logs and collect them in the log center ELK. Then unify the configuration, integrate the previous link tracking, load balancing, monitoring logs, etc., to complete the service-level observation platform

General development process of three microservice projects

  1. Pull micro image docker pull micro/micro

  2. Generate module project file docker run -rm -v root directory: root directory -w

  3. .proto file writing interface

  4. Generate micro.go file

  5. Complete the model file and write the data table struct mapping body

  6. Write the reponsitory file and use gorm to operate the database

  7. Complete the implementation of the interface in the service

  8. Expose the interface for protoc, implement the interface (request parameter assignment)

  9. Access various microservice plug-ins, such as configuration, registration center, link tracking, current limiting, ELK, etc.

  10. Complete the development of main.go and complete the deployment of the microservice project

4. What have you learned from this microservice project?

  • Go microservice architecture technology stack and services applied at each level

image.png

  • In this microservice project development, you can learn to master the following technologies:
  1. Use of the Go language

  2. Use of Docker and Docker-compose

  3. The use, writing, and commands of Proto

  4. Microservice development process:

    • 4.1 Create a project (Docker or go-micro)
    • 4.2 Write proto file and generate .go file
    • 4.3 In terms of writing domain database, including (model layer, repository layer, service layer), etc.
    • 4.4 Write the Handle layer and implement the interface defined by proto
    • 4.5 Write the common layer, configuration, mysql, public functions, jaeger (link tracking), etc.
    • 4.6 Write the main function to complete the project closed loop
  5. go-micro directory generation, use, introduction, installation

  6. Understanding of microservice components (registration center and configuration center (Consul), link tracking (jaeger), current limiting (server), load balancing 7

  7. (client), ELk, etc.)

  8. gorm database development

  9. Prometheus monitoring service

  10. Introduction to ELK

  11. kibana log visualization

  12. filebeat log upload

  13. Logstash collects logs

  14. elasticsearch log search

  15. zap log package

5 Some experience talks about microservices

  • The current application trend of Go language Why is Go language suitable for microservices?

    • 1. Go has high concurrency and other features, which are more suitable for large-scale systems.

    • 2. Go compiles quickly, has no dependent environment, and is more suitable for containerization

    • 3. Go will become the infrastructure programming language in the era of cloud computing, especially suitable for microservices
      image.png

  • For real microservice projects, service development is only the first step, and containerization, elastic scaling, and observability are the real keys.

  • Microservice technology system

image.png

  • Microservice Containerization

image.png

Six how to learn microservices

1. How does microservice go from 0 to 1

  1. Getting Started with Docker

    • Master its application in microservice development
  2. Mastering Microservices Essentials

    • Registration Center and Configuration Center
  3. Mastering Microservice Observations

    • Link tracking system access
  4. Master microservices and ensure stability

    • Fuse, current limiting, load balancing
  5. Master Microservices Maintenance

    • Performance monitoring and log system access
  6. Master Microservices Deployment

    • Docker and K8s deploy microservice projects

2. Start with functional features

  • Inter-service communication , including service governance, load balancing, and inter-service invocation;

  • Service fault tolerance and exception troubleshooting , including traffic shaping, downgrade fuse, call chain tracking;

  • Distributed capacity building , including microservice gateways, distributed transactions, message drivers, and distributed configuration centers.

  1. From the functional dimension of microservice components, inter-service communication is the most basic functional feature. This functional module is the most suitable entry point for beginners to learn microservice technology.

  2. After we have built the basic communication capabilities, the next step is to consider how to build service fault tolerance and improve the stability of service calls.

  3. After that, we can build some distributed support features from a global perspective.

  4. In this way, there is a learning curve with a gradual increase in difficulty, and it will not go from getting started to giving up.

7 What should I do if I encounter the following problems?

1. There are too many things to learn and not enough time to worry about what to do

topic description

  • Often those who learn technology will break through a basic stage and embark on a higher stage of development. When your horizons are opened, you will find that you have a lot of new knowledge waiting to take time to learn, and often this period of time will cause anxiety , what should I do at this time?

Tip : Combine your own experience and share your own mental journey. You can write your answer in the comment area and communicate with bloggers and friends.

suggestion:

  • First of all, being able to have such an idea shows that you are a self-motivated person. This is very important in your later career development. Anxiety is common to us. Everyone is the same, others are probably more anxious than you. Here are some notes for myself:
  1. When dealing with emotional problems, what I have learned over the years is that when you find a problem, you should not rush to draw conclusions, but calmly analyze why it happened, and first calm down your mentality and tone.

  2. Everyone's starting point for anxiety may be different, but the same thing is that excessive anxiety will backfire, consume our normal attention, and affect the original normal state. So don't be overly anxious, it's unnecessary, and it doesn't work (think for yourself).

  3. Turn anxiety into the driving force for your growth, and use it well. Appropriate anxiety can help you grow continuously. When you have no goals, it will be more terrifying than excessive anxiety. People are often eliminated during development.

2. Developing a plan is always in the foreseeable future, it is always blocked by some non-technical reasons

topic description

  • You often advocate an activity, a topic, and a direction that only you are doing at a very high level, and no one else cares. What should I do?

Tip : Combine your own experience and share your own mental journey. You can write your answer in the comment area and communicate with bloggers and friends.

suggestion:

  • Faced with this problem, one question that everyone should consider is whether your activities, topics, etc. are in the consensus of everyone. If there is no consensus, there is no common language. If you want to achieve the effect that everyone understands, so that you can carry out work in the future, but you can’t advance it, then you can play your boss’s role well and let him help you promote and implement it. Reach a consensus that this matter is right and needs to be done, and the matter will be successful, and then it will be handed over to the team. The power of the organization far exceeds that of the individual, and the final result may exceed your expectations.

3. How to deal with the pressure of deadlines and affiliations

topic description

  • This problem has always been faced by most people. The development performance of the company and the business indicators of the leader will take up your normal life, and even you will be in a state of tension all the time when you are at home after get off work and on vacation.

​Tips : Combine your own experience and share your own mental journey. You can write your answer in the comment area and communicate with bloggers and friends.

suggestion:

  • The pressure brought by the deadline is more serious than the pressure given by the leader. Sometimes, because things have to be completed ahead of schedule, they stay up all night for several days. Being in a state of high pressure for a long time leads to frequent insomnia and poor health.
  1. Later, I realized this problem and actively participated in the production of this construction period, so that even if I don’t have a mentality, I have expectations for what to do. When it’s critical, I can still express my thoughts, point out the resources I need, and gradually ease the situation. current status.

  2. After returning home, try to do only what you like, such as watching movies, TV, playing chess, etc. In practice, it is found that the sense of relaxation brought by changing the head is conducive to creative work.

  3. Mountains can’t be moved in a day, and meals can’t be eaten in a day. Don’t draw conclusions prematurely, start hastily, and think about what you lack, what you want, and what you have achieved. Separate life and work as much as possible.

eight last

  • So far, the go-micro microservice project has been officially completed.

  • Friends who are interested in microservices and Go can chat with bloggers, share learning experience, and grow together

  • I hope everyone pays attention to bloggers and columns, every blog is full of dry goods.

Guess you like

Origin blog.csdn.net/weixin_53795646/article/details/128785632