21
…WHAT’S THAT CQRS THING? introduction for adopters effect free!

hai detto CQRS a chi ?!?!?!

Embed Size (px)

Citation preview

Page 1: hai detto CQRS a chi ?!?!?!

…WHAT’S THAT CQRS THING?

introduction for adopters

effect

free!

Page 2: hai detto CQRS a chi ?!?!?!

COMMAND QUERY RESPONSIBILITY

SEGREGATION PATTERN

Page 3: hai detto CQRS a chi ?!?!?!

ORIGINAL SIN

CREATE

READ

UPDATE

DELETE

Page 4: hai detto CQRS a chi ?!?!?!
Page 5: hai detto CQRS a chi ?!?!?!
Page 6: hai detto CQRS a chi ?!?!?!

is an architectural pattern proposed by Greg Young that segregates reads and writes of a system into two separate subsystems.

CQRS

Page 7: hai detto CQRS a chi ?!?!?!

writes are usually asynchronous and stored in a transactional storage while reads are eventually consistent and retrieved from de-normalised views

CQRS (details)

Page 8: hai detto CQRS a chi ?!?!?!

BERTRAND MAYERDesigner of Eiffel

programming language

Coined “open/closed principle” and “design

by contract”

Introduced command query separation

(CQS)

Page 9: hai detto CQRS a chi ?!?!?!

Use of commands and queries separates write and read concerns

Page 10: hai detto CQRS a chi ?!?!?!

COMMANDTell to do something

Page 11: hai detto CQRS a chi ?!?!?!

COMMAND• Command is the message to change state

• Message handled by a CommandHandler

• Returns void (so nothing)

• Describes business intent

• Immutable

Page 12: hai detto CQRS a chi ?!?!?!

QUERYFetch state from data store

Page 13: hai detto CQRS a chi ?!?!?!

QUERY

• Read state from data store

• Does not change state

• Has a return value

Page 14: hai detto CQRS a chi ?!?!?!

WHY SHOULD I USE CQRS?

• Scalability

• Reduced complexity

• Flexibility

• Focus on the business

Page 15: hai detto CQRS a chi ?!?!?!

• Fear of change

• Mental leap

• All-Or-Nothing approach

BE AWARE OF

Page 16: hai detto CQRS a chi ?!?!?!

CQRS MYTHS

• is easy

• CQRS = Event Sourcing and vice versa

• requires an eventual consistent read store

• requires a bus/queues/asynchronous messaging

Page 17: hai detto CQRS a chi ?!?!?!

– Udi Dahan

“Most people using CQRS (and event sourcing too) shouldn't have done so”

– Greg Young

“It's important to note though, that these are things you can do, not necessarily things you should do.

Separating the read and write models can be quite costly”

WHEN SHOULD I AVOID IT?

Page 18: hai detto CQRS a chi ?!?!?!

WHATS NEXT?

• Event sourcing (ES)

• Eventual consistency

• Task based UI

• …

Page 19: hai detto CQRS a chi ?!?!?!
Page 20: hai detto CQRS a chi ?!?!?!

Thank you.

@realfuzzyMichele Franzin

Page 21: hai detto CQRS a chi ?!?!?!

CREDITSslide10 - www.defenceimagery.mod.uk - 45155579slide 12 - https://www.flickr.com/photos/broeckxsven/slides 4,9 - http://martinfowler.com/bliki/

http://martinfowler.com/bliki/CQRS.htmlhttp://udidahan.com/2009/12/09/clarified-cqrs/https://en.wikipedia.org/wiki/Command–query_separationhttps://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf

RESOURCES