Depth understanding of micro-analysis services (on)

Depth understanding of micro-analysis services (on)


Depth understanding of micro-analysis services (on)


Preface;

This year it was suggested that the 2019 micro services will be crazy to death, seen arguing micro service never stopped. In this I will be their understanding of micro-services collate it, and we want to help. Due to space too, small series into him on the next, oh I remember concern

What is micro-services

1) a set of small service (no particular standard size, as long as the same team of engineers to understand the identity service agreement)

2) independent process (java's tomcat, nodejs, etc.)

3) lightweight communications (not soap, is http protocol)

4) Based on the operational capacity (similar to user services, goods services, etc.)

5) Independent deploy fast (iteration speed)

6) no centralized management (without unified technology stack, can be flexible depending on the selected service or team)

ps: pioneer Netflix, micro-services, open source some good micro-services framework, there will be follow-up presentation.

Weigh how beneficial micro disadvantages services

Lee:

Strong module boundaries. (Modular evolution: Class -> component / library (sdk) -> Services (service), way more flexible)

It can be deployed independently.

Technical diversity.

Disadvantages:

Distributed complexity.

The final consistency. (Each team services, data management is decentralized, there will be inconsistencies)

Operation and maintenance complexity.

Test complexity.

When companies consider the introduction of micro services

From the complexity of the systems and productivity of these two perspectives. When the company started, the business complexity is not high, this time is to verify that the business model when the business is simple, with a single service but high productivity. As the company grew, slowly increase the complexity of the business, this time we can micro services to enhance the productivity. As for the transformation point, a team of architects to carry out various aspects of the measure, on personal experience, team development to more than a hundred people, the use of micro-services is very necessary.

Some architects have is the ability to micro-service architecture, so designed as direct micro services to design a system, rather than through a single service evolution slowly developed into a micro-services. Here I do not recommend this practice, because the beginning is not very understanding of the business and the business model has not been validated, this time on the micro-service risk is relatively high, is likely to fail. It is recommended that everyone in the application of single services mature, and more familiar with the business field, when if we find a single service can not adapt to business development, design and architecture to consider micro-services.

Organization Micro services

Depth understanding of micro-analysis services (on)


如上图左边,传统的企业中,团队是按职能划分的。开发一个项目时,会从不同的职能团队找人进行开发,开发完成后,再各自回到自己的职能团队,这种模式实践证明,效率还是比较低的。

如上图右边,围绕每个业务线或产品,按服务划分团队。团队成员从架构到运维,形成一个完整的闭环。一直围绕在产品周围,进行不断的迭代。不会像传统的团队一样离开。这样开发效率会比较高。至于这种团队的规模,建议按照亚马逊的两个披萨原则,大概10人左右比较好。

怎么理解中台战略和微服务

中台战略的由来:马云2015年去欧洲的一家公司supersell参观,发现这个公司的创新能力非常强,团队的规模很小,但是开发效率很高。他们就是采用中台战略。马云感触很深,回国后就在集团内部推出了中台战略。

Depth understanding of micro-analysis services (on)


简单的理解就是把传统的前后台体系中的后台进行了细分。阿里巴巴提出了大中台小前台的战略。就是强化业务和技术中台,把前端的应用变得更小更灵活。当中台越强大,能力就越强,越能更好的快速响应前台的业务需求。打个比喻,就是土壤越肥沃,越适合生长不同的生物,打造好的生态系统。

服务分层

每个公司的服务分层都不相同,有的公司服务没有分层,有的怎分层很多。目前业界没有统一的标准。

下面推荐一个比较容易理解的两层结构。

Depth understanding of micro-analysis services (on)


1:基础服务: 比如一个电商网站,商品服务和订单服务就属于基础服务(核心领域服务)。缓存服务,监控服务,消息队列等也属于基础服务(公共服务)

2:聚合服务 :例如网关服务就算一种聚合服务(适配服务)。

这是一种逻辑划分,不是物理划分,实际设计的东西很多很复杂。

