1. What are microservices?

Micro-service is a hot technology in recent years. Since 2017, it has gradually exploded. Gradually, large and small companies have introduced micro-service technology and landed in the actual business.

The concept of microservice was first put forward by Martin Fowler and James Lewis in 2014: Microservice is a small service composed of a single application, which has its own process and lightweight processing. The service is designed according to business functions, deployed in an automatic way, and communicates with other services using HTTP API. At the same time, services will use the minimum scale of centralized management (such as Docker) technology, services can be in different programming languages and databases, etc.

1.1. The pain of monomer application

Why microservices? Are microservices really that good?

Before we get to that, we need to understand the drawbacks of monolithic architectures.

Taking the MVC architecture as an example, services are usually provided by deploying a WAR package into Tomcat and starting Tomcat to listen on a port. In the early stage, when the business scale was small and the development team was small, the single application architecture was adopted, and the development, operation and maintenance costs of the team were controllable.

However, as the business grows and team developers expand, the monolithic application architecture starts to break down. There are basically the following aspects:

  • Inefficient deployment
  • Team development is expensive
  • The system high availability is poor
  • Online publishing is slow

1.2 service Orientation (SOA)

Service orientation is to transform the local method calls generated through JAR dependencies in traditional stand-alone applications into remote method calls generated through RPC interfaces.

1.3. Microservices

Microservices can be understood as a further development of service orientation.

On the basis of SOA, microservices have the following major developments:

  • Service separation is more granular. Microservices can be said to be the servitization of finer dimensions, as small as a sub-module, as long as the module depends on resources unrelated to other modules, then it can be split into a microservice.
  • The service is deployed independently. Each microservice strictly follows the principle of independent packaging and deployment, and does not affect each other. For example, a physical machine can deploy multiple Docker instances, and each Docker instance can deploy a microservice code.
  • The service is independently maintained. Each microservice can be developed, tested, released, and operated by a small team or even an individual, and is responsible for its entire life cycle.
  • Service governance capability is highly required. After being split into micro-services, the number of services increases, so a unified service governance platform is required to manage each service.

To sum up, microservice architecture is a fine-grained service separation of complex and bloated individual applications. Each service separation is independently packaged and deployed and delivered to a small team for development, operation and maintenance, which greatly improves the efficiency of application delivery and is widely adopted by major Internet companies.

Here is a schematic diagram of the architecture evolution:

2. How to split microservices

2.1 Two ways to split microservices

How does microservice unbundling work?

One of the most effective means is to service different functional modules, independent deployment and operation. Take social App as an example, it can be considered that the homepage information flow is a service, the comment is a service, the message notification is a service, and the personal homepage is also a service.

This service separation method is vertical separation, which is split from the service dimension. The standard is determined by the degree of association of services. Businesses with close association are suitable for splitting into a microservice, while businesses with relatively independent functions are suitable for splitting into a microservice.

Another servitization split is the horizontal split, which is split from the common and independent functional dimensions. The criteria is based on whether there is a common resource that is called by multiple other services, and the dependent resource is independent and not coupled to other businesses.

For example, social apps need to display the user’s nickname whether it is the homepage news stream, comments, message box or personal home page. If the user’s nickname function changes in product requirements, you need to launch almost all of the services, and the cost is a little high. Obviously, if I deploy the user’s nickname function as a separate service, then I only need to live with this service if any changes are made. Other services are not affected, and development and live costs are greatly reduced.

2.2. Problems to be solved for microservice separation

It is important to recognize that microservice architectures also have costs, and as architecture complexity increases, there are new issues that microservice architectures must address:

  • How services are defined. For individual applications, when different functional modules interact with each other, they usually provide the functions of each module in the way of class libraries. As for microservices, each service runs in its own process, what form should it communicate its information to the outside world? The answer is interface. No matter which communication protocol is used, HTTP or RPC, the invocation between services is agreed by interface description, which includes interface name, interface parameters and interface return value.
  • How services are published and subscribed. Since single applications are deployed in the same WAR package, the calls between interfaces are intra-process calls. After the independent deployment of microservices, how should the service provider expose its address to the outside world, and how should the service caller query the address of the service to be called? This is where you need a registrie-like place that records the address of each service provider for service callers to look up, and in the case of microservices, this is the registry.
  • How services are monitored. Typically for a service, we care most about metrics such as QPS (call volume), AvgTime (average time taken), and P999 (how many milliseconds does 99.9% of requests perform in). This is where you need a common monitoring solution that covers business burial points, data collection, data processing, and finally full link capabilities for data presentation.
  • How services are governed. As you can imagine, the number of services and the dependencies become more complex when you split into microservices architecture. For example, when a service has performance problems, dependent services are bound to be affected. A call performance threshold can be set, and if it is consistently exceeded for a period of time, service-dependent calls can return directly. This is known as a circuit breaker, and is one of the most common approaches to service governance.
  • How to locate faults? During monomer applications into the service, after a user calls may depend on multiple services, each service and deployed on different nodes, if the user calls appear problem, you need to have a solution to a user request, and continue to deliver in the multiple dependent service system, so that all paths in series, and fault location.

3. Selection of micro-service technology

For most companies, the cost of doing their own research to solve some of the problems of microservices architecture is prohibitive. Fortunately, however, there are a number of open source solutions available in the industry.

A few years ago, ali’s Dubbo is more popular, and then stopped maintenance, the last two years and revived, new vitality.

Later, Spring Cloud, a micro service solution under the Spring system, emerged and became popular quickly.

Spring Cloud is not a new framework per se, but an organic combination of frameworks that cleverly simplify the development of distributed system infrastructures by leveraging the development convenience of Spring Boot. Not all components are provided by Spring, and Netflix plays an important role.

The registry Eureka, fuse Hystrix, load balancing Ribbon, gateway Zuul and other important components are provided by Netflix.

4. Why use SpringCloud Alibaba

The SpringCloud ecosystem is already so complete. What is SpringClou Alibaba? Why use SpringCloud Alibaba?

From Aliyun:

Spring Cloud itself is a set of microservice specifications, not a ready-made framework, and the open source of Spring Cloud Alibaba provides developers with a way to implement this specification. At the same time, the complete micro-service components, Chinese documents and localized open source services provided by Spring Cloud Alibaba improve the speed at which developers can access micro-services and reduce the subsequent operation and maintenance difficulties.

To put it simply, Spring Cloud Alibaba is the implementation of a set of Sping Cloud specifications of Alibaba open source.

So, second, why use SpringCloud Alibaba?

As mentioned above, some important components of SpringCloud’s official version, or Netflix version of SpringCloud, such as the registry Euraka and Ribbon, are no longer being updated iteratively.

SpringCloud Alibaba coincides with its graduation from open source incubation, so the popularity of SpringCloud has increased rapidly in the past two years, and it can even be called “SpringCloud2.0”.

General structure diagram of SpringCloud Alibaba

Key differences from SpringCloud’s Netflix:

Compatibility table of Spring Cloud Alibaba versions:


Well, that’s the end of microservices and SpringCloub Alibaba!



reference

[1] : Small column: SpringCloudAlibaba micro-service practice

[2] : Java Daily guide SpringCloud Alibaba micro-service practice

[3] : Geek time started to learn the frontline practical experience of micro-service and micro-blog service experts from 0

[4] : The road of selection of micro-service technology

[5] : Spring Cloud Alibaba, the only domestic open source project in Spring community, graduated