CQRS innovations (English version)

53
6/20/22 www.ExigenServices.com CQRS - Innovative solution for problems of modern enterprise architectures. Andrey Lomakin ([email protected]) Artem Orobets ([email protected])

Transcript of CQRS innovations (English version)

Page 1: CQRS innovations (English version)

April 12, 2023 www.ExigenServices.com

CQRS - Innovative solution for problems of modern enterprise architectures.

Andrey Lomakin ([email protected]) Artem Orobets ([email protected])

Page 2: CQRS innovations (English version)

2 www.ExigenServices.com

Table of content

1. Why CQRS ?

a) Milestones of enterprise architecture history

b) Pitfalls of CRUD

c) CQRS as solution

2. CQRS internals

3. Axon framework as CQRS implementation

Page 3: CQRS innovations (English version)

3 www.ExigenServices.com

Why CQRS ?

I. Why CQRS ?

Page 4: CQRS innovations (English version)

4 www.ExigenServices.com

Lets talk about evolution of enterprise architecture

?

Back to the beginning

Page 5: CQRS innovations (English version)

5 www.ExigenServices.com

Evolution of presentation of documents

Epoch of paper documents

Page 6: CQRS innovations (English version)

6 www.ExigenServices.com

Evolution of presentation of documents

Epoch of electronic storages

Page 7: CQRS innovations (English version)

7 www.ExigenServices.com

Epoch of electronic storages

Search in electronic storage

Page 8: CQRS innovations (English version)

8 www.ExigenServices.com

Epoch of electronic storages

Epoch of CRUD architecture has came

Page 9: CQRS innovations (English version)

9 www.ExigenServices.com

Evolution of data processing

Epoch of business processes

Page 10: CQRS innovations (English version)

10 www.ExigenServices.com

CRUD approach is oriented on data manipulation, but not on business

logic modeling .

However…

Page 11: CQRS innovations (English version)

11 www.ExigenServices.com

Pitfalls of CRUD

II. Pitfalls of CRUD

Page 12: CQRS innovations (English version)

12 www.ExigenServices.com

Problem #1. Usage of JavaBeans ….

JavaBean – “Reusable software components that can be manipulated visually in a builder tool”.

Page 13: CQRS innovations (English version)

13 www.ExigenServices.com

1. Broken encapsulation of business objects.

2. Worse code readability.3. Harder maintainability.4. All business logic

is placed in service methods.

… results in …

Page 14: CQRS innovations (English version)

14 www.ExigenServices.com

Problem #2. Performance optimization and consequences.

Usage of ORM tools with denormalization dilutes

Page 15: CQRS innovations (English version)

15 www.ExigenServices.com

Problem #3. Scalability

During business data processing we always chose C in CAP theorem

Page 16: CQRS innovations (English version)

16 www.ExigenServices.com

Problem #4:In real life concurrent data modification conflicts do not exist.

Real life business processes do not have concurrent data modification conflicts.

Detection of such conflict is sign of flaw in implementation of business logic.

CRUD does not take this into account.

Page 17: CQRS innovations (English version)

17 www.ExigenServices.com

CQRS as solution

III. CQRS as solution

Page 18: CQRS innovations (English version)

18 www.ExigenServices.com

CQRS

CQRS - Command Query Responsibility Segregation

Page 19: CQRS innovations (English version)

19 www.ExigenServices.com

Problem # 1: Usage of JavaBeans

JavaBeans are still used on query side onlybut JavaBean != Domain Entity.

Page 20: CQRS innovations (English version)

20 www.ExigenServices.com

Problem #2. Performance optimization and consequences.

Data denormailzation is used on query side only

Page 21: CQRS innovations (English version)

21 www.ExigenServices.com

Data on query side

Each table – reflection of presentation of data on user screen.

Database are not restricted to be SQL only.

Possible alternatives - Apache Cassandra, HBase, OrientDB ….

Page 22: CQRS innovations (English version)

22 www.ExigenServices.com

Problem #3. Scalability

Data consistency is needed on business logic side only.

On query side eventual consistency is totally acceptable.

Page 23: CQRS innovations (English version)

23 www.ExigenServices.com

Problem #4:In real life concurrent data modification conflicts do not exist.

1. In the form of values of variables inside object

Two approaches to present object state

Page 24: CQRS innovations (English version)

24 www.ExigenServices.com

Two approaches to present object state

+11.2 M $ + 5.3 M $ - 8.2 M $

