CQRS and Event Sourcing
Nikolay	
  Vasilev	
  
CQRS and Event Sourcing
•  Applica0on	
  Architecture	
  
•  CQRS	
  and	
  Event	
  Sourcing	
  
•  Code	
  /	
  Example	
  
•  Ques0ons	
  
•  Resources	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 2
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
Application Architecture
Source:	
  [Evans,	
  DDD]	
  
Layered Architecture
•  One	
  of	
  the	
  oldest	
  paGerns	
  
•  Each	
  layer	
  could	
  couple	
  only	
  to	
  itself	
  	
  
or	
  below	
  
•  Lower	
  levels	
  could	
  loosely	
  couple	
  
to	
  upper	
  via	
  Observer	
  or	
  Mediator	
  [GoF]	
  
•  UI	
  Layer	
  
–  Only	
  renders	
  informa0on	
  
–  Example:	
  OHS	
  (Remote	
  Façade)	
  
•  Applica0on	
  Layer	
  
–  Very	
  lightweight	
  	
  
–  Building	
  Blocks:	
  Applica0on	
  Services	
  
–  Coordinate	
  opera0ons	
  over	
  	
  
Aggregates	
  (i.e.	
  express	
  Use	
  Cases)	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 4
Source:	
  [Evans,	
  DDD]	
  
Layered Architecture
•  Applica0on	
  Layer	
  
–  Register	
  Subscribers	
  for	
  Dom.	
  Events	
  	
  
–  Transac0ons,	
  Email	
  sending	
  etc.	
  
–  Devoid	
  of	
  domain	
  logic	
  
•  Domain	
  Layer	
  
–  Expressive	
  Behavioural-­‐Rich	
  Domain	
  	
  
Model	
  
•  Infrastructure	
  Layer	
  
–  Low	
  Level	
  Services	
  
–  Focus	
  on	
  technology	
  specific	
  decisions	
  
–  Persistence,	
  Messaging,	
  etc.	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 5
Source:	
  [Vernon,	
  DDD]	
  
Hexagonal Architecture (HA)
•  Also	
  known	
  as	
  “Ports	
  and	
  Adapters”	
  
•  Ports	
  
–  Outer	
  hexagon	
  (HTTP,	
  Messaging	
  etc.)	
  
–  Each	
  hexagon’s	
  side	
  represents	
  a	
  port	
  
–  Either	
  for	
  input	
  or	
  output	
  
–  Do	
  not	
  implement	
  ports(use	
  e.g.	
  Jersey)	
  
•  Adapters	
  
–  Transform	
  client’s	
  input	
  into	
  internal	
  	
  
API’s	
  “terms”	
  
–  Transform	
  internal	
  API’s	
  output	
  to	
  
input	
  suitable	
  for	
  clients	
  
–  Each	
  client	
  type	
  has	
  an	
  Adapter	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 6
Source:	
  [Vernon,	
  DDD]	
  
Hexagonal Architecture (HA)
•  Outer	
  hexagon	
  reaches	
  inner	
  
hexagon	
  via	
  applica0on’s	
  API	
  
•  Design	
  applica0on	
  inside	
  per	
  	
  
func0onal	
  requirements(use	
  cases	
  API)	
  
•  Layered	
  Architecture	
  +	
  DI	
  	
  
encourages	
  the	
  use	
  of	
  Hexagonal	
  Arch.	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 7
Event Driven Architecture (EDA)
•  Event	
  Sourcing	
  
	
  
•  Promotes,	
  detect,	
  consume	
  and	
  react	
  to	
  events	
  
	
  
•  Pipes	
  and	
  Filters	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 8
EpisodeAdded	
  
b#1,s#2	
  
SeriesRenamed	
  
b#20,s#1	
  
BrandAc0vated	
  
b#3	
  
Event Driven Architecture (EDA)
•  EDA	
  could	
  be	
  combined	
  with	
  	
  
Hexagonal	
  Architecture	
  (HA)	
  	
  
–  EDA	
  used	
  for	
  integra0on	
  
–  HA	
  used	
  for	
  Bounded	
  Contexts	
  
