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

Event Sourcing and Azure Cosmos DB using Sekiban Framework

Tomohisa Takaoka
April 17, 2024
18

Event Sourcing and Azure Cosmos DB using Sekiban Framework

Coffee with Azure Cosmos DB #27

https://www.youtube.com/watch?v=QAwZsBVgkv0

In this talk, I will explain this topic.
- What is Sekiban?
- How Sekiban and Azure Cosmos DB improve Appication development?
- Demo

Tomohisa Takaoka

April 17, 2024
Tweet

More Decks by Tomohisa Takaoka

Transcript

  1. Coffee with Azure Cosmos DB #27 Event Sourcing and Azure

    Cosmos DB using Sekiban Framework Please leave your questions and feedback in the YouTube comments.
  2. Who am I. Tomohisa Takaoka VP of Tech @ J-Tech

    Creations, Inc. CTO of J-Tech Japan, Inc. Developer of the Sekiban - Event Sourcing and CQRS Framework. Located at Long Beach CA, USA. • X : @tomohisa • Github : @tomohisa • Linkedin : tomohisatakaoka Designing my own 3D printed trackball as Hobby.
  3. Agenda. Event Sourcing + Azure Cosmos DB + Sekiban 1.

    What is Sekiban? 2. How Sekiban and Azure Cosmos DB improve Appication development? 3. Demo
  4. What is Sekiban? Sekiban is • Event Sourcing and CQRS

    Application Development Framework • ASP .NET Core , Modern C# 7, 8 + • Open Sourced in December 2023 with Apache 2.0 ◦ No paid version as for now. • Multiple Event Store Storage Option Available ◦ Azure Cosmos DB (No SQL) ◦ AWS Dynamo DB ◦ PostgreSQL (Azure Cosmos DB Postgres Compatible) • Sponsored by Japan Technical Software
  5. What is Sekiban? - What is Event Sourcing? Event Sourcing

    is... Instead of storing just the current state of the data in a domain, use an append-only store to record the full series of actions taken on that data. The store acts as the system of record and can be used to materialize the domain objects. This can simplify tasks in complex domains, by avoiding the need to synchronize the data model and the business domain, while improving performance, scalability, and responsiveness. It can also provide consistency for transactional data, and maintain full audit trails and history that can enable compensating actions. https://learn.microsoft.com/en-us/azure/architecture/patterns/event-sourcing
  6. What is Sekiban? - What is Event Sourcing? 1. e4

    c5 2. Nf3 Nc6 3. Bb5 e6 4. O-O Nge7 5. Re1 a6 6. Bf1 d5 7. exd5 Nxd5 8. d4 Nf6 9. Be3 Ng4 10. Bg5 f6 11. Bf4 cxd4 12. h3 Nh6 13. Bxh6 gxh6 14. Nbd2 b5 15. a4 Rb8 16. axb5 axb5 17. Nb3 Bb4 18. Nfxd4 Nxd4 19. Qh5+ Kf8 20. Red1 e5 21. c3 Bd6 22. cxd4 e4 23. Ra7 Rb7 24. Rxb7 Bxb7 25. Nc5 Bd5 26. Bxb5 Qa8 27. Nd7+ Ke7 28. Qxh6 Bc6 29. Qg7+ 1-0 Chess Notation Event Sourcing Chess Position Diagram State Sourcing https://www.chess.com/events/2023-fide-chess-world-cup/08-04/Caruana_Fabiano-Abasov_Nijat
  7. What is Sekiban? - State Sourcing can easily lost data.

    - Coffee 1 Add 1 Coffee - Coffee 1 - Orange 1 - Coffee 1 - Orange 1 - Tea 1 - Coffee 1 - Tea 1 Add 1 Orange Add 1 Tea Remove 1 Orange 1. Usually state removes records when its deleted. 2. If we save history for every records, it is so many data and hard to find reason for the deletion. (Not saved reason for the event)
  8. What is Sekiban? - Event Sourcing save events with Why

    that is happened. Add 1 Coffee Add 1 Orange Add 1 Tea Remove 1 Orange 1 Coffee Added 1 Coffee Added 1 Orange Added 1 Coffee Added 1 Orange Added 1 Tea Added 1 Coffee Added 1 Orange Added 1 Tea Added 1 Orange Removed 1. Can use removed data for the data analysis or adding features. 2. Can track histories of the data - audit and debug capabilities.
  9. Event Sourcing + Azure Cosmos DB + Sekiban How Sekiban

    and Cosmos DB improve development?
  10. How Sekiban and Cosmos DB improve development? Azure Cosmos DB

    is great database for the Event Sourcing and CQRS. https://devblogs.microsoft.com/cosmosdb/tag/design-patterns/
  11. How Sekiban and Cosmos DB improve development? It’s not easy

    to make all features for each projects. • Replay Aggregate Events to get State • Snapshots • Optimistic Version Check • Single Thread for each aggregate. • Multiple Aggregate Projection • Event Versions • Multiple Database Support • Testing Framework • Tenant Projections • Web API Integration • Multiple Projections Snapshot • Auto Generate Snapshot in background process. • Event Subscription... Etc...
  12. How Sekiban and Cosmos DB improve development? Sekiban has all

    those feature, Developer don’t need to implement and test each feature, just need to learn how to use it. • Replay Aggregate Events to get State • Snapshots • Optimistic Version Check • Single Thread for each aggregate. • Multiple Aggregate Projection • Event Versions • Multiple Database Support • Testing Framework • Tenant Projections • Web API Integration • Multiple Projections Snapshot • Auto Generate Snapshot in background process. • Event Subscription... Etc...
  13. How Sekiban and Cosmos DB improve development? Azure Cosmos DB

    has power to handle Sekiban’s capability and help us make great applications. • Multi-Region Scalability and Huge Data Availability. ◦ Azure Cosmos DB takes care of the all distributional capabilities. ▪ Partitioning - logical partitions and physical partitions. ▪ Replication ▪ Indexing ▪ Caching ▪ Global Distribution etc...
  14. How Sekiban and Cosmos DB improve development? Azure Cosmos DB

    has power to handle Sekiban’s capability and help us make great applications. • JSON Flexibility ◦ Capable of storing polymorphic data easily. [JsonDerivedType] in C#
  15. How Sekiban and Cosmos DB improve development? Azure Cosmos DB

    has power to handle Sekiban’s capability and help us make great applications. • Hierarchical Partition Key. ◦ Sekiban use Hierarchical Partition Key. ▪ Multi Tenant Data ▪ Aggregate Type ▪ Partition Id for each Aggregate.
  16. How Sekiban and Cosmos DB improve development? Sekiban is currently

    focus Small and Medium Enterprise application, we aim to develop more scalablility feature. • Materialized view support. ◦ Even now, developer can build materialized view from event using change feed from Azure Cosmos DB. • More microservices or functions support. ◦ Proxy and shading support for Command and Query side etc...
  17. Demo 1. Using Azure Cosmos DB Instance to develop •

    Create Containers (events, items) in Azure. • Put connection strings and set Database Name on appSettings.json (or secret) • Define Domain Code with Sekiban • WebAPI project can set for infrastructure and API connecting to Domain.
  18. Demo 2. Using Aspire to have development container locally. •

    Use Aspire Starter template • easily add Azure Cosmos DB Containers, Postgres Containers. • Inject connection string to the WebAPI project. • Run and test application ※NOTE※ Azure Cosmos DB Container launch slow and before finish initialization, it returns error. You might choose to provide container with docker compose and keep it up while you are in development.
  19. Conclusion. • Using Sekiban and Azure Cosmos DB, application developer

    can use power of Azure Cosmos DB with easily develop complex business model using Event Sourcing. • Event Sourcing is a pattern, that needs some understanding and knowledge to getting used to, still very powerful for data usage and audit capabilities. • It will be great tool in your toolbox to easily develop event sourcing application, using framework like Sekiban.
  20. Conclusion Give us feedback at X @tomohisa , @sekibandev Sekiban

    Landing page https://www.sekiban.dev Sekiban GitHub https://github.com/J-Tech-Japan/Sekiban Sekiban Developer Tech Blog in English (new) https://tomohisa.hashnode.dev #NextbeatTechBar