Micro-service design study (c) service registration and discovery services Governance

Foreword

Welcome to the Past series:

In today's popular micro-services, service granularity share split very fine, followed by a rapid increase in the number of services. In the wave of cloud native, the service management more often combined with container management platform, together form a one-stop automated dispatch management platform.

Of course, whether or not the use of container-based scheduling system, service governance principles and scope of change will not happen , but in different ways to achieve it.

Service management including service discovery, load balancing, current limiting, fuse, timeout, retries, tracking and other services. Our story today is the discovery of content services .

Chapter Summary

This chapter describes the following:

  1. What is service discovery? (What)
  2. Under the framework of micro-services Why do you need the service find it? (Why)
  3. Service discovery is how does it work? (How)
  4. CAP theorem
  5. Several existing solutions introduced (implementations)

Now, let's start this journey now.

What is service discovery (what)

Service discovery refers to finding a service provider's network location information.

Specifically refers to the use of a registry to record all the information in a distributed system services, so that other services can quickly find these services have been registered.

Service discovery is supporting large-scale SOA services and micro-architecture core module needs to have a service registration, service discovery, service health screening and services for notifications, change the key.

Why do you need service discovery? (Why)

Because there is no service discovery module, it will be coupled configuration service network location information in a specific service configuration among consumers, causing the system difficult to maintain.

Think of such a basic question: How do service consumers are aware of the service provider's IP and port it?

In a simple architecture, static configuration (such as DNS, Nignx load balancing configuration, etc.) can be a good way to solve the problem. Each service deployed in the same position, and rarely change. No resilient and elastic demand. The network address of the traditional monolithic application of probability change is small, in the event of a change of operation and maintenance personnel to manually update, load the configuration file.

But in the micro-services architecture is not the case, micro-service updates, frequent, and often will be resilient and elastic according to the load , because the network address changes in micro application examples of service is a very normal thing, and we mentioned earlier static configuration the solution, obviously not suitable for such a highly dynamic scenes. So, we need to provide a mechanism (module), so that service consumers can quickly and timely access to the latest information at the time of the service provider's IP address changes .

Service discovery is how does it work? (How)

As mentioned above, the use of a registry to record all the information in a distributed system services, so that other services can quickly find these services have been registered.

Let's use two examples to illustrate the operation of the service discovery mechanism (simple version):

image.png

  1. biz serviceStart telling its service information service center, service center complete written
  2. admin serviceStart, the service center to request biz serviceservice information
  3. Find a service center location information corresponding to the service, return toadmin service
  4. admin serviceAfter obtaining the actual address, the biz servicerequest to initiate

When biz serviceWhen using a cluster architecture, there are more nodes on the line, the entire workflow is kind of how it?

image.png

  1. Start new node service registration Discovery Center tells its own service information, service center complete written

  2. admin serviceInitiate a request to update biz servicethe address list service

    To give a client-side initiative to update the information request is "pull" way; there is a client-side register a callback, waiting for a notification service center, is a "push" manner)

CAP theorem

Although the "service discovery" of the entire operating mechanism is simple to understand, but in the actual scene distributed as a service core micro-architecture system, we definitely need way to build clusters, ensure high availability. This time, we need to consider some of the issues a distributed system may encounter.

In a distributed computer system, can only meet the consistency (Consistency), two of the three basic characteristics of availability (Availability) and partitions fault tolerance (Partition tolerance), this is the famous CAP theorem.

  • Consistency : refers to all the nodes are able to return with an updated copy of the data at the same time;

  • Availability : refers to a non-error can be returned in response to each request;

  • Zoning fault tolerance : refers to the communication between the server can not be kept open even if it will not affect the system continues to run at a certain time.

undefined

For distributed systems, fault tolerance partition must be met. Therefore, it must be a trade-off between consistency and availability, which is called the "Select AP chose to CP".

On the CAP theorem are not familiar with children's shoes, you can extend reading - CAP theorem

For service discovery and registration center cluster, if selected consistency at the expense of usability (select CP), then in order to ensure consistent data on the multi-service center, service center once down, the service center of a cluster point of need suspension of foreign data is written to provide services. Ensuring consistent data service center cluster at the same time, at the expense of the availability of written services. If you choose to availability at the expense of consistency (select AP), then in order to ensure uninterrupted service, when a center point of the service is down, still alive service center node can be selected writes data directly to the local store and then returned to the client ends, but this in turn will result in inconsistent data between multiple nodes.

The industry to provide for the registration of service discovery system, are essentially to meet APor CPsystem.

Existing solutions (implementations)

In a distributed service system, all of the service providers and consumers are dependent on [Center], the service center if there is a problem, there will be a state-aware service is not sensitive to such phenomena, and spread to the entire system. Therefore, to ensure the availability of critical registry for service discovery. To ensure the availability of the registry, to ensure multi-node deployment, if the background is a large site usually also be deployed across multiple rooms to ensure that the registry can still provide services in the case of a single room is not available. Service centers with high availability features need to have the following capabilities:

  1. It has the ability to multi-node deployment
  2. Have the ability to self-heal and adjust in a distributed scenario
  3. The ability to check the health of the nodes, the nodes access timeout can be removed from the current cluster, you can restore the ability to access node to join the current cluster again

In the following sections, we will introduce several common registry can be used directly as a product.

Zookeeper

Zookeeper is committed to providing a highly available and distributed coordination with strict sequential access control system, which is a distributed data consistency solutions.

ZooKeeper provides distributed notification and coordination, configuration management, naming service, the primary node election, distributed lock, distributed queues perfect solution . Which are widely distributed notification and coordination for service discovery. So far, it is the oldest service discovery field, the most widely used products.

