微服務之松耦合

參考:https://microservices.io/post/architecture/2023/03/28/microservice-architecture-essentials-loose-coupling.html

There’s actually two different types of coupling:

runtime coupling - influences availability
design-time coupling - influences development velocity

Runtime coupling and availability

Runtime coupling between services is the degree to which the availability of one service is affected by the availability of another service. Or to be more precise, it’s degree to which the availability of an operation implemented by one service is affected by the availability of another service
在這里插入圖片描述
微服務化以后導致一個請求會同步調用多個服務,請求的時常和可用性都會降低。

Reducing runtime coupling

在這里插入圖片描述
使用異步的方式可以提高請求的可用性,但是客戶端變得更復雜了,必須輪詢服務器獲得請求的狀態。
這里建議的依然是orderService調用Consumer Service,只是放到異步線程了而已。其實到底是OrderService調用ConsumerService的RPC api, 還是Consumer Service監聽OrderService的事件,要看業務邏輯而定,如果ConsumerService是OrderService的強依賴(說明OrderService domain必須要理解ConsumerService domain的概念和API),那么RPC的方式是合理的,反之,異步消息的方式更合理。
DDD總是推薦異步消息,因為一個transaction只更新一個aggregate。

Design-time coupling and development velocity

The degree of design-time coupling between a pair of software elements - classes…services - is the likelihood that they need to change together for the same reason. Design-time coupling between services in a microservice architecture is especially problematic. Let’s look at why it’s a problem and how we can minimize it.
這其實就是《整潔架構》里面所說的單一指責原則,或者說共同閉包原則,如果兩個模塊總是因為同一個原因改變,那么他們就應該屬于一個模塊,或者說,在微服務架構下,一個服務內部。
If two services are loosely coupled, then a change to one service rarely requires a change to the other service. However, if two services are tightly coupled, then a change to one service often requires a change to the other service. These types of lock step changes are expensive since it typically involves breaking API changes.

For example, let’s imagine that the Order Service and Customer Service are tightly coupled. Each time a breaking changes needs to be made to the Customer Service the sequence of steps is as follows:

Change the Customer Service to add a new major version of its API. The service must implement both the old and new version of its APIs until all clients have been migrated over.

  • Migrate the Order Service to the new API version
  • Remove the old API version from the Customer Service
  • What’s even worse, is that quite often the services are owned by different teams, which requires those teams to coordinate the changes. In other words, design-time coupling between services undermines team autonomy.

Reducing design-time coupling

Minimizing design-time coupling is one of the dark matter attractive forces that resists decomposition. There are a couple of different ways to minimize design-time coupling between services.

design subdomains to be loosely coupled - loosely coupled subdomains can be packaged as different services. Loose design-time coupling is usually achieved by each subdomain having a stable API that encapsulates its implementation.

package subdomains that are tightly coupled in the same service - If two subdomains are tightly coupled, then packaging them together in the same service will avoid design-time coupling between services.

解決方法也很簡單,就是遵循DDD的設計,子模塊(微服務)之間應該有合理的邊界,每個子模塊有相對獨立的業務邏輯,子模塊的API應該相對穩定。遵守單一指責原則,共同閉包原則。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/66147.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/66147.shtml
英文地址,請注明出處:http://en.pswp.cn/web/66147.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Django 和 Vue3 前后端分離開發筆記

Django 和 Vue3 前后端分離開發筆記 1. Django Ninja API Django Ninja 是一個用于使用 Django 和 Python 3.6 類型提示構建 API 的網絡框架。它具有以下主要特點: 簡單易懂:設計為易于使用和符合直覺,適合快速上手。快速執行:…

44_Lua迭代器

在Lua中,迭代器是一種用于遍歷集合元素的重要工具。掌握迭代器的使用方法,對于提高Lua編程的效率和代碼的可讀性具有重要意義。 1.迭代器概述 1.1 迭代器介紹 迭代器是一種設計模式,它提供了一種訪問集合元素的方法,而不需要暴露其底層結構。在Lua中,迭代器通常以一個函…

hot100_240. 搜索二維矩陣 II

