Slide 1

Slide 1 text

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.

Slide 2

Slide 2 text

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.

Slide 3

Slide 3 text

Agenda. Event Sourcing + Azure Cosmos DB + Sekiban 1. What is Sekiban? 2. How Sekiban and Azure Cosmos DB improve Appication development? 3. Demo

Slide 4

Slide 4 text

Event Sourcing + Azure Cosmos DB + Sekiban What is Sekiban?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

What is Sekiban?

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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)

Slide 10

Slide 10 text

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.

Slide 11

Slide 11 text

Event Sourcing + Azure Cosmos DB + Sekiban How Sekiban and Cosmos DB improve development?

Slide 12

Slide 12 text

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/

Slide 13

Slide 13 text

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...

Slide 14

Slide 14 text

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...

Slide 15

Slide 15 text

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...

Slide 16

Slide 16 text

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#

Slide 17

Slide 17 text

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.

Slide 18

Slide 18 text

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...

Slide 19

Slide 19 text

Event Sourcing + Azure Cosmos DB + Sekiban Demo

Slide 20

Slide 20 text

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.

Slide 21

Slide 21 text

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.

Slide 22

Slide 22 text

Event Sourcing + Azure Cosmos DB + Sekiban Conclusion

Slide 23

Slide 23 text

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.

Slide 24

Slide 24 text

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