Cross-service references in DB

mersadk

I am building service oriented system, with multiple services and application. Current I am not sure how to handle DB references between resources from multiple services and databases.

For example, I have a users service, where I can define all users and their roles. Next I have, products service, where I can define my products, their prices and other information.

I also have invoicing service, which is used to create invoices. This service will use information from previous two services. It will link products and users to invoice. Now I am not sure what is the best approach for this?

Do I just save product ID and user ID that it got from other two services, without any referential integrity?

If I do this, then I will have problem when generating reports, because at time of generation I will need to send a lot of requests to products service, to get names and prices of product in invoice. Same for users.

Do I create some table products in my invoicing application, and store name and price of product at the moment of invoice creation?

If I go with this approach, then in case that price or name of product changes, I will have inconsistent data across my applications?

Is there some well-known pattern for this kind of problem, that is what is the best solution.

ImadT

Cross-service references in DB is a common challenge for Data integrity between multiple web services, And specially when we are talking about Real time access.

There is two approaches for your case :

1- Databases Replication across your servers

I suppose that you have each application hosted on a separate server, So i can name your servers as Users_server, Products_server and Invoices_Server.

In your example, your Invoice web service need to grab data from Users & Products Servers, in this case you can create a Replication of your Users Database and Products Database on your Invoices_server.

This way you can run your Join queries on the same server and get data from multiple databases.

Query example :

SELECT *
FROM UsersDB.User u
JOIN InvoicesDB.Invoice i ON u.Id = i.ClientId 

2- Main Database Replication

1st step you have to replicate all your databases into one main server we can call it Base_server, which basically contain all your databases from all your services.

Then you can build an internal web service for your application to provide needed data in just "One Call", this answer your question about generating reports.

In other words, you will make one call to the mane Base service instead of making 2 or 3 calls to your separate services.

Note: As a Backend developer we use this organization as a best practice while building a large bundle based application, we create a base bundle and then create service_bundle which rely on the base bundle.

If your services are already live, we may need more details about the technology and databases type you using in order to give you a more accurate solution.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Consume WCF service in Xamarin Cross Platform Application

来自分类Dev

不能再访问Swisscom DB Service

来自分类Dev

超时时间已到。-在ServiceStack Service中使用Db

来自分类Dev

Azure App Service(Mobile)上的db上下文失败

来自分类Dev

如何从 Service Fabric Mesh 连接到 Azure Cosmos DB

来自分类Dev

OLE DB或ODBC错误:用户'NT AUTHORITY \ NETWORK SERVICE登录失败

来自分类Dev

如何阻止从Kubernates中的其他命名空间到DB Pod&Service(DNS)的流量?

来自分类Dev

Storing rvalue references: should this work?

来自分类Dev

Structured References: Absolute and Relative addressing

来自分类Dev

Cross platform Elixir deployment

来自分类Dev

CROSS/OUTER APPLY in MySQL

来自分类Dev

Dynamic Cross Apply Values

来自分类Dev

Cross compiling Qt 5

来自分类Dev

UNION与CROSS APPLY的表现

来自分类Dev

Cross Process Memory Barrier

来自分类Dev

Cross platform Sequential GUID

来自分类Dev

使用CROSS JOIN

来自分类Dev

使用CROSS JOIN

来自分类Dev

什么是sklearn.cross_validation.cross_val_score

来自分类Dev

MachineLearning cross_val_score与cross_val_predict

来自分类Dev

Xamarin Cross Platform上的BLE

来自分类Dev

在dplyr的cross()中引用列名

来自分类Dev

dplyr“加权总和”和cross()

来自分类Dev

雷+ cross_val_score

来自分类Dev

CROSS JOIN无法正常运作

来自分类Dev

Xamarin Cross Platform禁用IOS

来自分类Dev

无法导入 cross_validation

来自分类Dev

Cannot get OpenCV to compile because of undefined references?

来自分类Dev

glfw3 compiling undefined references