Micro-service design principles and the actual landing

Micro-service architecture is mandatory most enterprise application architecture, micro-serving reason is because of the relatively hot before application development approach has many advantages, such as more flexible, more scalable, fault influence range of smaller, more responsive now rapid change and the environment iteration needs.

I will micro-service architecture evolution, strengths and weaknesses, micro-service design principles and practical applications of landing experience to share, and then highlight as a "micro-service application platform," which capabilities need to provide, what problems to solve in order to better support enterprise application architecture.

Micro Services Architecture is my most current mainstream technical architecture, architecture design project is being managed by the group mainly SpringCloud, combined with my personal business more than a decade of technical architecture design and development of application software products to understand and Internet experience design, and gradually evolved a distributed application architecture platform.

A micro-service architecture evolution

In recent years, my colleagues have come to realize the benefits of the Internet, mobile Internet, networking and other brings, as a software industry practitioners, in life time experience the benefits of mobile Internet and the Internet of things while at work may feel it is from all some of the pressure side, that is our traditional enterprise IT building is also an urgent need for transformation, the need for external customers, we also need to respond to rapid changes in the external environment, the need for rapid innovation, our IT infrastructure also need to be made to Internet companies to learn the appropriate improvements to support the digital transformation of enterprises.

Let's look at the evolution of application architecture, recall micro Services Architecture is a step by step how evolution produced the earliest applications JSP / ASP technology-based, highly coupled logic and business pages, followed by single architecture (SSH or the SSM), made suitable separation or delamination process, the volume of items bigger and bigger, and later to have a certain extension, throughput, reliability, and performance, have a vertical configuration, i.e. the load balance added, with the development of enterprise information, each enterprise's internal systems more and more, forming a lot of information silos, to get through the barriers of information inside and outside the enterprise, then using SOA architecture to solve these problems, mainly about how to integrate between applications and interoperability, with the mobile Internet era of things, and now the micro-service architecture came into being, making the development more iterative agile, less coupling between modules, greatly enhance the speed troubleshooting, and many other benefits.

The basic idea of ​​micro-services architecture is "to create applications around business components, so that the application can separate development, management and accelerate."

Second, the benefits of micro Services Architecture

I summed up the advantages of several aspects, are as follows:

High degree of autonomy: each micro-service components are simple and flexible, can be deployed independently. No longer like before, the performance of applications that require a powerful application server to support.

Small efficient team collaboration: a large, complex applications can be responsible for several small teams to concentrate more on professional and appropriate it is even more efficient and reliable.

High cohesion, low coupling: between the micro services are loosely coupled, the internal micro service is highly cohesive, each micro-demand service easily.

Language independence: micro-services architecture and tool-independent language, the freedom to choose the appropriate language and tools, and efficient completion of business objectives can be.

See here, we will feel very good micro-service architecture, but there are still some questions, what kind of application be a micro-service application architecture? How to design the application of a micro-service architecture? Then we take a look we recommend the design principle of micro-services applications.

Third, several micro-service application architecture design principles

1. AFK split principle

The industry has a simple design concept for a scalable system architecture: the capacity and availability can solve the problem by adding machine.

  The concept of cloud computing concept crazy popular today, has been widely recognized system for a rapidly growing size, capacity and performance issues of course bear the brunt. But with the forward growth of the size of the system, in addition to face the problem of performance and capacity, but also brought about growth in the face of system functions and the number of modules time to bring the complexity of the issues and changes in the business of providing differentiated question of the service.

  However, many system architecture designed to take full account of these problems, leading to system reconfiguration become the norm, affecting service delivery capabilities, but also a waste of human and financial resources. This "scalable Art," a book proposed a system scalable model --AKF scalable cubic (Scalability Cube).

Y-axis (Function) functional division of interest applications, based on different service splitter

  Y axis expansion will be large, monolithic applications into multiple services, each implement a set of related functions, such as order management, customer management. In engineering common scenario is service oriented architecture (SOA), such as for an e-commerce platform, we can be split into different services, similar to the composition of the following schema:

  但通过上图可以发现,当服务数量增多时,服务调用关系变得复杂,为系统添加一个新功能,要调用的服务数变得不可控,由此引发了服务管理上的混乱,所以一般情况下,需要采用服务注册的机制形成服务网关来进行服务治理

X轴(水平扩展)关注水平扩展,也就是“加速器解决问题”

  X轴扩展与我们前面朴素理念是一致的,通过绝对平等的复制服务与数据,以解决容量与可用性的问题,其实就是将微服务运行多个实例,做集群加负载均衡的模式。

  为了提升单个服务的可用性与容量,对每一个服务进行X轴扩展划分。

Z轴(数据分区)关注服务与数据的优先级划分,如按地域划分

  Z轴扩展通常是指基于请求者或用户独特的需求,进行系统划分,并使得划分出来的子系统相互隔离但又是完整的。以生产汽车的工厂来举例:福特公司为了发展在中国的业务,或者利用中国的廉价劳动力,在中国建立一个完整的子工厂,与美国工厂一样,负责完整的汽车生产。这就是一种Z 轴扩展。

工程领域常见的Z轴扩展有以下两种方案

