Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DDD 讀書會 - Ch5. CQRS

DDD 讀書會 - Ch5. CQRS

對 CQRS 進行簡單的介紹

希望讓大家可以在讀 [複雜軟件設計之道] 第五章的時後可以更容易的理解

Layered Architecture, CQRS

river0825

May 20, 2021

Transcript

23 slides
  1. River Backend Engineer in XRSPACE Newbie to golang Volunteer in

    the DDDTW community. 在家當了兩天的水電工 About Me
  2. Agenda • Why CQRS • 什麼是 CQRS Patterns • 實踐

    CQRS 的幾種方式 • 如何 Scaling Read & Write • 總結
  3. How to query between BCs Order Id: 33991 restaurant: 大買家

    Kitchen Id: 33991 Status: PREPARED Delivery Id: 45-44-44 OrderId: 33991 Status: ENROUTE Eta: 6:25pm Accounting Id: 33-991 OrderId: 33991 Status: PAID <<Frontend>> Order Status findOrder(orderId)
  4. How to query between BCs Order Id: 33991 restaurant: 大買家

    Kitchen Id: 33991 Status: PREPARED Delivery Id: 45-44-44 OrderId: 33991 Status: ENROUTE Eta: 6:25pm Accounting Id: 33-991 OrderId: 33991 Status: PAID findOrder(orderId) Find Order
  5. The Misconceptions of CQRS • CQRS is Hard • CQRS

    is Eventually Consistent • Your Models Need to be Event Sourced • Commands Should be Asynchronous • CQRS Only Works with Messaging System • You Need to Use Domain Event with CQRS
  6. 幾種 Scaling 的方式 - Scaling the Read Side: - An

    Eventually Consistent Read Model - Use the Read Model to Consolidate Many Bounded Contexts - Using a Reporting Database or a Caching Layer - Scaling the Write Side: - Using Asynchronous Commands
  7. CQRS 總結 • CQRS 不是一種可以適用於所有系統內的模式 • 當 domain object 無法符合複雜的

    UI 顯示需求,而且不想讓 domain object 妥 協時。請使用 CQRS • 專注於 aggregate 在寫入及業務邏輯的行為,而不是一些報表的功能 • View models 就是為了 Reporting 的需要而量身打造的,它可以乎略 domain model 並且直接存取資料庫以達到較好的效能 • CQRS 是一個簡單的 pattern, 是 SRP (Single Responsibility Principle) 的在 model 層級上的實踐
  8. CQRS 總結 • CQRS 常常被認為是 messaging, eventual consistency, domain events,

    event sourcing 的關係緊密,但其實不然。這些模式可以配合的很好,但並不是必要的 • CQRS 可以加大在讀取方面的能力,但也伴隨著後果 • 當你有一個高度合作並且會多次寫入同一組 Aggregate,可以試一下非同步的 command process • 使用 非同步的 write model 及最終一致性的 read model 是有代價的,請確保商 業模式是可以接受的。並要從用戶體驗的角度來考慮整個流程 • CQRS 可以讓你的系統很容易的擴展
  9. Reference • Patterns, Principles, and Practices of Domain-Driven Design -

    Chapter 24 • Microservice Patterns - Chapter 7

More Decks by river0825

Other Decks in Programming