hot100_240. 搜索二維矩陣 II 直接遍歷列減行增 編寫一個高效的算法來搜索 m x n 矩陣 matrix 中的一個目標值 target 。該矩陣具有以下特性: 每行的元素從左到右升序排列。 每列的元素從上到下升序排列。 示例 1: 輸入:matrix [[1,4,7,1…

一步到位Python Django部署,淺談Python Django框架

Django是一個使用Python開發的Web應用程序框架,它遵循MVC(Model-View-Controller)設計模式,旨在幫助開發人員更快、更輕松地構建和維護高質量的Web應用程序。Django提供了強大的基礎設施和工具,以便于處理復雜的業務邏…

Apache PAIMON 學習

參考:Apache PAIMON:實時數據湖技術框架及其實踐 數據湖不僅僅是一個存儲不同類數據的技術手段,更是提高數據分析效率、支持數據驅動決策、加速AI發展的基礎設施。 新一代實時數據湖技術,Apache PAIMON兼容Apache Flink、Spark等…

《計算機網絡》課后探研題書面報告_了解PPPoE協議

PPPoE協議的工作原理與應用分析 摘 要 PPPoE(Point-to-Point Protocol over Ethernet)是一種廣泛應用于寬帶接入的網絡協議,特別是在DSL(數字用戶線路)和光纖網絡中具有重要的應用價值。PPPoE結合了PPP協議的認證、加…

【MySQL學習筆記】MySQL存儲過程

存儲過程 1、基礎語法2、變量2.1 系統變量2.2 用戶自定義變量2.3 局部變量 3、if 流程控制4、參數5、case 流程控制6、循環結構6.1 while 循環6.2 repeat 循環6.3 loop 循環 7、游標8、存儲函數 存儲過程是事先經過編譯并存儲在數據庫中的一段 SQL 語句的集合,調用存…

MAC上安裝Octave

1. 當前最新版Octave是9.3版本,需要把mac os系統升級到14版本(本人之前的版本是10版本) https://wiki.octave.org/Octave_for_macOS octave的歷史版本參考此文檔:Octave for macOS (outdated) - Octavehttps://wiki.octave.org/Oc…

mysql-5.7.18保姆級詳細安裝教程

本文主要講解如何安裝mysql-5.7.18數據庫: 將綠色版安裝包mysql-5.7.18-winx64解壓后目錄中內容如下圖,該例是安裝在D盤根目錄。 在mysql安裝目錄中新建my.ini文件,文件內容及各配置項內容如下圖,需要先將配置項【skip-grant-tab…

VSCode連接Github的重重困難及解決方案!

一、背景: 我首先在github創建了一個新的項目,并自動創建了readme文件其次在vscode創建項目并寫了兩個文件在我想將vscode的項目上傳到對應的github上時,錯誤出現了 二、報錯及解決方案: 1.解決方案: 需要在git上配置用…

YOLOV8漲點技巧之混合注意力與特征金字塔網絡融合

YOLO發展歷程 自2015年YOLOv1問世以來,這一革命性的目標檢測算法經歷了一系列重大升級。以下是YOLO各版本的主要發展里程碑: 版本 發布時間 主要開發者 YOLOv1 2015年6月 Joseph Redmon YOLOv2(YOLO9000) 2016年12月 Joseph Redmon YOLOv3 2018年4月 Joseph Redmon

數據分析:非度量多維排列 NMDS (Non-metric multidimensional scaling)ANOSIM檢驗分析

禁止商業或二改轉載,僅供自學使用,侵權必究,如需截取部分內容請后臺聯系作者! 文章目錄 介紹原理步驟加載R包數據下載導入數據數據預處理計算距離矩陣ANOSIM檢驗非度量多維排列NMDS應力值(stress value)畫圖輸出系統信息介紹 非度量多維排列(Non-metric Multidimensiona…

Open FPV VTX開源之ardupilot配置

Open FPV VTX開源之ardupilot配置 1. 源由2. 配置3. 總結4. 參考資料5. 補充5.1 飛控固件版本5.2 配置Ardupilot的BF OSD5.3 OSD偏左問題 1. 源由 飛控嵌入式OSD - ardupilot配置使用ardupliot配套OSD圖片。 Choose correct font depending on Flight Controller SW. ──>…

硬件實用技巧:TPS54331DR橫杠標識識別1引腳

若該文為原創文章,轉載請注明原文出處 本文章博客地址:https://hpzwl.blog.csdn.net/article/details/145116969 長沙紅胖子Qt(長沙創微智科)博文大全:開發技術集合(包含Qt實用技術、樹莓派、三維、OpenCV…

Python庫之PyAutoGUI安裝以及使用方法

Date: 2025.01.15 20:54:01 author: lijianzhan PyAutoGUI是一個功能強大的Python庫,它允許我們用于通過編程控制鼠標和鍵盤,實現自動化任務。它可以模擬用戶的輸入操作,例如點擊、拖動、輸入文本等,適用于 GUI 自動化、測試腳本、…

Linux離線部署ELK

文章目錄 前期準備開始安裝安裝elastic search安裝logstash安裝kibana 配置ELK配置ElasticSearch配置logstash配置kibana 啟動ELK啟動命令啟動測試 設置ELK策略創建ILM策略將ILM策略與日志index關聯查看索引是否被ILM策略管理 前期準備 ELK包含三部分軟件 ElasticSearch用作搜…

Go語言的數據競爭 (Data Race) 和 競態條件 (Race Condition)

文章精選推薦 1 JetBrains Ai assistant 編程工具讓你的工作效率翻倍 2 Extra Icons:JetBrains IDE的圖標增強神器 3 IDEA插件推薦-SequenceDiagram,自動生成時序圖 4 BashSupport Pro 這個ides插件主要是用來干嘛的 ? 5 IDEA必裝的插件&…

Node.js - Express框架

1. 介紹 Express 是一個基于 Node.js 的 Web 應用程序框架,主要用于快速、簡便地構建 Web 應用程序 和 API。它是目前最流行的 Node.js Web 框架之一,具有輕量級、靈活和功能豐富的特點。 核心概念包括路由,中間件,請求與響應&a…

《光學遙感圖像中顯著目標檢測的多內容互補網絡》2021-9

一、簡介 在本文中,我們提出了一種新的多內容互補網絡 (MCCNet) 來探索 RSI-SOD 的多內容互補性。具體來說,MCCNet 基于通用的編碼器-解碼器架構,并包含一個名為 multi-content complementation module (MC…

【STM8S】STM8S之自定義短、長、連擊按鍵

本文最后修改時間:2018年10月22日 01:57 一、本節簡介 本文介紹STM8S系列如何實現按鍵的短按、長按、連擊。 二、實驗平臺 編譯軟件:IAR for STM8 1.42.2 硬件平臺:stm8s003f3p6開發板 仿真器:ST-LINK 庫函數版本&#xff1a…