跳到主要內容

簡易檢索 / 詳目顯示

研究生: 吳唯禎
Wu, Wei-Jhen
論文名稱: 探索DBSP應用於提升Event Sourcing/CQRS 讀取模型效能之可行性
On the Feasibility of Using DBSP to Enhance Event Sourcing/CQRS Read Model Performance
指導教授: 廖峻鋒
Liao, Chun-Feng
許志堅
Sheu, Jyh-Jian
口試委員: 馬尚彬
Ma, Shang-Pin
學位類別: 碩士
Master
系所名稱: 傳播學院 - 數位內容碩士學位學程
Digital Content and Technologies
論文出版年: 2026
畢業學年度: 114
語文別: 中文
論文頁數: 56
中文關鍵詞: 事件溯源命令查詢職責分離DBSP增量視圖維護讀取模型
外文關鍵詞: Event Sourcing, CQRS, DBSP, Incremental View Maintenance, Read Model
相關次數: 點閱:5下載:0
分享至:
查詢本校圖書館目錄 查詢臺灣博碩士論文知識加值系統 勘誤回報
  • 隨著雲端服務規模與資料量持續成長,系統除了需要處理大量資料寫入,也必須回應日益複雜的查詢需求。事件溯源(Event Sourcing, ES)透過保存系統中發生的事件,使系統狀態具備可追溯與可重建的特性;命令查詢職責分離(Command Query Responsibility Segregation, CQRS)則進一步將寫入模型與讀取模型分離,以提升系統的擴充性與查詢彈性。然而,讀取模型通常需要隨著事件持續更新,當查詢涉及多資料表關聯、聚合運算或多層級視圖相依時,對應的更新邏輯將變得更加複雜,並可能產生重複計算、更新延遲及維護成本增加等問題。
    DBSP 是一種以資料差異為基礎的增量計算模型,能夠在輸入資料發生變化時,僅針對受影響的部分更新查詢結果,而不必重新執行完整查詢。此特性使其適合應用於複雜查詢視圖的維護。然而,DBSP 所處理的是關聯式資料的新增、刪除與修改,而 Event Sourcing 所記錄的則是具有業務意義的領域事件,因此兩者的資料表示方式上存在差異,無法直接整合。
    為解決上述問題,本研究提出事件至差異轉譯機制(Event-to-Delta Translation),將領域事件轉換為 DBSP 可處理的關聯式資料差異,並設計一套整合 Event Sourcing、CQRS 與 DBSP 的讀取模型維護架構。此架構保留 Event Sourcing 的事件紀錄與狀態重建能力,並利用 DBSP 維護由關聯、聚合及多層級視圖所構成的查詢結果,以降低複雜讀取模型的更新與維護負擔。
    本研究以 JPetStore 為案例系統,並使用 Feldera 作為 DBSP 執行引擎,針對不同資料規模、查詢複雜度與視圖相依程度進行系統評估,並與事件重播、基礎資料表查詢及傳統手動維護讀取模型等方式進行比較。實驗結果顯示,在查詢結構較為單純時,各種方式皆能提供可接受的效能;當查詢涉及較多關聯、聚合或多層級視圖相依時,DBSP 可透過增量計算與差異傳播,減少不必要的完整重算,並維持較穩定的更新與查詢效能。相較於手動撰寫各查詢視圖的更新邏輯,本研究方法亦能降低複雜讀取模型的實作與維護負擔,並提供接近傳統增量維護方式的效能表現。
    研究驗證了將 DBSP 應用於 ES/CQRS 讀取模型維護的可行性,並提出一種連結領域事件與關聯式增量計算的方法。研究結果顯示,此方法適用於以關聯式資料庫為基礎,且讀取模型具有複雜查詢、聚合運算或多層級視圖相依的應用情境,可作為未來事件驅動系統與增量計算技術整合之參考。


    As the scale of cloud services and the volume of data continue to grow, systems must not only handle large amounts of data writes but also respond to increasingly complex query requirements. Event Sourcing (ES) preserves the events that occur within a system, allowing system states to be traced and reconstructed. Command Query Responsibility Segregation (CQRS) further separates the write model from the read model to improve system scalability and query flexibility. However, read models must usually be updated continuously as events occur. When queries involve joins across multiple tables, aggregation operations, or dependencies among multiple layers of views, the corresponding update logic becomes increasingly complex and may lead to redundant computation, update latency, and higher maintenance costs.
    DBSP is an incremental computation model based on data differences. When input data changes, it updates only the affected portions of the query results instead of recomputing the entire query. This characteristic makes DBSP suitable for maintaining complex query views. However, DBSP processes insertions, deletions, and updates of relational data, whereas Event Sourcing records domain events with business semantics. Therefore, the two approaches differ in their data representations and cannot be integrated directly.
    To address this issue, this study proposes an Event-to-Delta Translation mechanism that transforms domain events into relational data deltas that can be processed by DBSP. In addition, this study designs a read-model maintenance architecture that integrates Event Sourcing, CQRS, and DBSP. The proposed architecture preserves the event-recording and state-reconstruction capabilities of Event Sourcing while using DBSP to maintain query results composed of joins, aggregations, and multi-layer view dependencies, thereby reducing the update and maintenance burden of complex read models.
    This study uses JPetStore as the case system and Feldera as the DBSP execution engine. The system is evaluated under different data scales, levels of query complexity, and degrees of view dependency, and is compared with event replay, base-table queries, and traditional manually maintained read models. The experimental results show that when query structures are relatively simple, all approaches provide acceptable performance. When queries involve more joins, aggregations, or multi-layer view dependencies, DBSP reduces unnecessary full recomputation through incremental computation and delta propagation while maintaining relatively stable update and query performance. Compared with manually implementing update logic for each query view, the proposed approach also reduces the implementation and maintenance burden of complex read models while providing performance close to that of traditional incremental maintenance approaches.
    This study verifies the feasibility of applying DBSP to ES/CQRS read-model maintenance and proposes a method for connecting domain events with relational incremental computation. The results indicate that the proposed approach is suitable for applications based on relational databases in which read models involve complex queries, aggregation operations, or multi-layer view dependencies. The findings may serve as a reference for future integration of event-driven systems and incremental computation technologies.

    誌謝 i
    摘要 ii
    Abstract iv
    目 錄 vi
    圖 目 錄 ix
    表 目 錄 x
    第一章 緒論 1
    1.1 研究背景與動機 1
    1.2 研究目的與研究問題 4
    1.3 論文貢獻 5
    1.4 研究流程 5
    第二章 背景與相關研究 7
    2.1 命令與查詢責任分離(Command Query Responsibility Segregation, CQRS) 7
    2.2 事件溯源(Event Sourcing) 8
    2.3 CQRS 與 Event Sourcing 的整合架構 10
    2.4 Read Model 與 Projection 12
    2.5 Projection 維護問題 13
    2.6 增量式視圖維護(Incremental View Maintenance) 14
    2.7 DBSP 15
    2.8 相關研究比較 15
    第三章 研究方法 17
    3.1 DBSP 的增量計算模型 17
    3.1.1 資料狀態流 18
    3.1.2 差異流(Delta Stream) 18
    3.1.3 微分與積分算子 19
    3.1.4 增量查詢模型 19
    3.1.5 Z-set 與 Abelian Group 20
    3.2 事件至差異轉譯機制(Event-to-Delta Translation) 22
    3.3 多表組合與複雜相依視圖的鏈式差異傳播 25
    3.3.1 多表 Join 與 Aggregation 傳播範例 30
    第四章 系統設計與實作 33
    4.1 系統分層架構設計 33
    4.2 系統階段 34
    4.2.1 初始化階段(Initialization Phase) 35
    4.2.2 運行階段(Runtime Phase) 36
    第五章 實驗設計與系統評估 38
    5.1 實驗設計 38
    5.1.1 Read Model 維護策略 38
    5.1.2 CQRS 查詢類型 39
    5.1.3 查詢複雜度層級 40
    5.1.4 採用案例、測試工具與負載模擬 41
    5.2 Level 1:單一實體狀態查詢重建成本分析 42
    5.2.1 實驗數據結果 42
    5.3 Level 2:單層聚合與查詢組合成本分析 44
    5.3.1 實驗數據結果 45
    5.4 Level 3:Join Dependency 查詢成本分析 47
    5.4.1 實驗數據結果 47
    5.5 小結 50
    第六章 結論 51
    6.1 研究成果總結 51
    6.2 研究貢獻 52
    6.3 研究限制 52
    6.4 未來研究方向 53
    參考文獻 54

    Betts, D., Dominguez, J., Melnik, G., Simonazzi, F., and Subramanian, M. (2013). Exploring CQRS and event sourcing: A journey into high scalability, availability, and maintainability with windows azure. Accessed: October 29, 2025.
    Budiu, M., Chajed, T., McSherry, F., Ryzhyk, L., and Tannen, V. (2024). DBSP: Incremental computation on streams and its applications to databases. SIGMOD Rec., 53(1):87–95.
    Budiu, M., Ryzhyk, L., Zellweger, G., Pfaff, B., Suresh, L., Kassing, S., Gyawali, A.,Budiu, M., Chajed, T., McSherry, F., and Tannen, V. (2025). DBSP: automatic incremental view maintenance for rich query languages. The VLDB Journal, 34(4):39.
    Casella, K., Avery, P., Reta, R., and Breuer, J. (2017). Scaling event sourcing for Netflix downloads — episode 1. https://netflixtechblog.com/scaling-event-sourcing-for-netflix-downloads-episode-1-6bc1595c5595. Netflix Tech Blog, Accessed:: May 2026.
    Chirkova, R. and Yang, J. (2012). Materialized views. Foundations and Trends in Databases, 4(4):295–405.
    Debski, A., Szczepanik, B., Malawski, M., Spahr, S., and Muthig, D. (2018). A scalable, reactive architecture for cloud applications. IEEE Software, 35(2):62–71.
    Evans, E. (2003). Domain-Driven Design: Tackling Complexity in the Heart of Software. Addison-Wesley Professional.
    Fowler, M. (2005). Event sourcing, 2005. http://martinfowler.com/eaaDev/EventSourcing.html. Accessed: January 20, 2025.
    Fuchs, L., Kahane, J., Robertson, A., and Ulam, S. (1960). Abelian Groups, volume 960. Springer.
    Green, T. J., Ives, Z. G., and Tannen, V. (2011). Reconcilable differences. Theory of Computing Systems, 49(3):460–488.
    Gupta, A. and Mumick, I. S. (1993). Maintaining views incrementally. ACM SIGMOD Record, 22(2):157–166.
    Gupta, A. and Mumick, I. S., editors (1999). Materialized Views: Techniques, Implementations, and Applications. MIT Press, Cambridge, MA.
    Kabbedijk, J., Jansen, S., and Brinkkemper, S. (2012). A case study of the variability consequences of the CQRS pattern in online business software. In Proceedings of the 17th European Conference on Pattern Languages of Programs, EuroPLoP ’12, New York, NY, USA. Association for Computing Machinery.
    Maddodi, G., Jansen, S., and Overeem, M. (2020). Aggregate architecture simulation in event-sourcing applications using layered queuing networks. In Proceedings of the ACM/SPEC International Conference on Performance Engineering, ICPE ’20, page 238–245, New York, NY, USA. Association for Computing Machinery.
    Meyer, B. (1997). Object-Oriented Software Construction. Prentice Hall, Upper Saddle River, NJ, 2nd edition.
    Nikolic, M. and Olteanu, D. (2018). Incremental view maintenance with triple lock factorization benefits. In Proceedings of the 2018 International Conference on Management of Data, SIGMOD ’18, page 365–380, New York, NY, USA. Association for Computing Machinery.
    Overeem, M., Spoor, M., and Jansen, S. (2017). The dark side of event sourcing: Managing data conversion. In 2017 IEEE 24th International Conference on Software Analysis, Evolution and Reengineering (SANER), pages 193–204.
    Overeem, M., Spoor, M., Jansen, S., and Brinkkemper, S. (2021). An empirical characterization of event sourced systems and their schema evolution—lessons from industry. Journal of Systems and Software, 178:110970.
    Vasconcellos, P. R., Bezerra, V. M., and Bianchini, C. P. (2018). Applying event sourcing in a ERP system: A case study. In 2018 XLIV Latin American Computer Conference(CLEI), pages 80–89.
    Young, G. (2010). CQRS documents. https://cqrs.wordpress.com/wp-content/uploads/2010/11/cqrs_documents.pdf. Draft document, Accessed: March 28, 2025.

    QR CODE
    :::