.net core 微服务_使用.NET Core的单片到微服务

.net core 微服务

Apart from BookMyShow’s 150+ microservices, the transaction system, which is one of the most important ones, is written in C# targeting .NET framework. The initial version was written targeting .NET framework 2.0 back in 2007 and during all these years it has grown — in terms of scale and code. It consists of around 4 core components (class libraries) and has been running on fat Windows virtual machines.

除了BookMyShow的150多种微服务外,最重要的交易系统之一是以C#为目标的.NET框架编写的。 最初的版本是在2007年针对.NET Framework 2.0编写的,在这些年中,它的规模和代码都在增长。 它由大约4个核心组件(类库)组成,并已在胖Windows虚拟机上运行。

Here’s a brief of what each of these components are responsible for:

这是这些组件各自负责的简要信息:

  • Ticketing System — Responsible for to and fro communication between BookMyShow and various cinema softwares. It facilitates all the core booking operations like fetching seat layout, seat selection, booking confirmation et. al. and acts as a generic interface for the transaction system for all of these operations.

    票务系统—负责BookMyShow与各种电影软件之间的来回通信。 它促进了所有核心的预订操作,例如获取座位布局,座位选择,预订确认等。 等 并充当所有这些操作的交易系统的通用接口。

  • Payment Gateways — Just like ticketing, it is responsible for all payment related operations and communications between BookMyShow and different payment providers. It also provides a generic interface to the transaction system for common operations.

    支付网关—就像票务一样,它负责BookMyShow与不同支付提供商之间所有与支付有关的操作和通信。 它还为事务处理系统提供了通用接口,以便进行常见操作。

  • Order Manager — Provides a common interface to the transaction system for all order related operations provided by our platform varying from movies to live entertainment, and more.

    订单管理器-为交易平台提供一个通用接口,用于交易平台所提供的所有与订单相关的操作,从电影到现场娱乐等等。

  • Cache Manager — This component is responsible for read through and write through cache operations with Redis being our main cache provider supported by various database technologies like SQL, MariaDB, MongoDB as primary storages.

    缓存管理器-该组件负责读和写缓存操作,Redis是我们的主要缓存提供程序,并由各种数据库技术(例如SQL,MariaDB,MongoDB)作为主要存储支持。

Apart from these components, there’s shared code (common classes) used by one or many of these components. Shared code ranges from common business logic to wrappers supporting various I/O operations like database and api calls.

除了这些组件之外,其中一个或多个组件还使用共享代码(通用类)。 共享代码的范围从常见的业务逻辑到支持各种I / O操作(如数据库和api调用)的包装器。

Every year we continue to grow in terms of incoming traffic which means we need to have enough instances in place to handle the load. We also have microservices written in other technologies (GoLang, NodeJS, PHP) which are running on linux. After years of managing infrastructure, we have seen a huge difference in ease of managing linux servers than windows servers in terms of speed of scaling and ease of automation (in setting up new servers, deploying code and operating system updates). Another huge problem we face with our monolith is that teams cannot deploy shared code updates without involving other teams. For e.g. a database driver update cannot be done as it would mean updating the drivers for all the teams at the same time, and if there is not backward compatibility, things are definitely going to break.

每年,我们的传入流量都在不断增长,这意味着我们需要有足够的实例来处理负载。 我们还具有用其他技术(GoLang,NodeJS,PHP)编写的微服务,这些技术正在linux上运行。 经过多年的基础架构管理,我们在扩展Linux的速度和自动化的便利性(设置新服务器,部署代码和操作系统更新)方面,在管理Linux服务器方面与在Windows服务器方面存在巨大差异。 我们面临的另一个巨大问题是,团队无法在没有其他团队参与的情况下部署共享代码更新。 例如,无法完成数据库驱动程序更新,因为这将意味着同时更新所有团队的驱动程序,并且如果不存在向后兼容性,则肯定会中断。

