选择微服务还是库作为依赖项? [英] Select micro services vs library as dependency?

查看:204
本文介绍了选择微服务还是库作为依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个模块(带有DB1的mod1和带有DB2的mod2)托管为微服务.这两个模块都有一些共同的功能,可以与DB1和DB2进行交互.

I have two modules(mod1 with DB1 and mod2 with DB2) hosted as microservices. Both modules have some common functionality which can interact with DB1 and DB2 both.

方法_1:-将另一个mod3作为通用组件的共享库jar并注入到两个模块中,以避免代码重复

Approach_1:- Make another mod3 as shared library jar for common component and inject it in both modules to avoid duplication of code

方法_2:-为公用组件而不是共享库jar创建另一个微服务.

Approach_2:- Make another micro service for common component instead of shared library jar.

不确定在设计方面哪种方法更好,在这里我需要考虑哪些标准?

Not sure which approach is better in term of design and what criteria I need to consider here?

据我了解,它应该是一个共享库而不是微服务,因为它将与多个数据库交互.如果它是共享jar,则该模块在逻辑上与业务上的调用方模块同在.

Per my understanding, It should be a shared library instead of microservice as it will interact with multiple DB. If it is shared jar, that module logically lies with caller module business wise.

推荐答案

如果您有两个都可以访问相同两个数据库的微服务,并且您正在考虑将公共数据库访问代码分解为一个库,那么您应该至少考虑一下您实际上只有一个微服务的想法.

If you have two micro services that both access the same two databases, and you are thinking about factoring the common database-access code out into a library, then you should at least consider the idea that you really only have one microservice.

考虑一下,如果您更改其中一个数据库的架构,将会发生什么.您必须更新两个微服务才能处理更改.如果您有一个库,则必须更新该库,然后构建和发布这两个微服务.通过维护两个微服务而不是一个,您会获得什么?似乎还需要更多工作.

Think about what would happen if you changed the schema of one of the databases. You'd have to update both of the microservices in order to deal with the change. If you had a library, you'd have to update the library, then build and release both of the micro services. What are you gaining by maintaining two microservices instead of just one? It just seems like more work.

您可能会说,有时候我可能会做出仅影响一个微服务逻辑的更改,然后我才可以构建和发布该服务.没错,但是如果您只有一项微服务,那么您仍然只是在构建和发布一项微服务.仅仅因为存在其他一些您尚未构建和发布的微服务,构建和发布一个微服务并不容易.

You might say, well sometimes I might make a change that only affects the logic of one microservice, and then I could build and release just that service. That's true, but if you had one microservice, you'd still just be building and releasing one microservice. It's not easier to build and release one microservice just because there exists some other microservice that you're not building and releasing.

这篇关于选择微服务还是库作为依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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