What are microservices?

The concept of microservices was first put forward by Martin Fowler and James Lewis in 2014. They defined microservices as small services composed of a single application with its own process and lightweight processing. The services are designed according to business functions and deployed in a fully automatic way. Communicate with other services using the 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. Microservices are the end product of an SOA architecture that is designed to break up businesses and enable services to run independently. It has the following characteristics

Finer granularity of service separation 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.

Independent service deployment Each microservice complies with the independent package deployment principle 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.

Each microservice can be developed, tested, published, and operated by a small team or even an individual, and is responsible for its entire life cycle.

High requirement for service governance Capability Because the number of services increases after being split into micro-services, a unified service governance platform is required to manage each service.

In microservice architecture, service invocation mainly relies on the following basic components: Service Description Registry service framework Service monitoring service tracking service governance

Introduction to the open source RPC framework

Dubbo

The earliest open source RPC framework in China, developed by Alibaba and opened source at the end of 2011, only supports Java language. There was no maintenance pit in the middle of many people, 17 years to restart the maintenance of the new Spring. The architecture diagram is as follows

Liverpoolfc.tv: dubbo. IO /

In terms of communication framework, Dubbo uses Netty as the default communication framework.

In terms of communication protocols, Dubbo supports not only the proprietary Dubbo protocol, but also RMI, Hession, HTTP, and Thrift.

In terms of serialization formats, Dubbo supports a variety of serialization formats, such as Dubbo, Hession, JSON, Kryo, FST, etc.

Performance: dubbo.apache.org/zh-cn/docs/…

Tars

Tars is a high-performance RPC development framework based on the name service and Tars protocol. It also supports an integrated service governance platform to help individuals or enterprises quickly build their own stable and reliable distributed applications in the way of micro-services. Tars is an open source project based on years of practice achievements of TAF (Total Application Framework), a micro-service architecture used internally by Tencent.

Liverpoolfc.tv: github.com/TarsCloud/T…

The architecture diagram is as follows

Support multi-language C++, Java, Nodejs, PHP, Go

Performance: github.com/TarsCloud/T…

gRPC

Originally developed by Google, it is a language-neutral, platform-neutral, open source remote procedure Call (RPC) system. Liverpoolfc.tv: GRPC. IO

HTTP/2 Based on HTTP/2 HTTP/2 provides connection multiplexing, bidirectional flow, server push, request priority, header compression, and other mechanisms. It can save bandwidth, reduce the number of TCP connections, save CPU, and prolong the battery life of mobile devices. GRPC protocol design uses the existing semantics of HTTP2, request and response data is sent using HTTP Body, other control information is represented by headers.

IDL uses ProtoBuf gRPC defines services using ProtoBuf, a data serialization protocol (similar to XML, JSON, and Hessian) developed by Google. ProtoBuf can serialize data and is widely used in data storage and communication protocols. High compression and transmission efficiency, simple syntax, strong expression.

Multi-language support (C, C++, Python, PHP, Nodejs, C#, Objective-C, Golang, Java) gRPC supports multiple languages and can automatically generate client and server function libraries based on the language. GRPC supports C, C++, Node.js, Python, Ruby, Objective-C, PHP, C# and other languages. Grpc-java already supports Android development.

Motan

Motan is another well-known open source RPC framework in China, which also supports only Java language implementation. Its architecture can be described in the following figure.

Register: Used to interact with the registry, including registration service, subscription service, service change notification, service heartbeat, and other functions. The Server registers services through the Register module during system initialization, and the Client subscribes to the list of servers that provide services through the Register module during system initialization. The Register module also notifies the Client when the Server list changes.

Protocol: used to describe RPC services and configure and manage RPC services. Filters of different functions can be added at this layer to complete statistics and concurrency limitation.

Serialize: Serializes and deserializes objects such as parameters and results in RPC requests. That is, converts objects to byte streams. By default, Hessian 2, which is more friendly to Java, is used for serialization.

Transport: used for remote communication. The default mode is Netty NIO TCP long link.

Cluster: module used by the Client. Cluster is the logical encapsulation of a group of available servers. It contains several servers that can provide RPC services.

Spring Cloud

Spring Cloud is a development framework that provides a series of functions to solve the service governance in microservice architecture. It is completely developed based on Spring Boot. Spring Cloud integrates excellent components in the open source industry with Spring Boot features. As a whole, it provides a set of service governance solutions in the micro-service architecture. Its architecture diagram can be described in the following diagram.

The following are the core features of Spring Cloud:

  • Distributed/versioned configuration
  • Service registration and discovery
  • routing
  • Services and calls between services
  • Load balancing
  • The circuit breaker
  • Distributed messaging

Spring Cloud is a boon for small and medium sized Internet companies, which often do not have the resources or financial resources to develop their own distributed system infrastructure. Using Spring Cloud’s one-stop solution can significantly reduce development costs while taking their business in stride.

Below is a detailed comparison of RPC frameworks

How to choose?


For example, the company does not plan to switch Java framework or continue to use NET architecture, has certain research and development capabilities, high requirements for concurrency, that gRPC is undoubtedly the most suitable, cross-language support, high performance;

There is no perfect solution, only the right one

Recommended reading

Redis questions that Internet companies must ask in an interview

Mysql (2)

Learn Java advanced technology dry goods, practice sharing, job promotion, talk about the ideal. Like-minded friends, welcome to join.