–  LA	
  could	
  replace	
  HA	
  as	
  well	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 9
Source:	
  [Vernon,	
  DDD]	
  
Event Driven Architecture (EDA)
•  Events	
  as	
  mechanism	
  for	
  Storage	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 10
Source:	
  [Vernon,	
  DDD]	
  
Event Driven Architecture (EDA)
•  Append-­‐only	
  architecture	
  
–  No	
  “Delete”	
  ac0on	
  
	
  
•  Distribute	
  easier	
  than	
  RDBMS	
  
–  Due	
  to	
  no	
  locks	
  
–  Sharding	
  (uses	
  only	
  Aggregate	
  keys)	
  
•  Loading	
  Objects	
  
–  Loads	
  accumulated	
  events	
  for	
  an	
  Aggregate	
  	
  
–  Performance	
  issue	
  for	
  over	
  than	
  100	
  events	
  
–  Rolling	
  Snapshots	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 11
EpisodeAdded	
  
b#1,s#2	
  
SeriesRenamed	
  
b#20,s#1	
  
SeriesRemoved	
  
b#10,s#2	
  
BrandAc0vated	
  
b#3	
  
4	
  
3	
  
snap	
  
2	
  
1	
  
CQRS
•  Command	
  and	
  Query	
  Responsibility	
  Segrega0on	
  (CQRS)	
  
•  Bertrand	
  Mayer’s	
  CQS	
  Principle	
  
–  Command:	
   	
  If	
  method	
  alters	
  the	
  state	
  should	
  not	
  return	
  value	
  (i.e.	
  returns	
  void)	
  
–  Query:	
   	
  If	
  you	
  return	
  value	
  you	
  cannot	
  mutate	
  state	
  
•  What	
  if	
  we	
  apply	
  it	
  at	
  architectural	
  level?	
  ;)	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 12
Read Service
Write Service
CQRS
•  Stereotypical	
  vs.	
  CQRS	
  Architecture	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 13
Source:	
  [Young,	
  CQRS]	
  
Stereotypical Architecture
CQRS
•  Stereotypical	
  vs.	
  CQRS	
  Architecture	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 14
Source:	
  [Young,	
  CQRS]	
  
CQRS
CQRS and Event Sourcing
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
Source:	
  [Young,	
  CQRS]	
  
CQRS + ES
•  CQRS	
  +	
  EDA	
  with	
  	
  
Domain	
  Events	
  
	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 16
CQRS + ES
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 17
Source:	
  [Young,	
  CQRS]	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
Code / Example
Code / Example
•  Example	
  project	
  
–  DDD-­‐CQRS	
  Sample,	
  (v.02)	
  
–  HLA:	
   	
   	
   	
  h"p://prezi.com/akrfq7jyau8w/ddd-­‐cqrs-­‐leaven-­‐v20/	
  
–  Code	
  base:	
   	
   	
  h"ps://github.com/Bo"egaIT/ddd-­‐leaven-­‐v2	
  	
  
–  User	
  Group: 	
   	
  h"ps://groups.google.com/forum/#!forum/ddd-­‐cqrs-­‐sample	
  
•  More	
  projects	
  on	
  official	
  CQRS	
  site	
  
–  hGp://cqrs.wordpress.com/examples/	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 19
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
Questions?
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 21
Thank	
  you	
  for	
  your	
  aGen0on!	
  
Resources
Resources
•  [Evans,	
  DDD]	
  "Domain-­‐Driven	
  Design:	
  Tackling	
  Complexity	
  in	
  the	
  Heart	
  of	
  Sonware",	
  Eric	
  
Evans,	
  Addison	
  Wesley,	
  20/08/2003,	
  ISBN:	
  0-­‐321-­‐12521-­‐5	
  
•  [Vernon,	
  DDD],	
  "Implemen0ng	
  Domain-­‐Driven	
  Design",	
  Vaughn	
  Vernon,	
  2013,	
  	
  	
  	
  	
  ISBN-­‐10:	
  
0-­‐321-­‐83457-­‐7,	
  ISBN-­‐13:	
  978-­‐0-­‐321-­‐83457-­‐7	
  
