本文件分享了微服務架構的導入經驗,強調了相較於單體式架構的優勢,包括擴展性、故障隔離和資源利用率的提升。通過使用 Windows 容器技術進行系統佈署,實現了更簡化和高效的服務管理,並提出了將傳統 ASP.NET 系統遷移到微服務架構的具體步驟及實際案例。文中也探討了微服務架構在人才發展管理系統中的應用,闡述了建立良好服務邊界和 API 定義的重要性。
Monolithic application approachMicroservices application approach
• A microservice application
separates functionality into
separate smaller services.
• Scales out by deploying each
service independently creating
instances of these services across
servers/VMs/containers
• A monolithic application has most
of its functionality within a few
processes that are componentized
with libraries.
• Scales by cloning the app on
multiple servers/VMs/Containers
App 1 App 2App 1
6.
• Single monolithicdatabase
• Tiers of specific technologies
State in Monolithic approach State in Microservices approach
• Graph of interconnected microservices
• State typically scoped to the microservice
• Variety of technologies used
• Remote Storage for cold data
stateless services
with
separate stores
stateful
services
stateless
presentation
services
stateless
services
#9 Autonomous Service / 符合單一責任原則 (single responsibility principal)
微服務要多 “小” 才夠小?
夠小,而無法再小
服務與團隊是否能夠搭配? EX: codebase 過大,無法由多數個小團隊管理,就需要分解他
服務越小,微服務的優點與缺點都會被放大
優點: (同上)
缺點: 部屬上的困難,追蹤除厝的困難 > 要借重基礎建設自動化,來簡化管理任務 (container)
Contain code plus “state”
Interact with other microservices over well defined interfaces
Remains consistent and available in the presence of failures
#10 Build and operate a service at scale
Improved resource utilization to reduce cost
Fault Isolation
Small Focused Teams
Continuous Innovation
Can be written in any language and framework (and platform / OS)
#11 Split to several independent services
Define interfaces (API) and libraries (SDK) with backward compatibility
Scale application in 3-dimations:
Functional decomposition
Scale by cloning
Scale by splitting similar things
Deploy service(s) in Containers
Using Immutable Servers (No OS configuration, updating, remote administration was needed)
Using Orchestration to management containers (networking, load balance and upgrade for each micro-services)
Like “貨櫃“, 所有貨物出廠就早就裝好,貨運公司只負責貨櫃的搬運,追蹤,管理。運送過程完全不會更動任何貨櫃內的東西。開發者 = 工廠,IT就像貨運公司,把服務送達 User 身上。
Ex: 手機的 OS / APP 有升級,不需要更新軟體,只要丟掉舊手機,換台新的(已安裝新軟體)打開就可以用了。> 當然沒人這麼笨,因為更新 APP / OS 比較便宜。
> 但是,如果你一次有上百台 SERVER 要更新 (更新很麻煩,又很慢),同時替換機器又很便宜 (虛擬的嘛! 下幾行指令就好),更換速度又快又簡單(如果只要幾秒鐘) 的話> 而且所有 OS / APP 的替換程序通通一樣,則丟掉換新的會是更好的做法
> 因此,找一套合適的管理工具,來管理這樣的 VM / CONTAINER 是理想的做法
#14 趨勢:
不可更改的 OS
單一功能的 OS
UniKernel
OS 只是為了執行 Container Engine
…
#22 BUILD > (SHIP) > RUN process
ASP.NET > Publish > Build Docker Image > RUN
RUN 2 instances, Show volume (change logo), show result
BUILD new version, re-deploy & keep volume
#26 將教材相關的服務,切割成 Course Server
將大型後端作業的處理,切割成 JOB Server
#38 BUILD > (SHIP) > RUN process
ASP.NET > Publish > Build Docker Image > RUN
RUN 2 instances, Show volume (change logo), show result
BUILD new version, re-deploy & keep volume