CQRS explained with a million dollar idea What are we going to do? - - PowerPoint PPT Presentation

cqrs
SMART_READER_LITE
LIVE PREVIEW

CQRS explained with a million dollar idea What are we going to do? - - PowerPoint PPT Presentation

CQRS explained with a million dollar idea What are we going to do? The million dollar idea Command and query segregation Command and query responsibility segregation Code structure Disclaimer: when (not) to use The million


slide-1
SLIDE 1

CQRS

explained with a million dollar idea

slide-2
SLIDE 2

What are we going to do?

  • The million dollar idea
  • Command and query segregation
  • Command and query responsibility segregation
  • Code structure
  • Disclaimer: when (not) to use
slide-3
SLIDE 3

The million dollar idea

  • Based on my graduation project
  • Car/ride-sharing application
  • Focus on social aspect 


(you both know this person 


  • r both sharing the same interest)
  • Primarily used for scheduled travel
  • Assumptions
  • We need CQRS
slide-4
SLIDE 4

Command and query segregation

  • Commands
  • Changing the state of a system without returning a value
  • Queries
  • Return a result without changing the state of the system (generating no side-

effects)

  • Can be described as use-cases, i.e.
  • RegisterRide
  • FindRide
  • FindRideMatch
slide-5
SLIDE 5

Why?

  • Ease of mind, you don’t have to worry about

executing queries since you “can’t” break things

  • “Out of the box” able to perform commands

asynchronously

slide-6
SLIDE 6

Command and query responsibility segregation

–Martin Fowler

“At its heart is the notion that you can use a different model to update information than the model you use to read information.”

slide-7
SLIDE 7

Command and query responsibility segregation

slide-8
SLIDE 8

Command and query responsibility segregation

  • Different read and write models
  • Domain events
  • They describe what happend in the domain 


(for example RideWasCreated, DepartureTimeHasChanged)

  • Are dispatched for every change in the domain
  • Are used to update the read models
  • Side effect: allows traceability and accountability (i.e. the bug

is caused by this sequence of steps)

slide-9
SLIDE 9

Why?

  • Storing data at the best possible place (No-SQL,

Graph etc) in the best possible format (normalized

  • r denormalized) for the use-case
  • Scalability advantages
  • Better performance
slide-10
SLIDE 10

The example application

slide-11
SLIDE 11

Disclaimer: when (not) to use?

  • Be aware that CQRS can overcomplicate your

application, explore alternatives before falling for the “cool” factor of this pattern

  • Consider using CQRS in the following cases
  • When working in large teams
  • When working with difficult business logic
  • When scalability matters
slide-12
SLIDE 12

Further reading…

  • https://leanpub.com/ddd-in-php - DDD in PHP
  • http://getprooph.org/ - The CQRS and event

sourcing components for PHP