•  [Young,	
  CQRS],	
  "CQRS	
  Documents	
  by	
  Greg	
  Young",	
  Greg	
  Young,	
  11/2010.	
  hGp://
cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf	
  
•  [Cockburn,	
  Hex	
  Arch]	
  "Hexagonal	
  Architecture",	
  h"p://alistair.cockburn.us/Hexagonal
+architecture	
  
•  [Fowler,	
  NoSQL	
  talk]	
  "NoSQL	
  maGers	
  Cologne	
  2013	
  -­‐	
  Key	
  Note:	
  NoSQL	
  Dis0lled	
  to	
  an	
  hour	
  -­‐	
  
Mar0n	
  Fowler",	
  Mar0n	
  Fowler,	
  2013,	
  h"p://vimeo.com/66052102	
  	
  
•  Domain	
  Driven	
  Design	
  Website,	
  h"p://domaindrivendesign.org/	
  
•  DDD	
  User	
  Group,	
  h"p://tech.groups.yahoo.com/group/domaindrivendesign/	
  
•  DDD	
  Community,	
  h"p://dddcommunity.org/	
  
•  CQRS	
  Official	
  Website,	
  h"p://cqrs.wordpress.com/	
  	
  
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 23
Bulgarian Java User Group
Nikolay Vasilev, CC BY-SA 3.0
CQRS + ES Page 24

More Related Content

PDF
A year with event sourcing and CQRS
PDF
12-factor-jruby
PDF
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
PDF
Writing less code with Serverless on AWS at AWS Community Day DACH 2021
PDF
Writing less code with Serverless on AWS at FrOSCon 2021
PPTX
Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)
PDF
Writing less code with Serverless on AWS at OOP 2022
PDF
12 Factor Scala
A year with event sourcing and CQRS
12-factor-jruby
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
Writing less code with Serverless on AWS at AWS Community Day DACH 2021
Writing less code with Serverless on AWS at FrOSCon 2021
Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)
Writing less code with Serverless on AWS at OOP 2022
12 Factor Scala

What's hot (20)

PDF
Writing less code with Serverless on AWS at AWS User Group Nairobi
PPTX
Microservices Architecture for Content Management Systems using AWS Lambda an...
PPTX
Oracle application container cloud back end integration using node final
PDF
ADCD 2022 - Handling secrets in the release process with Azure DevOps and Azu...
PPTX
Azure dev ops integrations with Jenkins
PPTX
Alfresco DevCon 2019 Performance Tools of the Trade
PDF
Serverless Summit - Quiz
PPTX
Scaling wix to over 70 m users
PPTX
MS Insights Brazil 2015 containers and devops
PDF
How would ESBs look like, if they were done today.
PPTX
MicroServices on Azure
PDF
#JaxLondon keynote: Developing applications with a microservice architecture
PPTX
Java PaaS Vendor Survey - September 2011
PPTX
R2DBC - Good Enough for Production?
PDF
Anatomy of a Modern Node.js Application Architecture
PPTX
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
PDF
Serverless Architecture Patterns - Manoj Ganapathi - Serverless Summit
PPTX
Oracle OpenWorld 2014 Review Part Four - PaaS Middleware
PPTX
Amazon Webservices for Java Developers - UCI Webinar
PDF
Continuous integration and delivery for java based web applications
Writing less code with Serverless on AWS at AWS User Group Nairobi
Microservices Architecture for Content Management Systems using AWS Lambda an...
Oracle application container cloud back end integration using node final
ADCD 2022 - Handling secrets in the release process with Azure DevOps and Azu...
Azure dev ops integrations with Jenkins
Alfresco DevCon 2019 Performance Tools of the Trade
Serverless Summit - Quiz
Scaling wix to over 70 m users
MS Insights Brazil 2015 containers and devops
How would ESBs look like, if they were done today.
MicroServices on Azure
#JaxLondon keynote: Developing applications with a microservice architecture
Java PaaS Vendor Survey - September 2011
R2DBC - Good Enough for Production?
Anatomy of a Modern Node.js Application Architecture
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Serverless Architecture Patterns - Manoj Ganapathi - Serverless Summit
Oracle OpenWorld 2014 Review Part Four - PaaS Middleware
Amazon Webservices for Java Developers - UCI Webinar
Continuous integration and delivery for java based web applications
Ad

