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

Asynchronous events

Getting data via service endpoints synchronously may become overwhelming for services that maintain a widely used database, like the users database. Therefore, it is recommended for services to maintain a read-only cache for such databases and keep it up to date asynchronously using events, as shown in the following diagram:

For example, instead of looking up the address or order count using service endpoints synchronously, services such as User Service and Orders Service can publish the events of interest on a message queue in order of occurrence. The User Service can then receive the orders event from the Orders Service via the Message Broker and update its database with the orders count or cache it. Similarly, the Orders Service can receive any address update event from the User Service, keep the address up to date for the user within its cache, and refer to it as and when required to generate orders for users.

Microservices should always have an isolated database, but it is not recommended to create separate services to isolate immutable databases such as geolocations, PIN codes, domain knowledge, and so on. Since these database do not change that often, it is fair enough to share and cache these across microservices.
主站蜘蛛池模板: 英吉沙县| 博客| 新巴尔虎右旗| 大连市| 浙江省| 庆城县| 罗田县| 平阳县| 泾阳县| 光泽县| 吴江市| 定州市| 香河县| 观塘区| 永丰县| 肃宁县| 沅陵县| 水富县| 沾化县| 乌鲁木齐县| 鄂伦春自治旗| 手游| 上饶县| 民丰县| 卢氏县| 商河县| 沂源县| 凤阳县| 德钦县| 灯塔市| 金寨县| 樟树市| 灌阳县| 南木林县| 韶关市| 南丹县| 儋州市| 旬邑县| 铁力市| 广安市| 镇赉县|