Chapter 1 Introduction to Microservices

Understanding Microservices

With the development of the Internet industry, the requirements for services are becoming higher and higher, and the service architecture has gradually evolved from a monolithic architecture to the now popular microservice architecture . What are the differences between these architectures?

  • Understand the pros and cons of microservices architecture

Monolithic architecture

Monolithic architecture : All business functions are developed in one project and deployed as a package.

image-20230817155321413

The advantages and disadvantages of monolithic architecture are as follows:

advantage:

  • simple structure
  • Low deployment cost

shortcoming:

  • High degree of coupling (difficult to maintain and upgrade)

Distributed architecture

Distributed architecture : The system is split according to business functions. Each business function module is developed as an independent project and is called a service.

image-20230817155806244

Advantages and disadvantages of distributed architecture:

advantage:

  • Reduce service coupling
  • Conducive to service upgrade and expansion

shortcoming:

  • The service calling relationship is complicated

issues to consider

image-20230817160011635
  • How to define the granularity of service splitting?
  • How to maintain the service cluster address?
  • How to call between services?
  • How to perceive the service health status?

Cluster, microservice, distributed

①. Microservices: Reject large single applications, split microservices based on business , and deploy and run each service independently

  • (The subtle difference between microservices and distributed is that the application of microservices is not necessarily scattered on multiple servers, it can also be the same server)

②. Cluster, distributed, node

  • Cluster: Several services are gathered together to implement the same business
    • A cluster can be I am an application. I can’t handle this application any longer. I deploy this application on different machines and provide one service to the outside world.
  • Distributed: Split a system into different subsystems and deploy them on different servers (this is called distributed)
  • Node: A server in the cluster
    • Note: cluster (multiple people doing the same thing together) distributed (multiple people doing different things together)
    • Each node in the distribution can be a cluster, but the cluster is not necessarily distributed.
    • Cluster is a physical form, distribution is the way of working

Example:

  • The small restaurant used to have only one cook, who did everything from cutting, washing, preparing ingredients and cooking.
  • Later, when there were more customers, one chef in the kitchen was too busy, so another chef was hired. Both chefs could cook the same dishes. The relationship between the two chefs was that of a cluster.
  • In order to allow the chef to concentrate on cooking and make the dishes perfect, a side dish chef is hired to be responsible for cutting vegetables, preparing vegetables, and preparing ingredients... The relationship between the chef and the side dish chef is distributed.
  • Even one side dish chef was too busy, so another one was hired. The two chefs had a close relationship.
  • One of the sommeliers took leave for some reason, but the other sommeliers still did what they were supposed to do. It’s just that the tasks of the sommeliers who didn’t ask for leave were evenly increased, but their tasks and responsibilities remained unchanged. This is a cluster.

microservice

Architectural characteristics of microservices:

  • Single responsibility: Microservices are split into smaller granularities. Each service corresponds to a unique business capability and achieves a single responsibility.
  • Autonomy: independent team, independent technology, independent data, independent deployment and delivery
  • Service-oriented: services provide unified and standard interfaces, independent of language and technology
  • Strong isolation: Service calls must be isolated, fault-tolerant, and downgraded to avoid cascading problems.

The above characteristics of microservices are actually setting a standard for distributed architecture, further reducing the coupling between services and providing service independence and flexibility. Achieve high cohesion and low coupling. Therefore, it can be considered that microservices are a distributed architecture solution with good architectural design. ,

The specific architecture of microservices

image-20230817161338056

But how to implement the plan? What technology stack to choose? Internet companies around the world are actively trying their own microservice implementation solutions.

Among them, the most eye-catching one in the Java field is the solution provided by Spring Cloud.

Microservice technology comparison

image-20230817161814420

Technology needs in the business

image-20230817162312072

The version used for learning

image-20230817162608112
  • SpringBoot version is 2.3.4.RELEASE
  • SpringCloud version is Hoxton.SR8
  • spring-cloud-alibaba-dependencies是2.2.2.RELEASE
<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
        <mysql.version>5.1.47</mysql.version>
        <mybatis.version>2.1.1</mybatis.version>
</properties>

Summarize

  • Monolithic architecture: simple and convenient, highly coupled, poor scalability, suitable for small projects. For example: student management system

  • Distributed architecture: loose coupling and good scalability, but the architecture is complex and difficult. Suitable for large-scale Internet projects, such as: JD.com, Taobao

  • Microservices: a good distributed architecture solution

    • ① Advantages: smaller splitting granularity, more independent services, and lower coupling

    • ② Disadvantages: The architecture is very complex, making operation, maintenance, monitoring, and deployment more difficult.

SpringCloud is a one-stop solution for microservice architecture, integrating various excellent microservice functional components

Considerations for Service Splitting

  • Do not develop the same business repeatedly for different microservices
  • Microservice data is independent, do not access the databases of other microservices
  • Microservices can expose their own business as interfaces for other microservices to call
image-20210713210800950

Guess you like

Origin blog.csdn.net/qq_50985215/article/details/132678312