Viewers also liked (12)

PPTX
CQRS and Event Sourcing, An Alternative Architecture for DDD
PDF
DDD, CQRS & ES lessons learned (Gitte Vermeiren)
PDF
SciSmalltalk: Doing Science with Agility
PPTX
CQRS recipes or how to cook your architecture
PDF
CQRS + Event Sourcing
PPTX
Real World Event Sourcing and CQRS
PDF
Introduction to Domain Driven Design
PDF
Microservice Architecture with CQRS and Event Sourcing
PPT
BDD with JBehave and Selenium
ODP
Distributed systems and consistency
PDF
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
PPTX
Single User v/s Multi User Databases
CQRS and Event Sourcing, An Alternative Architecture for DDD
DDD, CQRS & ES lessons learned (Gitte Vermeiren)
SciSmalltalk: Doing Science with Agility
CQRS recipes or how to cook your architecture
CQRS + Event Sourcing
Real World Event Sourcing and CQRS
Introduction to Domain Driven Design
Microservice Architecture with CQRS and Event Sourcing
BDD with JBehave and Selenium
Distributed systems and consistency
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Single User v/s Multi User Databases
Ad

Similar to CQRS and Event Sourcing (20)

PDF
Domain Driven Design
PDF
Project "Babelfish" - A data warehouse to attack complexity
PDF
Genomic Computation at Scale with Serverless, StackStorm and Docker Swarm
PDF
OpenStack cloud for ConoHa, Z.com and GMO AppsCloud in okinawa opendays 2015 ...
PDF
Azure Serverless Toolbox
PDF
HOW TO DRONE.IO IN CI/CD WORLD
PDF
Blazing fast web experience at your fingertips with Experience Edge, JSS for ...
PPTX
Build Web Applications using Microservices on Node.js and Serverless AWS
PDF
Scala, ECS, Docker: Delayed Execution @Coursera
PDF
(SACON) Satish Sreenivasaiah - DevSecOps Tools and Beyond
PDF
Kubernetes + Jenkins X: a Cloud Native Approach
PPTX
20171122 aws usergrp_coretech-spn-cicd-aws-v01
PPTX
Microservices Architecture for Web Applications using Amazon AWS Cloud
PPTX
DevOps automation for AWS
PPTX
ARC201 Microservices Architecture @ AWS re:Invent 2015
PPTX
Microservices Architecture for Web Applications using AWS Lambda and more
PPTX
Microservices Architecture for Digital Platforms using Serverless AWS
PPTX
Evolve 19 | Jayan Kandathil | Running AEM Workloads on Microsoft Azure
PDF
Why Kubernetes? Cloud Native and Developer Experience at Zalando - OWL Tech &...
PDF
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...
Domain Driven Design
Project "Babelfish" - A data warehouse to attack complexity
Genomic Computation at Scale with Serverless, StackStorm and Docker Swarm
OpenStack cloud for ConoHa, Z.com and GMO AppsCloud in okinawa opendays 2015 ...
Azure Serverless Toolbox
HOW TO DRONE.IO IN CI/CD WORLD
Blazing fast web experience at your fingertips with Experience Edge, JSS for ...
Build Web Applications using Microservices on Node.js and Serverless AWS
Scala, ECS, Docker: Delayed Execution @Coursera
(SACON) Satish Sreenivasaiah - DevSecOps Tools and Beyond
Kubernetes + Jenkins X: a Cloud Native Approach
20171122 aws usergrp_coretech-spn-cicd-aws-v01
Microservices Architecture for Web Applications using Amazon AWS Cloud
DevOps automation for AWS
ARC201 Microservices Architecture @ AWS re:Invent 2015
Microservices Architecture for Web Applications using AWS Lambda and more
Microservices Architecture for Digital Platforms using Serverless AWS
Evolve 19 | Jayan Kandathil | Running AEM Workloads on Microsoft Azure
Why Kubernetes? Cloud Native and Developer Experience at Zalando - OWL Tech &...
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...

