分享微服务之间code和架构 [英] Sharing code and schema between microservices

查看:199
本文介绍了分享微服务之间code和架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你去的微服务架构在您的组织,他们可以通过饲养员或它的共享配置当量。然而,各种服务应该如何共享一个共同的数据库架构?公用常数?共同的事业吗?

If you go for a microservices architecture in your organization, they can share configuration via zookeeper or its equivalent. However, how should the various services share a common db schema? common constants? and common utilities?

一种方法是放置在同一个code库中的所有微服务,但是这将违背附带微服务脱钩...

One way would be to place all the microservices in the same code repository, but that would contradict the decoupling that comes with microservices...

另一种方法是让每个微服务是完全独立的,但是这会导致在分开的数据库code重复和数据复制每个微服务必须持有

Another way would be to have each microservice be completely independent, however that would cause code duplication and data duplication in the separate databases each microservice would have to hold.

另一种方法是实现功能微服务无上下文的\\状态,但是这通常是不现实的,并且将推动架构,具有维持从\\背景\\状态和大量的流量给它的中心枢纽。

Yet another way would be to implement functional microservices with no context\state, but that's usually not realistic and would push the architecture to having a central hub that maintains the context\state and a lot of traffic from\to it.

什么是分享微服务之间code和模式的可扩展,高效实用,希望美丽的方式?

推荐答案

关于共同code,它使用包装系统的最佳实践。所以,如果你使用Java,然后用maven,如果你使用Ruby然后宝石,如果然后Python的PyPI等。
理想的情况下包装系统增加了小摩擦,所以你可能有一个(比如说,GIT)为了一个共同的LIB库(或几种常见-库针对不同的主题),并通过一个构件库(如私人行家/宝石/ PyPI中)发表他们的文物。然后在微服务添加上所需的libs.So code重用的依赖是很容易。
在某些情况下,包装系统做添加使用的一切单一的git回购和多模块项目设置一些摩擦(行家一)所以有​​人会preFER。这并不像第一种方法是干净的,但工程,以及和不算太糟糕。
其他选项是使用git子模块(不希望),或者git的子树(更好),以包含在一个单一的父库源$ C ​​$ C。

Regarding common code, the best practice it to use a packaging system. So if you use Java, then use maven, if you use Ruby then Gems, if python then pypi etc. Ideally a packaging system adds little friction so you may have a (say, git) repository for a common lib (or several common-libs for different topics) and publish their artifacts through an artifact repository (e.g. private maven/gems/pypi). Then at the microservice you add dependency on the required libs.So code reuse is easy. In some cases packaging systems do add some friction (maven for one) so one might prefer using a single git repo for everything and a multi-module project setup. That isn't as clean as the first approach but works as well and not too bad. Other options are to use git submodule (less desired) or git subtree (better) in order to include the source code in a single "parent" repository.

关于模式 - 如果你想通过这本书玩,那么每个微服务都有自己的数据库。他们不碰对方的数据。这是一个非常模块化的方法起初似乎一些摩擦添加到您的过程,但最终我想你会感谢我的。这将允许在你的微服务快速迭代,比如你可能要与一个特定的服务,另一个数据库的实现来替换一个数据库的实现。想象一下这样当你所有的服务都使用同一个数据库!祝你好运......但是,如果每个单独的服务使用它自己的数据库服务正确抽象数据库(例如它不接受SQL查询的API调用,例如;-)),然后改变MySQL来卡桑德拉突然变得可行。
还有其他的上涨空间具有完全隔离的数据库,例如负载和缩放,找出瓶颈,管理等。

Regarding schema - if you want to play by the book, then each microservice has its own database. They don't touch each other's data. This is a very modular approach which at first seems to add some friction to your process but eventually I think you'll thank me. It will allow fast iteration over your microservices, for example you might want to replace one database implementation with another database implementation for one specific service. Imagine doing this when all your services use the same database! Good luck with that... But if each single service uses it's own database the service abstracts the database correctly (e.g. it does not accept SQL queries as API calls for example ;-)) then changing mysql to Cassandra suddenly become feasible. There are other upsides to having completely isolated databases, for example load and scaling, finding out bottlenecks, management etc.

因此​​,在短期 - 普通code(公用事业,常量等) - 使用包装系统或某些源$ C ​​$ C链接,如git的树

So in short - common code (utilities, constants etc) - use a packaging system or some source code linkage such as git-tree

数据库 - 你不要碰我的,我不碰你的。这是解决这个问题的更好的方法。

Database - you don't touch mine, I don't touch yours. That's the better way around this.

心连心,冉。

这篇关于分享微服务之间code和架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