单元化架构

  在分布式服务设计领域,一个单元Cell就是满足某个分区所有业务操作的自包含闭环。如上面我们说到的Y轴扩展的SOA架构。客户端对服务端节点的选择一般是随机的,但是,如果在此上加Z轴扩展,那服务节点的选择将不再是随机的,而是每个单元自成一体。

数据分区

  为了性能数据安全上的考虑,我们将一个完整的数据集按一定维度划分出不同的子集。一个分区(Shard),就是整体数据集的一个子集。比如用尾号来划分用户,那同样尾号的那部分用户就可以认为是同一个分区,数据分区一般包括以下几种数据划分形式:

  数据类型:如业务类型

  数据范围:如时间段、用户ID

  数据热度:如用户活跃度、商品热度

  按读写分:如商品描述、商品库存

2.前后端分离

何为前后端分离?前后端分离在不同时期有不同的理解,大约在十年前的前后端分离指的是表示层技术、业务逻辑代码以及数据访问层的分离,但是部署还是在一起,最终形成了一个大大的war包或者EAR包。随着时代的进步,出现了模板化技术,使得团队角色分工进一步细化,再后来出现了分布式部署项目,形成了前端团队与后端团队独立开发、独立部署,最终以中立的RestAPI接口进行无状态交互,好处显而易见。

  前后端分离原则,简单的将就是前端和后端的代码分离,我们推荐的模式是最好采用物理分离的方式部署,进一步促使更彻底的分离。如果您还是继续使用十几年前的服务端模板技术,如jsp,把java、js、css、html都堆到一个页面里,一方面被时代远远的甩在了不起眼的小角落,另一方面现代复杂的应用痛苦至极。

这种前后端分离有几个好处:

1,前后端技术分离,可以由各自的专家来对各自的领域进行优化,这样前端的用户体验会更好。

2,分离模式下,前后端交互界面更清晰,就剩下接口模型,后端接口简介明了,更易于维护。

3,前端多渠道继承场景更容易实现,后端服务无需变更,采用统一的数据和模型,可以支持多个前端,例如:微信h5前端、PC前端、安卓前端、IOS前端、车载端等等。

3.无状态服务

对于无状态服务,首先说一下什么是状态:如果一个数据需要被多个服务共享,才能完成一笔交易,那么这个数据被称为状态。进而依赖这个“状态”数据的服务被称为有状态服务,反之称为无状态服务。

那么这个无状态服务原则并不是说在微服务架构里就不允许存在状态,表达的真实意思是要把有状态的业务服务改变为无状态的计算类服务,那么状态数据也就相应的迁移到对应的“有状态数据服务”中。

4.无状态通信风格

无状态通讯有很多好处:

无状态协议HTTP,具备先天优势,扩展能力很强。例如需要安全加密是,有现成的成熟方案TLS/HTTPS可用。

JSON 报文序列化,轻量简单,人与机器均可读,学习成本低,搜索引擎友好。

语言无关,各大热门语言都提供成熟的Restful API框架,相对其他的一些RPC框架生态更完善。

当然在有些特殊业务场景下,也需要采用其他的RPC框架,如thrift、avro-rpc、grpc。但绝大多数情况下Restful就足够用了。

场景说明:例如我们以前在本地内存中建立的数据缓存、Session缓存,到现在的微服务架构中就应该把这些数据迁移到分布式缓存中存储,让业务服务变成一个无状态的计算节点。迁移后,就可以做到按需动态伸缩,微服务应用在运行时动态增删节点,就不再需要考虑缓存数据如何同步的问题。

四、微服务架构带来的问题

做到了前面讲的四个原则,那么就可以说是构建了一个微服务应用,感觉上也不复杂。但实际上微服务也不是个万金油,也是有利有弊的,接下来我们来看看引入微服务架构后带来的问题有哪些。

依赖服务变更很难跟踪,其他团队的服务接口文档过期怎么办?依赖的服务没有准备好,如何验证我开发的功能。

部分模块重复构建,跨团队、跨系统、跨语言会有很多的重复建设。

微服务放大了分布式架构的系列问题,如分布式事务怎么处理?依赖服务不稳定怎么办?

运维复杂度陡增,如:部署物数量多、监控进程多导致整体运维复杂度提升。

上面这些问题我们应该都遇到过,并且都会有一些成熟稳定的解决方案,比如提供文档管理、服务治理、服务模拟的工具和框架; 实现统一认证、统一配置、统一日志框架、分布式汇总分析; 采用全局事务方案、采用异步模拟同步;搭建持续集成平台、统一监控平台等等,但是,给团队随之带来了更多的挑战。

五、微服务架构落地经验

1. 采用成熟的调用链监控系统,进行微服务之间调用链的实时监控,通过一张图可以直观的看到复杂应用的调用关系;

2. 采用SpringCloud技术栈进行实施,技术成熟,社区活跃;

3. 采用目前最火的K8S docker集群管理系统,进行微服务的运维部署,使得运维更加弹性与轻松;

4. 做好日志集中检索,出现问题及时发现;

5. 故障告警连接钉钉、短信、邮件等方式,随时掌握线上情况,及时进行处理,给客户带来极致体验。

 

发布了4 篇原创文章 · 获赞 0 · 访问量 43

Guess you like

Origin blog.csdn.net/leijun_110/article/details/104602327
Recommended