undefined

This article does not introduce specific knowledge Zookeeper coherency protocols, data structures, etc., are interested can read the previous article of Zookeeper

Zookeeper Learning Series [a] teach you some basic concepts Zookeeper Zookeeper Zookeeper [three] Learning Series clustered architecture, mechanisms for reading and writing and the consistency principle (ZAB agreement)

Zookeeper read and write mechanism and coherence protocol determines that it is a CP system.

Advantages and disadvantages

ZooKeeper as the most widely distributed coordination component, the advantages are many. Extensive use is its biggest advantage, which also makes it easy to take advantage of ZooKeeper in the technical architect selection. However, it is clearly stated that the service is not the best choice for the Zookeeper discovery field, its main advantage for distributed strong consistency scene in elections and distributed lock. When the master node ZooKeeper because of network failures and lost contact with the other nodes in the system to trigger the election, the cluster is unavailable, this will lead to paralysis of registered service system during the elections.

Further reading Alibaba Why do not ZooKeeper service discovery?

Service center for data consistency requirements are not very demanding, but also difficult to achieve real-time perception goes down (there will be delay), it is more important is the ability to heal itself. Zookeeper by the client-side caching capability allows Curator ZooKeeper found a higher degree of adaptation in the field of service, but this is not ZooKeeper native capacity and designed.

etcd

With CoreOS increasingly hot and Kubernetes other projects in the open source community, etcd project components which are used as a high-availability, strong storage warehouse consistency of service discovery, getting into the vision of developers.

image.png

etcd Zookeeper is a project inspired by, and which has a similar structure and function to achieve a more straightforward Raft based protocols and language go. etcd also a CP system, consistency demands stronger than the availability requirements. etcd by TTL (Time To Live, survival time) to achieve similar functionality Zookeeper temporary nodes, a client need etcd continuously determines the timing renewal node operating status of the service.

Specific extension can read the following article.

Further reading etcd: round reading from scenario to implement the principle of

Official website: etcd.io/

Then introduce a high-quality etcd implement the principles of interpretation of the article: The principle of availability of distributed storage etcd

Compared Zookeeper, etcd has the following advantages:

  1. simple. Using the Go language deploy simple ; use HTTP as an interface easy to use; use Raft algorithm ensures strong consistency so that user can easily understand .
  2. Data persistence . etcd an update on the default data for persistence.
  3. Security . etcd support SSL client security authentication.

Eureka

Eureka open the Netflix, mainly for positioning the intermediate layer AWS service domain. Because Eureka is used as a registration center Spring Cloud, and therefore subject to a lot of attention. Eureka by the server and client both components. Eureka is generally used as the server service registration server, Eureka client to interact with the server simplified, provides support for the polling service failover as a load balancer.

Eureka ZooKeeper than the kind of CP system is more suitable as a registry service discovery system. Eureka priority to ensuring the availability, it uses a decentralized to the design concept, the entire service cluster consists of peer nodes, no election as the master node as ZooKeeper. Node in the cluster node failure does not affect the normal external services registration service and query capabilities . Eureka client has the ability to failover, if we find the connection fails when registering a service to the Eureka server, it automatically switches to the other nodes. Therefore, if there is a server node Eureka also be able to work properly, you need not worry about the availability of registry. However, to ensure consistency of data availability will inevitably lead to loss of client queries to the information is not necessarily up to date .

undefined

Eureka 2.X Although it has been announced that no longer maintained, but its current function has been very stable, even if you do not upgrade, service registry / discovery of these functions have been enough

Consul

Consul from HashiCorp product, provides some column properties, including service discovery, more extensive health check (memory, disk usage, and other fine-grained service state detection function), key-value pair storage capability, and multiple data centers (official website described four main features). And other programs compared with "one-stop" features.

image.png

Consul use the Go language, and therefore has a natural portability (support for Linux, windows and Mac OS X); package contains an executable file only to facilitate the deployment, with Docker and other lightweight containers can seamlessly fit.

And etcd Like, Consul raft agreement, which calls for more than half of the nodes are written based on the success of the registration was considered successful Leader hang throughout the Consul during the re-election is not available. Ensure strong consistency at the expense of usability.

The author is not much research on the Consul, interested readers can access relevant documents on their own learning.

Official website: www.consul.io/

nacos

Nacos is our domestic Alibaba's new open-source projects, the core position is "easier to help build a cloud-native application of dynamic service discovery, configuration, and service management platform." (Popular understanding, registry + Configuration Center)

image.png

Service (Service) is a first-class citizens Nacos world. Nacos supports almost all major types of "services" discovery, configuration and management:

  • Kubernetes Service

  • gRPC & Dubbo RPC Service

  • Spring Cloud RESTful Service

Nacos key features include:

  • Service discovery and health monitoring services
  • Dynamic configuration services
  • Dynamic DNS Service
  • Service and metadata management

More content, please read Nacos extended the official document:

Further reading nacos.io/zh-cn/docs/...

summary

This chapter describes some of the relevant knowledge discovery services, and related properties currently on the market the more popular service registry, hoping to inspire you.

Our next issue will be again.

Reference article

  1. Service Discovery in a Microservices Architecture
  2. Microservices: Service Registration and Discovery
  3. Service Discovery
  4. nacos.io/zh-cn/
  5. etcd: From scenarios to achieve the principle of all-round reading
  6. "From the cloud as a service to the native"
  7. "Micro Service Design"

If this article helpful to you, hoping to spot a praise, this is the biggest driving force for me.

Guess you like

Origin juejin.im/post/5dde5db16fb9a07175551fc9