在微服务之间共享(几乎)相同的数据以进行项目推荐是个坏主意吗? [英] Is it bad idea to share (almost) identical data among microservices for item recomendation purposes

查看:64
本文介绍了在微服务之间共享(几乎)相同的数据以进行项目推荐是个坏主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对由微服务组成的应用程序的架构有疑问.

I have a question about the architecture of application composed of microservices.

我几乎没有微服务,但是在这个问题中有趣的是:

I have few microservices, but those that are interesting in the context of this question are:

  1. 人力资源-这里存储着所有用户数据,例如用户名,性别,用户体验等.
  2. 职位-这里存储着有关每个职位广告的所有数据-职位描述,预期经验等.
  1. Human Resources - here are stored all the user data such as username, sex, user's experience etc.
  2. Jobs - here are stored all the data about each job advertisement - job description, expected experience etc.

因此,我需要创建新的微服务(将其命名为 Recommender ),其唯一目的是-根据上述微服务的文本,从 Human推荐最合适的人工帐户每个职位广告的资源.来自工作.我用来计算相似度的NLP算法需要遍历每个职位广告中的每个人力资源项目.

So, I need to create new microservice (let's name it Recommender) which sole purpose will be - based on the texts of the microservices mentioned above to recommend best fitted human account from Human Resources to each job ad. from Jobs. The NLP algorithm which I use to calculate the similarities need to walk each Human Resources item for every Jobs ad.

到目前为止,太好了.实现此目的的一种方法是引入Message Queue.在来自 Human Resources 的人力资源的每个创建/更新操作上,以通过此MQ发送带有所有资源数据的新消息.推荐微服务将处理此新消息,它将处理所需的数据(删除不需要的数据)并将其存储在本地数据库中.当更新/创建工作资源以计算一对一相似度时,将需要相同的内容.

So far, so good. One way to achieve this is to introduce Message Queue. On each create/update operation of human resource from Human Resources to push new message with all the resource data through this MQ. The Recommender microservice will handle this new message, it will process the needed data (remove the not needed data) and it will store it in local DB. Same thing will be needed when Jobs resource is updated/created in order to calculate one-to-one similarities.

这是我的问题:

  1. 是否有更好的方法来实现上述目标?
  2. 我知道微服务架构设计中的最佳实践告诉我们,数据不应该重复,但是可以存储经过处理的有限数据(例如原始数据的副本)吗?

谢谢!

推荐答案

我认为带有三个服务(HR,Jobs,Recommender)的通用体系结构很好,因为它明确定义了职责并分离了系统中的不同功能.

I think that the general architecture with the three services (HR, Jobs, Recommender) is fine as it clearly defines the responsibilities and separates the different functions in the system.

我认为,您不应将任何数据永久保留在推荐服务中.想象一下,如果HR数据库的数据库架构发生了更改(例如新数据字段),则可能必须更改推荐程序算法,但是您只想更改一个(HR)服务中的数据库,而不想更改两个服务中的数据库.想象一下,如果由于某种原因,Recommender服务由于错误而错过了更新事件,您将不得不以某种方式修复这两个服务之间不一致的数据库状态.

In my opinion, you should not keep any data persistently in the Recommender service. Imagine if the database schema for the HR database changes (e.g. new data field), you will perhaps have to change the recommender algorithm, but you want to change the database in only one (the HR) service, and not in both services. Imagine if for some reason the Recommender service missed an update event due to an error, you would somehow have to repair the inconsistent database state between the two services.

另一方面,如果您需要节省服务之间的通信带宽,则可以考虑将某些数据作为体系结构的折衷方案-但这似乎不太可能,并且会与微服务体系结构背后的想法背道而驰.

On the other hand, if you had a requirement to save on communication bandwidth between your services, you could think of keeping some data as an architectural tradeoff - but this seems improbable and would be kind of against the idea behind a microservices architecture.

这篇关于在微服务之间共享(几乎)相同的数据以进行项目推荐是个坏主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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