Cosmos DB 架構

開發 Azure Storage

Shahzad Mian

Content developer, DataCamp

Azure Cosmos DB

Azure_Cosmos_DB.svg.png

開發 Azure Storage

問題點

Cosmos DB problem

開發 Azure Storage

什麼是 Cosmos DB?

 

CosmosDB

  • 多模型、全球分散的 NoSQL 資料庫。
  • NoSQL:彈性、如資料夾般的儲存。
  • 支援多種 API 與資料型態。
  • 就像彈性的餐廳菜單——選你要的 API 口味:
    • SQL(Core)用於 JSON 文件。
    • MongoDB 給 Mongo 開發者。
    • Cassandra 適合寬欄資料。
    • Gremlin 用於圖形關係。
    • Table API 做鍵值儲存。
開發 Azure Storage

給開發者的 Cosmos DB

  • 以開發者為中心設計。
  • 自動索引,免架構管理。
  • 查詢快速。
  • 五種一致性層級:從 Strong 到 Eventual。
  • 在效能與一致性間取捨。
    • Strong:所有人即時得到相同結果。
    • Eventual:之後會逐步一致。

 

Strong and eventual consistency

開發 Azure Storage

擴充與輸送量(RU/s)

Provisioned mode

  • 每秒要求單位(RU/s)= Cosmos DB 的效能「貨幣」。
  • 每次讀、寫或查詢都會消耗 RU/s。
  • 可選固定佈建或自動調整。
開發 Azure Storage

擴充與輸送量(RU/s)

Scaling

  • 每秒要求單位(RU/s)= Cosmos DB 的效能「貨幣」。
  • 每次讀、寫或查詢都會消耗 RU/s。
  • 可選固定佈建或自動調整。
  • 自動調整會隨需求自動變動。
開發 Azure Storage

彈性擴充與分割區

  • Cosmos DB 透過分割區來擴充。
  • 每個容器都使用分割區鍵。
  • 鍵會把相關資料分在一起。
  • 例:Cipher Coffee 的訂單用 /customerId
  • /customerId 為分割區鍵時,同一客戶的訂單在同一分割區。
  • 資料成長時查詢仍快。
  • 「熱點分割區」:負載不均拖慢效能。

Elastic scale and partioning

開發 Azure Storage

全球散佈

  • 輕鬆將資料複寫到任一 Azure 區域。
  • 勾選核取方塊即可,無需繁瑣設定。
  • 若某區域故障,流量會自動改道。
  • 無停機、無資料遺失。
  • 就像備用咖啡館能即時接手服務。

Global distribution

開發 Azure Storage

監控與成本最佳化

  • 在 Azure 入口網站追蹤效能。
  • 檢視 RU/s、延遲、請求費用等指標。
  • 就像車用儀表板:看速度與油耗。
  • Cipher Coffee 的工程師分析了這些指標。
  • 透過動態調整輸送量降成本。

Monitoring

開發 Azure Storage

一起來練習吧!

開發 Azure Storage

Preparing Video For Download...