Microservice SpringCloud Tutorial - What is Microservice

Microservices (MicroServices) was originally a term proposed by Martin Fowler in the paper "MicroServices" published in 2014. Once it was proposed, it became a hot topic in the technical circle.

We can understand microservices literally, that is, "tiny services". Below we will introduce them from two aspects: "service" and "tiny".

1) The so-called "service" actually refers to the functional modules in the project, which can help users solve a certain problem or a group of problems, and appear as one of the IDE (integrated development environment, such as Eclipse or IntelliJ IDEA) in the development process Engineering or Moudle.

2) "Tiny" emphasizes the size of a single service, which is mainly reflected in the following two aspects:

  • Microservices are small in size and low in complexity: a microservice usually only provides a single business function service, that is, a microservice only focuses on doing one thing well, so microservices usually have less code, smaller size, and higher complexity Low.
  • The microservice team needs fewer members: Generally, a microservice team only needs 8 to 10 people (2 to 5 developers) to complete all the work from design, development, testing to operation and maintenance.

microservice architecture

Microservice architecture is a design style of system architecture. Different from the traditional monolithic architecture (ALL IN ONE), the microservice architecture advocates splitting a single application into multiple small services. These small services are all running in their own independent processes, and lightweight services are used between services. Level communication mechanism (usually HTTP RESTFUL API) to communicate.

Usually, these small services are built around a specific business, and each service only focuses on completing one task and doing it well, that is, "professional people do professional things".

Each service can be independently deployed in various environments, such as development environment, test environment, and production environment, and each service can be started or destroyed independently without affecting other services.

The interaction between these services is carried out using standard communication technologies, so different services can use different data storage technologies and even use different programming languages.

Microservice Architecture vs Monolithic Architecture

In today's software development field, there are mainly two system architecture styles, that is, the emerging "microservice architecture" and the traditional "monolithic architecture".

Monolithic architecture is the most classic type of software architecture in the industry before the emergence of microservice architecture, and many early projects also adopted monolithic architecture. The monolithic architecture writes all the business logic in the application in the same project, and finally compiles, packages, and deploys it to run on a server.

In the early stage of the project, the monolithic architecture has obvious advantages in terms of development speed and operation and maintenance difficulty. However, with the continuous improvement of business complexity, many disadvantages of the monolithic architecture have gradually emerged, mainly in the following three aspects:

  • With the increase of business complexity, the code volume of monolithic applications (applications adopting monolithic architecture) is also increasing, resulting in the decline of code readability, maintainability and scalability.
  • With more and more users, the concurrency of the program is getting higher and higher, while the ability of a single application to handle high concurrency is limited.
  • Monolithic applications concentrate all services in the same project, and modifying or adding services may have a certain impact on other services, resulting in increased testing difficulty.

Due to these disadvantages of the monolithic architecture, many companies and organizations have begun to transform their projects from the monolithic architecture to the microservice architecture.

Let's compare the difference between the microservice architecture and the monolithic architecture.

difference microservice architecture monolithic architecture
team size The microservice architecture can split a single application in the traditional mode into multiple independent services, and each microservice can be developed, deployed and maintained independently. The team size required for each service from design, development to maintenance is small, and the team management cost is small. Applications with a monolithic architecture usually require a large team to work around a huge application, and the cost of team management is high.
data storage method Different microservices can use different data storage methods, for example, some use Redis and some use MySQL. All modules of a single architecture share the same public database, and the storage method is relatively single.
Deployment method Each service in a microservice architecture can be deployed independently and scaled independently of other services. When deployed properly, a microservices-based architecture can help businesses to deploy applications more efficiently. Every feature change or bug fix to a monolithic application requires a redeployment of the entire application.
development mode In an application program using the microservice architecture, different modules can be developed using different technologies or languages, and the development model is more flexible. In a monolithic application, all modules must use the same technology and language, and the development model is limited.
fault isolation In the microservice architecture, faults are isolated in a single service, avoiding the overall collapse of the system. In a monolithic architecture, when a component fails, the failure is likely to propagate through the process, making the system globally unavailable.
project structure The microservice architecture splits a single application into multiple independent small services, each of which can be independently developed, deployed, and maintained, and each of which can fulfill a specific business requirement. For single-architecture applications, all business logic is concentrated in the same project.

Characteristics of Microservices

Microservices have the following characteristics:

  • Services are divided according to business. Each service usually only focuses on a specific business, requires a small amount of code, is low in complexity, and is easy to maintain.
  • Each microservice can be independently developed, deployed, and run with less code, so it starts and runs faster.
  • The team required for each service from design, development, testing to maintenance is small, generally 8 to 10 people, and the team management cost is small.
  • As long as there is any modification to the application with a monolithic architecture, the entire application needs to be redeployed to take effect, and microservices perfectly solve this problem. In the microservice architecture, after a microservice is modified, only the service needs to be redeployed instead of the entire application.
  • In the microservice architecture, developers can reasonably choose languages ​​and tools for development and deployment based on the characteristics of the project business and the team. Different microservices can use different languages ​​and tools.
  • Microservices have good scalability. As the business continues to increase, the volume and code volume of microservices will expand dramatically. At this time, we can split the microservices again according to the business; in addition, when the number of users and concurrency increase, we can also Deploy microservices in clusters to increase the load capacity of the system.
  • Microservices can be used in conjunction with containers (Docker) to achieve rapid iteration, rapid construction, and rapid deployment.
  • Microservices have good fault isolation capabilities. When a microservice in the application fails, the fault will be isolated in the current service without affecting other microservices and causing the entire system to fail.
  • The microservice system has the ability to track links.

Microservice Framework

Microservice architecture is a system architecture style and idea. If you want to truly build a microservice system, you need the support of a microservice framework. With the popularity of microservices, many programming languages ​​have launched their microservice frameworks one after another. Let's briefly list them below.

Java microservices framework

There are mainly five types of Java microservice frameworks on the market:

  • Spring Cloud: It can build services based on REST services and help architects build a complete microservice technology ecological chain.
  • Dropwizard: For developing high-performance and Restful Web services, it provides out-of-the-box support for configuration, application metrics, logging, and operational tools.
  • Restlet: This framework follows the RST architectural style and helps Java developers build microservices.
  • Spark: One of the best Java microservice frameworks that supports the creation of microservice architecture applications through Java 8 and Kotlin.
  • Dubbo: A distributed service governance framework open sourced by Alibaba.

Go language microservice box

There are fewer microservice frameworks in the Go language, and GoMicro is used more. It is an RPC framework with functions such as load balancing, service discovery, synchronous communication, asynchronous communication, and message encoding.

Phyton microservice framework

The microservice frameworks in Phyton mainly include Flask, Falcon, Bottle, Nameko, and CherryPy. 

NodeJS microservice framework

Molecular is an event-driven architecture built with NodeJS. The framework has built-in components such as service registry, dynamic service discovery, load balancing, fault tolerance, and built-in caching. 

SpringCloud+RabbitMQ+Docker+Redis+Search+Distributed, system detailed springcloud microservice technology stack course

Guess you like

Origin blog.csdn.net/Itmastergo/article/details/131931839