Around May 2017, we initiated a plan to transform our transaction monolith into microservices using a tech stack which can run on linux. At this time, .NET core was already out with the latest stable version at that time being 1.1. We tried it out but there was neither much support for all the existing .NET framework APIs that we used, nor community support from open source libraries. By August 2017, except the tech-stack, we had a high-level plan on how we were going to proceed to break down our monolith. We had decided on having all internal communication on gRPC and a step-by-step re-write of our monolithic components.

2017年5月左右,我们启动了一项计划,使用可在Linux上运行的技术堆栈将交易整体转换为微服务。 当时,.NET core已经不存在了,当时最新的稳定版本是1.1。 我们进行了尝试,但是对我们使用的所有现有.NET Framework API都没有太多支持,也没有开源库提供的社区支持。 到2017年8月,除了技术堆栈之外,我们已经制定了一个高层计划,以决定如何分解整体。 我们决定在gRPC上进行所有内部通信,并逐步重写我们的整体组件。

We were almost ready to execute our plan when around the same time, Microsoft released .NET standard 2.0 along with .NET core 2.0, providing support for more than 32k .NET framework APIs making it much easier to port existing code to .net standard/core.

大约在同一时间,我们几乎准备执行我们的计划,Microsoft发行了.NET标准2.0和.NET Core 2.0,并为超过32k的.NET Framework API提供了支持,这使得将现有代码移植到.net标准/更加容易。核心。

Image for post

We decided to give this version a try. We took a small subset of one of our core components — the ticketing system and started porting it. We finalised a gRPC contract and created a microservice in just a week.

我们决定尝试使用此版本。 我们从一小部分核心组件中获取了票务系统,并开始进行移植。 我们完成了一份gRPC合同,并在短短一周内创建了一个微服务。

And how did we achieve this? Well, since dot-net framework and .NET-core share the same language and nothing changed in terms of language syntax, our business logic didn’t demand any modifications. All we did was copy our classes from the class library to this new microservice, a few minor tweaks in how we call external apis like switching to http client factory from web request class, create a gRPC server on top of it and we had our first .NET core microservice ready!

我们如何实现这一目标? 好吧,由于dot-net框架和.NET-core共享相同的语言,并且在语言语法方面没有任何变化,因此我们的业务逻辑不需要进行任何修改。 我们所做的只是将我们的类从类库复制到此新的微服务中,对我们如何调用外部api进行了一些细微调整,例如从Web请求类切换到http客户端工厂,在其之上创建了一个gRPC服务器,我们有了第一个.NET核心微服务已准备就绪!

Image for post

The ported microservice performed pretty well and soon we started adding more cinema related business logic to it. At present, more than 50% of our movies related ticketing happens through this. The microservice is deployed on Kubernetes, which allows it to scale automatically without any manual intervention. During one of the recent big releases, it performed pretty well with 14 pods handling roughly ~70k RPM in total.

移植的微服务性能非常好,很快我们就开始向它添加更多与电影相关的业务逻辑。 目前,超过50%的电影相关票务是通过这种方式发生的。 该微服务已部署在Kubernetes上,从而无需任何人工干预即可自动扩展。 在最近的一个大型发行中,它的14个Pod的表现相当不错,总共可处理约70k RPM

Without a complete rewrite and with a very little effort, we were able to migrate to linux using .NET core and the results have been promising. We can now scale our ticketing system automatically on demand and deployments for the ticketing team has been easier than ever, they can deploy whenever they want and use any version of libraries they need. Hence, we continue to migrate all our existing .NET framework systems to .NET core, and as we write this, we are close to finishing it.

无需完全重写就可以用.NET core迁移到linux,并且结果令人鼓舞。 现在,我们可以按需自动扩展票务系统,并且票务团队的部署比以往更加轻松,他们可以随时随地进行部署,并使用所需的任何版本的库。 因此,我们将继续将所有现有的.NET Framework系统迁移到.NET核心,并且在撰写本文时,我们即将完成。

翻译自: https://we-are.bookmyshow.com/monolith-to-microservices-using-dotnet-core-220b057aa1e6

.net core 微服务

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值