Sum: 8.3 M $

2. In form of event queue

Page 25: CQRS innovations (English version)

25 www.ExigenServices.com

Two approaches to present object state

Each aggregate (DDD) – event container. There is no need to use relational

databases. It is preferable to have DB with ACID

properties.

Page 26: CQRS innovations (English version)

26 www.ExigenServices.com

Two approaches to present object state

Advantages: System monitoring support. Ability rollback system state till any moment

in the past. Framework for data replication and conflict

resolution.

Page 27: CQRS innovations (English version)

27 www.ExigenServices.com

Conflict resolution

Correct customer address

Customer reallocated

Conflict resolver

Customer reallocated

Page 28: CQRS innovations (English version)

28 www.ExigenServices.com

Architecture of CQRS applications

IV. Architecture of CQRS applications

Page 29: CQRS innovations (English version)

29 www.ExigenServices.com

CQRS – is approach only

CQRS is approach only, how it will be implemented, depends

on you.

Page 30: CQRS innovations (English version)
Page 31: CQRS innovations (English version)

31 www.ExigenServices.com

Queries

Multilayer architecture

DB query

CQRS

Conversion to domain model

Conversion to DTO

Transmutation of datato client

DB query

Conversion to domain model

Conversion to DTO

Transmutation of datato client

Page 32: CQRS innovations (English version)
Page 33: CQRS innovations (English version)

33 www.ExigenServices.com

Commands

Command – presentation of business action, action which is meaningful for end user.

Advantages of usage of commands:1. Orientation on business problems.2. Convenient facilities for monitoring and scalability.

Page 34: CQRS innovations (English version)
Page 35: CQRS innovations (English version)
Page 36: CQRS innovations (English version)

36 www.ExigenServices.com

….advantages…..

1. Good preconditions for DDD usage.2. Usage of complex event processing

possibilities.3. Simplicity of distribution of responsibilities

between highly specialized commands.

Page 37: CQRS innovations (English version)

37 www.ExigenServices.com

CQRS frameworks

V. CQRS frameworks

Page 38: CQRS innovations (English version)

38 www.ExigenServices.com

Axon framework

Axon framework - most popular and feature rich.

Page 39: CQRS innovations (English version)

39 www.ExigenServices.com

Example of CQRS application

Address Book – address list management

Page 40: CQRS innovations (English version)
Page 41: CQRS innovations (English version)

41 www.ExigenServices.com

Command creation and submission

Page 42: CQRS innovations (English version)
Page 43: CQRS innovations (English version)

43 www.ExigenServices.com

Command processing

Page 44: CQRS innovations (English version)

44 www.ExigenServices.com

Business action

Page 45: CQRS innovations (English version)

45 www.ExigenServices.com

Event processing on query side

Page 46: CQRS innovations (English version)
Page 47: CQRS innovations (English version)

47 www.ExigenServices.com

Query side

Page 48: CQRS innovations (English version)

48 www.ExigenServices.com

Simplicity of configuration

Page 49: CQRS innovations (English version)

49 www.ExigenServices.com

Axon – repository и event store.

Repository

Event Store

JPA

File System JPA Mongo DB

Page 50: CQRS innovations (English version)

50 www.ExigenServices.com

Event Stores – pros and cons

There is no ACID support better performance

JPA Event Store

Transactional but slow

Mongo DB, File system

Page 51: CQRS innovations (English version)

51 www.ExigenServices.com

Questions

Page 52: CQRS innovations (English version)

52 www.ExigenServices.com

Authors

Artem Orobets. twitter: @Dr_EniSh , [email protected], skype: dr_enish

Andrey Lomakin. twitter: @Andrey_Lomakin , [email protected] , skype: lomakin_andrey

Page 53: CQRS innovations (English version)

53 www.ExigenServices.com

Sources

1. First CQRS introduction http://www.infoq.com/presentations/greg-young-unshackle-qcon08

2. CQRS architecture overview - http://elegantcode.com/2009/11/11/cqrs-la-greg-young/

3. Greg Young blog - http://codebetter.com/gregyoung/

4. Race conditions does not exist http://www.udidahan.com/2010/08/31/race-conditions-dont-exist/

5. Domain Driven Design Aggregator - http://domaindrivendesign.org/

6. Axon framework home page - http://code.google.com/p/axonframework/

7. Mark Nijhof blog http://cre8ivethought.com/blog