官术网_书友最值得收藏!

Combining data

In a monolithic environment, combining data is easy; you need to just join two tables to create the required view. In microservices, datasets are distributed across microservices and combining them requires moving the data across microservices, which may involve significant network and storage overhead. It also becomes challenging to keep the combined data up to date. There are multiple ways to solve the problem of combining data or joins in a microservices architecture based on the scope of the request.

For example, if you wish to build an order summary page for a particular user, you need to get only that user's data from the User Service and all the orders for that user from the Orders Service. These can be obtained independently and joined at the requesting service level to generate the order summary, as shown in the preceding diagram. These kinds of join work well for 1:N joins.

Real-time joins work well for limited datasets, but it is expensive to combine data in real time for each request. Imagine tens of thousands of similar requests hitting the Order Summary Service every second. In such scenarios, services should instead keep denormalized (https://en.wikipedia.org/wiki/Denormalization) combined data in a cache that is kept up to date using the events generated by the source services. The service can then respond to the requests by just looking up this denormalized data cache in real time. This approach scales well at the expense of data being near real time. The data in the cache might be off by the time source service generates the event and target service picks it up and makes changes to its cache.

For example, as shown in the preceding diagram, an Interest Service may receive user interests via its API endpoint, but it may need the user and order details from the User and Orders services respectively. Instead of directly looking up details for each user interest, the Interest Service may subscribe to the events generated by the user and orders service and internally keep a denormalized cache view of interest data that is readily available with all the required details of users and orders.

主站蜘蛛池模板: 绵阳市| 龙陵县| 五华县| 镇远县| 甘肃省| 利辛县| 宝清县| 台北市| 博兴县| 泾川县| 泰和县| 大足县| 休宁县| 钟山县| 弥勒县| 霍城县| 铜陵市| 徐闻县| 新建县| 离岛区| 宣汉县| 三河市| 新建县| 厦门市| 阿坝| 当涂县| 广昌县| 年辖:市辖区| 遵义县| 屯昌县| 神农架林区| 白河县| 班玛县| 阜平县| 綦江县| 潮安县| 枣阳市| 平邑县| 泰安市| 石棉县| 咸宁市|