Recently uploaded (20)

PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
Connector Corner: Transform Unstructured Documents with Agentic Automation
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PPTX
SGT Report The Beast Plan and Cyberphysical Systems of Control
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
CEH Module 2 Footprinting CEH V13, concepts
PPTX
Internet of Everything -Basic concepts details
PDF
substrate PowerPoint Presentation basic one
PDF
Ensemble model-based arrhythmia classification with local interpretable model...
PDF
Lung cancer patients survival prediction using outlier detection and optimize...
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
PDF
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
giants, standing on the shoulders of - by Daniel Stenberg
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Module 1 Introduction to Web Programming .pptx
Advancing precision in air quality forecasting through machine learning integ...
Connector Corner: Transform Unstructured Documents with Agentic Automation
NewMind AI Weekly Chronicles – August ’25 Week IV
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
SGT Report The Beast Plan and Cyberphysical Systems of Control
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
CEH Module 2 Footprinting CEH V13, concepts
Internet of Everything -Basic concepts details
substrate PowerPoint Presentation basic one
Ensemble model-based arrhythmia classification with local interpretable model...
Lung cancer patients survival prediction using outlier detection and optimize...
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf

CQRS and Event Sourcing

  • 1. CQRS and Event Sourcing Nikolay  Vasilev  
  • 2. CQRS and Event Sourcing •  Applica0on  Architecture   •  CQRS  and  Event  Sourcing   •  Code  /  Example   •  Ques0ons   •  Resources   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 2
  • 3. Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 Application Architecture
  • 4. Source:  [Evans,  DDD]   Layered Architecture •  One  of  the  oldest  paGerns   •  Each  layer  could  couple  only  to  itself     or  below   •  Lower  levels  could  loosely  couple   to  upper  via  Observer  or  Mediator  [GoF]   •  UI  Layer   –  Only  renders  informa0on   –  Example:  OHS  (Remote  Façade)   •  Applica0on  Layer   –  Very  lightweight     –  Building  Blocks:  Applica0on  Services   –  Coordinate  opera0ons  over     Aggregates  (i.e.  express  Use  Cases)   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 4
  • 5. Source:  [Evans,  DDD]   Layered Architecture •  Applica0on  Layer   –  Register  Subscribers  for  Dom.  Events     –  Transac0ons,  Email  sending  etc.   –  Devoid  of  domain  logic   •  Domain  Layer   –  Expressive  Behavioural-­‐Rich  Domain     Model   •  Infrastructure  Layer   –  Low  Level  Services   –  Focus  on  technology  specific  decisions   –  Persistence,  Messaging,  etc.   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 5
  • 6. Source:  [Vernon,  DDD]   Hexagonal Architecture (HA) •  Also  known  as  “Ports  and  Adapters”   •  Ports   –  Outer  hexagon  (HTTP,  Messaging  etc.)   –  Each  hexagon’s  side  represents  a  port   –  Either  for  input  or  output   –  Do  not  implement  ports(use  e.g.  Jersey)   •  Adapters   –  Transform  client’s  input  into  internal     API’s  “terms”   –  Transform  internal  API’s  output  to   input  suitable  for  clients   –  Each  client  type  has  an  Adapter   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 6
  • 7. Source:  [Vernon,  DDD]   Hexagonal Architecture (HA) •  Outer  hexagon  reaches  inner   hexagon  via  applica0on’s  API   •  Design  applica0on  inside  per     func0onal  requirements(use  cases  API)   •  Layered  Architecture  +  DI     encourages  the  use  of  Hexagonal  Arch.   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 7
  • 8. Event Driven Architecture (EDA) •  Event  Sourcing     •  Promotes,  detect,  consume  and  react  to  events     •  Pipes  and  Filters   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 8 EpisodeAdded   b#1,s#2   SeriesRenamed   b#20,s#1   BrandAc0vated   b#3  
  • 9. Event Driven Architecture (EDA) •  EDA  could  be  combined  with     Hexagonal  Architecture  (HA)     –  EDA  used  for  integra0on   –  HA  used  for  Bounded  Contexts   –  LA  could  replace  HA  as  well   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 9 Source:  [Vernon,  DDD]  
  • 10. Event Driven Architecture (EDA) •  Events  as  mechanism  for  Storage   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 10 Source:  [Vernon,  DDD]  
  • 11. Event Driven Architecture (EDA) •  Append-­‐only  architecture   –  No  “Delete”  ac0on     •  Distribute  easier  than  RDBMS   –  Due  to  no  locks   –  Sharding  (uses  only  Aggregate  keys)   •  Loading  Objects   –  Loads  accumulated  events  for  an  Aggregate     –  Performance  issue  for  over  than  100  events   –  Rolling  Snapshots   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 11 EpisodeAdded   b#1,s#2   SeriesRenamed   b#20,s#1   SeriesRemoved   b#10,s#2   BrandAc0vated   b#3   4   3   snap   2   1  
  • 12. CQRS •  Command  and  Query  Responsibility  Segrega0on  (CQRS)   •  Bertrand  Mayer’s  CQS  Principle   –  Command:    If  method  alters  the  state  should  not  return  value  (i.e.  returns  void)   –  Query:    If  you  return  value  you  cannot  mutate  state   •  What  if  we  apply  it  at  architectural  level?  ;)   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 12 Read Service Write Service
  • 13. CQRS •  Stereotypical  vs.  CQRS  Architecture   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 13 Source:  [Young,  CQRS]   Stereotypical Architecture
  • 14. CQRS •  Stereotypical  vs.  CQRS  Architecture   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 14 Source:  [Young,  CQRS]   CQRS
  • 15. CQRS and Event Sourcing Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0
  • 16. Source:  [Young,  CQRS]   CQRS + ES •  CQRS  +  EDA  with     Domain  Events     Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 16
  • 17. CQRS + ES Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 17 Source:  [Young,  CQRS]  
  • 18. Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 Code / Example
  • 19. Code / Example •  Example  project   –  DDD-­‐CQRS  Sample,  (v.02)   –  HLA:        h"p://prezi.com/akrfq7jyau8w/ddd-­‐cqrs-­‐leaven-­‐v20/   –  Code  base:      h"ps://github.com/Bo"egaIT/ddd-­‐leaven-­‐v2     –  User  Group:    h"ps://groups.google.com/forum/#!forum/ddd-­‐cqrs-­‐sample   •  More  projects  on  official  CQRS  site   –  hGp://cqrs.wordpress.com/examples/   Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 19
  • 20. Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 Questions?
  • 21. Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 21 Thank  you  for  your  aGen0on!  
  • 23. Resources •  [Evans,  DDD]  "Domain-­‐Driven  Design:  Tackling  Complexity  in  the  Heart  of  Sonware",  Eric   Evans,  Addison  Wesley,  20/08/2003,  ISBN:  0-­‐321-­‐12521-­‐5   •  [Vernon,  DDD],  "Implemen0ng  Domain-­‐Driven  Design",  Vaughn  Vernon,  2013,          ISBN-­‐10:   0-­‐321-­‐83457-­‐7,  ISBN-­‐13:  978-­‐0-­‐321-­‐83457-­‐7   •  [Young,  CQRS],  "CQRS  Documents  by  Greg  Young",  Greg  Young,  11/2010.  hGp:// cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf   •  [Cockburn,  Hex  Arch]  "Hexagonal  Architecture",  h"p://alistair.cockburn.us/Hexagonal +architecture   •  [Fowler,  NoSQL  talk]  "NoSQL  maGers  Cologne  2013  -­‐  Key  Note:  NoSQL  Dis0lled  to  an  hour  -­‐   Mar0n  Fowler",  Mar0n  Fowler,  2013,  h"p://vimeo.com/66052102     •  Domain  Driven  Design  Website,  h"p://domaindrivendesign.org/   •  DDD  User  Group,  h"p://tech.groups.yahoo.com/group/domaindrivendesign/   •  DDD  Community,  h"p://dddcommunity.org/   •  CQRS  Official  Website,  h"p://cqrs.wordpress.com/     Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 23
  • 24. Bulgarian Java User Group Nikolay Vasilev, CC BY-SA 3.0 CQRS + ES Page 24