微服务的技术架构体系

下图是一个成型的互联网微服务的架构体系:

Depth understanding of micro-analysis services (on)


1:接入层 负载均衡作用,运维团队负责

2:网关层 反向路由,安全验证,限流等

3:业务服务层 基础服务和领域服务

4:支撑服务层

5:平台服务

6:基础设施层 运维团队负责。(或者阿里云)

微服务的服务发现的三种方式

第一种:如下图所示,传统的服务发现(大部分公司的做法)。服务上线后,通知运维,申请域名,配置路由。调用方通过dns域名解析,经过负载均衡路由,进行服务访问。缺点: LB的单点风险,服务穿透LB,性能也不是太好

Depth understanding of micro-analysis services (on)


第二种:也叫客户端发现方式。如下图所示。通过服务注册的方式,服务提供者先注册服务。消费者通过注册中心获取相应服务。

并且把LB的功能移动到了消费者的进程内,消费者根据自身路由去获取相应服务。优点是,没有了LB单点问题,也没有了LB的中间一跳,性能也比较好。但是这种方式有一个非常明显的缺点就是具有非常强的耦合性。针对不同的语言,每个服务的客户端都得实现一套服务发现的功能。

Depth understanding of micro-analysis services (on)


第三种:也叫服务端发现方式,如下图所示。和第二种很相似。但是LB功能独立进程单独部署,所以解决了客户端多语言开发的问题。唯一的缺点就是运维成比较高,每个节点都得部署一个LB的代理,例如nginx。

Depth understanding of micro-analysis services (on)


微服务网关

网关就好比一个公司的门卫。屏蔽内部细节,统一对外服务接口。

Depth understanding of micro-analysis services (on)


下图是一个网关所处位置的示例图。

Depth understanding of micro-analysis services (on)


Netflix Zuul网关介绍

Depth understanding of micro-analysis services (on)


核心就是一个servlet,通过filter机制实现的。主要分为三类过滤器:前置过滤器,过滤器和后置过滤器。

主要特色是,这些过滤器可以动态插拔,就是如果需要增加减少过滤器,可以不用重启,直接生效。原理就是:通过一个db维护过滤器(上图蓝色部分),如果增加过滤器,就将新过滤器编译完成后push到db中,有线程会定期扫描db,发现新的过滤器后,会上传到网关的相应文件目录下,并通知过滤器loader进行加载相应的过滤器。

Depth understanding of micro-analysis services (on)


整个网关调用的流程

上图从左变http Request开始经过三类过滤器,最终到最右边的Http Response,这就是Zull网关的整个调用流程。

微服务的路由发现体系

Route Discovery entire micro system service, usually by the service registries and gateways of two parts. In NetFlix as an example, Eureka Zull two components and support the entire route netFlix discovery system. As shown below, a request is first sent to the external gateway, the gateway to the service registry to obtain the corresponding service call. Secondly calls between internal services, also through the service registry

Depth understanding of micro-analysis services (on)


Micro Service Configuration Center

At present, most companies are configured to write the configuration file, modify the configuration of the situation encountered, the high cost. And do not modify the configuration of the record, the problem difficult to trace. Configuration Center will take to solve the above problems.

Configurability: database connection, service parameters and the like

Depth understanding of micro-analysis services (on)


Configuration Center is a web service, configured to modify the configuration through the back pages, each service will get the new configuration parameters. There are two main implementations, one is push, the other is pull. Two methods have their advantages and disadvantages. push real-time performance is better, but encountered network jitter, the message will be lost. pull the message will not be lost but the real-time worse. It can simultaneously use two ways to achieve a better result. As shown below, this is a well-known Internet company's distribution center architecture diagram.

Depth understanding of micro-analysis services (on)


RPC encountered REST

Depth understanding of micro-analysis services (on)


Some internal core services, high performance requirements can be used RPC, generally using rest of external services.

The upper half of the first share here, oh I remember concern, will share daily java related articles

 


Guess you like

Origin blog.51cto.com/14456091/2427393