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

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.
主站蜘蛛池模板: 贵南县| 泸溪县| 浙江省| 五河县| 策勒县| 祁阳县| 四平市| 峡江县| 武鸣县| 温泉县| 东乌| 铁岭市| 英山县| 洞口县| 福泉市| 沛县| 南陵县| 乐清市| 泰兴市| 通州区| 江孜县| 潼南县| 莒南县| 德清县| 虎林市| 九龙城区| 左贡县| 淮阳县| 邯郸市| 温泉县| 乌苏市| 广东省| 抚顺市| 盐源县| 怀宁县| 翁源县| 呼图壁县| 开鲁县| 荆门市| 洛浦县| 云霄县|