简体   繁体   English

在典型的微服务体系结构中,如何在微服务的单独的RDBMS数据库中链接相关数据?

[英]How to link the related data in the separate RDBMS databases of the micro-services in a typical micro-services architecture?

Let us say that I am designing an e learning portal where in a user can choose the courses he wishes to take and then do the payment online and then he/ she can use the courses.So I have modules like 1) Courses 2) Payments 3) User management. 假设我正在设计一个电子学习门户,用户可以在其中选择自己想参加的课程,然后在线进行付款,然后他/她可以使用这些课程。因此,我有以下模块:1)课程2)付款3)用户管理。 I choose to design 3 separate microservices ie a) Courses b) Payments and c) User management based on the domain. 我选择设计3个独立的微服务,即a)课程b)付款和c)基于域的用户管理。 Now if this system was a monolith then we could have used a foreign key and would have linked the user , courses and payments tables for relating the data. 现在,如果该系统是一个整体,那么我们可以使用外键,并可以链接用户,课程和付款表以关联数据。 Now since these 3 are different micro-services and will have its own databases, then how is the data linked together? 现在,由于这三个是不同的微服务,并且将拥有自己的数据库,那么如何将数据链接在一起? ie If I want to relate that a particular user 'X' has enrolled to 'A','B','C' courses? 即,如果我想证明某个特定的用户“ X”已经注册了“ A”,“ B”,“ C”课程?

The micro service consumer of another other micro service can store identifiers of a specific external resource and relate it logically to its own resources in its database (RDBMS or any DB type). 另一个其他微服务的微服务使用者可以存储特定外部资源的标识符,并将其逻辑关联到其数据库(RDBMS或任何DB类型)中自己的资源。
That is not a database constraint relation but if this constraint is a have to, you can of course add some check about its presence and its consistency. 那不是数据库约束关系,但是如果必须要有此约束,那么您当然可以添加一些有关其存在性和一致性的检查。

Supposing that the relation between the micro services be : 假设微服务之间的关系为:

User Management  ->  Courses
                uses

The User Management could store resource identifiers of Courses resources associated to Users. 用户管理可以存储与用户相关联的课程资源的资源标识符。
In this way you have a way to join the data of two domains in a specific way. 这样,您便可以以特定方式合并两个域的数据。
If the other dependency way is necessary ( Courses -> User Management), nothing prevents you to perform the same logical. 如果需要其他依赖方式(“课程->用户管理”),则没有什么可以阻止您执行相同的逻辑。

Not your question but important consequence of data relationship between micro service : data update of external resources have to be handled. 不是您的问题,而是微服务之间的数据关系的重要结果:必须处理外部资源的数据更新。 Pull, push ? 拉,推? With or without cache ? 有无缓存? It essentially depends on your use cases. 它基本上取决于您的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM