SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Scaling wix to over 70 m users
Scaling wix to over 70 m usersScaling wix to over 70 m users
Scaling wix to over 70 m users
Yoav Avrahami
 

Was ist angesagt? (20)

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

Andere mochten auch

Single User v/s Multi User Databases
Single User v/s Multi User DatabasesSingle User v/s Multi User Databases
Single User v/s Multi User Databases
Raminder Pal Singh
 

Andere mochten auch (12)

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

Ähnlich wie CQRS and Event Sourcing

Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
Amazon Web Services
 

Ähnlich wie CQRS and Event Sourcing (20)

Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Project "Babelfish" - A data warehouse to attack complexity
 Project "Babelfish" - A data warehouse to attack complexity Project "Babelfish" - A data warehouse to attack complexity
Project "Babelfish" - A data warehouse to attack complexity
 
Genomic Computation at Scale with Serverless, StackStorm and Docker Swarm
Genomic Computation at Scale with Serverless, StackStorm and Docker SwarmGenomic Computation at Scale with Serverless, StackStorm and Docker Swarm
Genomic Computation at Scale with Serverless, StackStorm and Docker Swarm
 
OpenStack cloud for ConoHa, Z.com and GMO AppsCloud in okinawa opendays 2015 ...
OpenStack cloud for ConoHa, Z.com and GMO AppsCloud in okinawa opendays 2015 ...OpenStack cloud for ConoHa, Z.com and GMO AppsCloud in okinawa opendays 2015 ...
OpenStack cloud for ConoHa, Z.com and GMO AppsCloud in okinawa opendays 2015 ...
 
Azure Serverless Toolbox
Azure Serverless ToolboxAzure Serverless Toolbox
Azure Serverless Toolbox
 
HOW TO DRONE.IO IN CI/CD WORLD
HOW TO DRONE.IO IN CI/CD WORLDHOW TO DRONE.IO IN CI/CD WORLD
HOW TO DRONE.IO IN CI/CD WORLD
 
Blazing fast web experience at your fingertips with Experience Edge, JSS for ...
Blazing fast web experience at your fingertips with Experience Edge, JSS for ...Blazing fast web experience at your fingertips with Experience Edge, JSS for ...
Blazing fast web experience at your fingertips with Experience Edge, JSS for ...
 
Build Web Applications using Microservices on Node.js and Serverless AWS
Build Web Applications using Microservices on Node.js and Serverless AWSBuild Web Applications using Microservices on Node.js and Serverless AWS
Build Web Applications using Microservices on Node.js and Serverless AWS
 
Scala, ECS, Docker: Delayed Execution @Coursera
Scala, ECS, Docker: Delayed Execution @CourseraScala, ECS, Docker: Delayed Execution @Coursera
Scala, ECS, Docker: Delayed Execution @Coursera
 
(SACON) Satish Sreenivasaiah - DevSecOps Tools and Beyond
(SACON) Satish Sreenivasaiah - DevSecOps Tools and Beyond(SACON) Satish Sreenivasaiah - DevSecOps Tools and Beyond
(SACON) Satish Sreenivasaiah - DevSecOps Tools and Beyond
 
Kubernetes + Jenkins X: a Cloud Native Approach
Kubernetes + Jenkins X: a Cloud Native ApproachKubernetes + Jenkins X: a Cloud Native Approach
Kubernetes + Jenkins X: a Cloud Native Approach
 
20171122 aws usergrp_coretech-spn-cicd-aws-v01
20171122 aws usergrp_coretech-spn-cicd-aws-v0120171122 aws usergrp_coretech-spn-cicd-aws-v01
20171122 aws usergrp_coretech-spn-cicd-aws-v01
 
Microservices Architecture for Web Applications using Amazon AWS Cloud
Microservices Architecture for Web Applications using Amazon AWS CloudMicroservices Architecture for Web Applications using Amazon AWS Cloud
Microservices Architecture for Web Applications using Amazon AWS Cloud
 
(ARC309) Getting to Microservices: Cloud Architecture Patterns
(ARC309) Getting to Microservices: Cloud Architecture Patterns(ARC309) Getting to Microservices: Cloud Architecture Patterns
(ARC309) Getting to Microservices: Cloud Architecture Patterns
 
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
 
DevOps automation for AWS
DevOps automation for AWSDevOps automation for AWS
DevOps automation for AWS
 
ARC201 Microservices Architecture @ AWS re:Invent 2015
ARC201 Microservices Architecture @ AWS re:Invent 2015ARC201 Microservices Architecture @ AWS re:Invent 2015
ARC201 Microservices Architecture @ AWS re:Invent 2015
 
Microservices Architecture for Web Applications using AWS Lambda and more
Microservices Architecture for Web Applications using AWS Lambda and moreMicroservices Architecture for Web Applications using AWS Lambda and more
Microservices Architecture for Web Applications using AWS Lambda and more
 
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
 
Microservices Architecture for Digital Platforms using Serverless AWS
Microservices Architecture for Digital Platforms using Serverless AWSMicroservices Architecture for Digital Platforms using Serverless AWS
Microservices Architecture for Digital Platforms using Serverless AWS
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

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