# ModernWeb'19 心得 ###### tags: `microservices` - Progressive Deployment & NO Deploy(No conscious Deployment) - [投影片](https://www.slideshare.net/yftzeng/progressive-deployment-nodeploy) - 新浪微博高可用架構(RPC、service mesh) ## Microservices 優點 - 小巧、專注、自主性(高內聚,低耦合),由多個 microservices 組成應用程式 - 技術異質性 - 容易部署及擴充 - 容易替換 - ... ## Microservices 缺點 當一家公司有數百個 microservices 在運行時... - services 相依架構複雜 - services 之間的溝通成本 - 監控機制複雜 - 資料正確性及一致性 - ... ## Progressive Deployment & NO Deploy(No conscious Deployment) ### 環境建置複雜 當大型應用程式需要由上千個 microservices 運作時... - Microservices 相依性複雜,建置相關環境很麻煩。 - 即使成功啟動相依的 microservices,也很難重現正式環境的資料。 - 只有正式環境辦法有機會串接各種真實的 services ### Progressive Deployment - 既然 dev、staging 無法完整重現 prod 環境,直接 **testing in prod** 吧! - 透過 toggle / feature flag 開關新功能,控制開啟範圍及程度 - 短時間無法處理的 bug,直接從 toggle / feature flag 關閉該功能即可 - 流程變成 code commit -> code review -> progressive deployment - 使用 toggle / feature flag 這種漸進式部署方式也可稱為 **Dark Launching** ![](https://i.imgur.com/CFFdfFH.png) ### Feature Management Feature management : [LaunchDarkly](https://launchdarkly.com/) ```php $client = new LaunchDarkly\LDClient("YOUR_SDK_KEY"); $user = new LaunchDarkly\LDUser("user@test.com"); if ($client->variation("your.flag.key", $user)) { # application code to show the feature } else { # the code to run if the feature is off } ``` ## RPC(Remote Procedure Call) - 允許從 A 電腦中的應用程式呼叫 B 電腦中的子程式 - 有些程式語言內建實現同語言間的調用,EX: golang rpc package、Java RMI(Java Remote Method Invocation) - 跨語言可以採用傳統 HTTP/1.1 通訊協議,但 microservices 世界中通常是採用比 HTTP/1.1 傳輸耗用量更少的協議(HTTP/2,TPC,...) ![](https://i.imgur.com/x2bjpOw.png) ## RPC Framework ![](https://i.imgur.com/eMSOBSi.jpg) cross-language RPC framework: - [gRPC(Google)](https://www.grpc.io/) - [Apache Thrift(Facebook)](https://thrift.apache.org/) - [Motan(新浪微博)](https://github.com/weibocom/motan) - [Dubbo(阿里巴巴)](http://dubbo.I/O/) ## Service Mesh - Handling service-to-service communication - circuit breaker & service discovery - control plane : 流量管理、網格測試,確保服務之間的通訊安全... - 類似的服務:[Istio(K8S)](https://istio.io/)、[AWS App Mesh](https://aws.amazon.com/tw/app-mesh/)、[Google Cloud Service Mesh](https://cloud.google.com/service-mesh/?hl=zh-tw) ![](https://i.imgur.com/dIlVYMR.png) ![](https://i.imgur.com/cAE2PR4.png) note: - circuit breaker: 連結到每個 service 前會有一層類似斷路器機制,當 service fail 次數過多時,斷路器會阻斷任何通往該 service 請求(只允許部分 protected call)並發出 alert - service discovery: 定位 service instance、healthy check、偵測 server loading 及分配 request。(AWS Elastic Load Balancer) ## Refrences - [Pattern: Service Mesh](https://philcalcado.com/2017/08/03/pattern_service_mesh.html) - [Service Discovery in a Microservices Architecture](https://www.nginx.com/blog/service-discovery-in-a-microservices-architecture/) - [CircuitBreaker](https://martinfowler.com/bliki/CircuitBreaker.html) - [微服務基礎建設](https://columns.chicken-house.net/2016/09/15/microservice-case-study-01/)