亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

java - 微服務(wù)架構(gòu)下跨服務(wù)查詢的聚合有什么好的方案?
大家講道理
大家講道理 2017-04-18 10:55:55
0
4
2251

微服務(wù)架構(gòu)中,每個服務(wù)都有自己的獨立數(shù)據(jù)庫。
然而現(xiàn)在有個需求,需要生成一張實時的報表,該報表包含兩個服務(wù)的數(shù)據(jù)。
如服務(wù)A,服務(wù)B。B中僅包含A的主鍵id作為關(guān)聯(lián)。
而此報表的搜索條件包含A服務(wù)實體中的字段也包含B服務(wù)實體中的字段。

現(xiàn)有方案
1、如果搜索條件中包含A的條件,則先去服務(wù)A中搜索,得到所有結(jié)果的主鍵,在服務(wù)B中使用where A.id IN (ids) 再次查詢
想法:當(dāng)A.id數(shù)量龐大時,這個查詢極其緩慢! 而A.id數(shù)量龐大的情況很多

2、使用搜索引擎

想法:感覺殺雞用牛刀

請教各位大牛有更好的方案嗎

大家講道理
大家講道理

光陰似箭催人老,日月如移越少年。

reply all(4)
迷茫

Laxative

If it is online business data (OLTP), then option 1 is the standard practice of microservices. If such related queries need to be done frequently online, it means that the coupling of the two services (and their two libraries) is very serious, so why bother to separate them in the first place?

If it is an analysis report, it falls under the OLAP category. Solution 2 is indeed a desirable solution. If you feel that using a search engine is overkill, you might as well try doing various report analysis operations on the slave database. For example, the online A database and B database are synchronized to a read-only database in real time, and then in the read-only database JOIN is done in one go.

Peter_Zhu

One of the design principles of microservices is to separate services that are not related to the business into separate services. There is overlap between your businesses.

洪濤

In fact, this kind of problem is very common in microservices. For example, you need to query the order through some information on the product. The order and the product belong to two microservices respectively. In addition to your own two solutions, there are also

  1. Put the data aggregation into the data warehouse, aggregate the data in A and B in real time into another database (not necessarily mysql, it can also be Hbase), and pull the data from the report from the data warehouse

  2. When designing the table, it is appropriate to redundant some fields. As you said, some fields of A can be predictably redundant on B

Method 1 has a very fatal shortcoming. Once paging is involved, this method is definitely not feasible. Which solution to adopt depends on the order of magnitude corresponding to your data. If the corresponding amount of data is not very large, you can Using method 1, if the speed is slow, you can open a few more threads to retrieve the corresponding data in batches (if there are too many IDs, pull them in batches, and batch query are effective solutions that can reduce timeouts and time); if the amount of data is large , it is recommended to use a data warehouse. The main benefit of using a data warehouse is that it will not put pressure on the main database, because the generation of aggregate tables can be obtained through Binlog; because the report still belongs to the category of offline data, if it really needs to be like an order The query is so real-time, very efficient and accompanied by the status of the table, and there are so many search conditions, then the search engine is a good choice
So, you can use method 1 and method 3 according to the actual situation

黃舟

Requirements such as generating reports should not be placed in business database systems. You can make a set of otter aggregation libraries on the backend to synchronize data from multiple services in real time. Then you can play whatever you want in this aggregation library.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template