什麼是微服務、微服務架構

本文基於微服務提出者馬丁.福勒(Martin Fowler) 的微服務論文

一、什麼是微服務

While there is no precise definition of this architectural style, there are certain common characteristics around organization around business capability, automated deployment, intelligence in the endpoints, and decentralized control of languages and data.
對於微服務,業界並沒有一個統一的、明確的定義

簡單的說,微服務是指將一個單體的應用程序拆分成一組小型服務;微服務化的核心就是將傳統的一站式應用,根據業務拆分成一個一個的服務,徹底地去耦合,每一個微服務提供單個業務功能的服務,一個服務做一件事,從技術角度看就是一種小而獨立的處理過程,類似進程概念,能夠自行單獨啓動或銷燬,擁有自己獨立的數據庫。

從狹義上看,每一個微型服務對應我們IDEA中構建的一個個Module

二、什麼是微服務架構

In short, the microservice architectural style 1 is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery.
總之,微服務架構風格是一種將一個單體應用拆分成一組小型服務的方法,每個服務運行在自己獨立的進程中,並與輕量級的通信機制(通常是HTTP resource API)通信。這些服務是圍繞業務能力進行構建的,可以通過完全自動化的機器進行部署。

  • 微服務架構即是基於微服務理念的架構風格(SpringCloud是分佈式微服務架構下的一站式解決方案,是各個微服務架構落地技術的集合體,俗稱微服務全家桶)

  • 單體應用到微服務的演進:

Enterprise Applications are often built in three main parts: a client-side user interface (consisting of HTML pages and javascript running in a browser on the user’s machine) a database (consisting of many tables inserted into a common, and usually relational, database management system), and a server-side application.
企業應用服務通常由這三個主要部分組成:客戶端用戶界面(由運行在用戶機器的瀏覽器上的HTML頁面和JS腳本組成)、數據庫(通常由一種公共的關係型數據庫管理系統的衆多表組成)和服務端應用程序。

The server-side application will handle HTTP requests, execute domain logic, retrieve and update data from the database, and select and populate HTML views to be sent to the browser.
服務器端應用程序將處理HTTP請求,執行業務邏輯,從數據庫檢索和更新數據,並選擇並填充要發送給瀏覽器的HTML視圖。

This server-side application is a monolith - a single logical executable2.
這種服務器端應用程序是一個大型整體性的-一個邏輯單一的可執行文件。

這句是重點了:

Any changes to the system involve building and deploying a new version of the server-side application.
對系統的任何更改都涉及構建和部署一個新版本的服務器端應用程序。

隨着時間的推移,系統變得越來越龐大且複雜,對系統的一小部分做出的更改都需要重建並部署整個系統,這使得開發和維護系統的成本變得高昂。
這些缺陷催生了微服務架構風格:將應用程序構建爲微服務組件。這種微服務組件包括了這些特性:

  1. 服務是獨立部署的和可獨立擴展的;
  2. 服務有穩定的模塊邊界,甚至允許使用不同的語言來編寫不同的服務;
  3. 不同的服務可以使用不同的數據庫,可以由不同的團隊來管理。

Martin Fowler的論文中有這樣一張圖片,很好的描述了單體應用和微服務的區別:
在這裏插入圖片描述


  1. The term “microservice” was discussed at a workshop of software architects near Venice in May, 2011 to describe what the participants saw as a common architectural style that many of them had been recently exploring. In May 2012, the same group decided on “microservices” as the most appropriate name. James presented some of these ideas as a case study in March 2012 at 33rd Degree in Krakow in Microservices - Java, the Unix Way as did Fred George about the same time. Adrian Cockcroft at Netflix, describing this approach as “fine grained SOA” was pioneering the style at web scale as were many of the others mentioned in this article - Joe Walnes, Daniel Terhorst-North, Evan Botcher and Graham Tackley. ↩︎

  2. Unix社區使用Monolith一詞已有一段時間了。它出現在The Art of Unix Programming來描述那些變得太大的系統 ↩︎

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章