SlideShare a Scribd company logo
1 of 40
CQRS & EVS with
Building of a modern distributed enterprise application
CQRS & EVS with
• My name is Lluis Fernández.
• I’m involved in a tech group of freelancers named
B-Team.
• We offer consultancy on distributed system
architectures.
• Contact:
llffernandez@gmail.com
b-team_b-team@googlegroups.com
• What’s this about.
• The patterns: CQRS, EVS and ESB.
• All together: An example of distributed
enterprise application.
CQRS & EVS with
CQRS & EVS with
What’s this about?
CQRS & EVS with
• NoSQL databases, like MongoDB, have
contributed to the adoption and implementation
of archetypes and patterns to develop
distributed enterprise applications.
• High read/write rates, huge data stores
management, highly scalable read-only
replication and schema-less document
orientation, are well suited for those kind of
patterns and techniques.
CQRS & EVS with
• This presentation is about how some of these
patterns and archetypes had been applied during
the implementation of real-word use case: a
Shipment Management application for one of
the most important Messaging and Packages
Delivery companies in Spain.
CQRS & EVS with
CQRS.
CQRS & EVS with
• CQRS stands for Command-Query Responsibility
Segregation.
• Commands are expected to do writes of small
portions of data.
• Queries are expected to do reads of big portions
of data.
• CQRS encourages the separation of these
different workloads.
CQRS & EVS with
CQRS facade
Commands
Queries
Shipment
management
core services
View data
synchronization
Regular
operations on
Master data
Master DB
(R/W)
Views DB
(Readonly)
Replication
Corporate
shipment
management
web app.
Packages
Add package
Add destination
Add origin
Add delivery
Assign courier
Pending
deriveries
Lost packages
Packages by
shipment
Packages by
shipment
CQRS & EVS with
• Reduces contention and collision between
queries and commands persistence-level
operations.
• Allows the scaling-out of queries, usually the
most common and expensive operations.
• Allows the use of heterogeneous view data
stores.
CQRS & EVS with
Shipment management core services
Simple automatic synchronization
(replication)
Queries
Commands
Datasets optimized
for expected queries
(grouping, filtering,
joins, etc.)
Infrastructure-provided
synchronization mechanism.
No optimization:
Master data = View data
Regular datasets
(packages,
deliveries, etc.)
These synchronization
processes introduce
staleness of data
provided to the queries.
Views DB (Readonly) Master DB (R/W)
View data
synchronization
Regular
operations on
Master data
Packages
DeliveriesCustomers
Packages by
shipment
Package
tracking
CQRS & EVS with
Queries
Commands
Shipment management core services
Queries
Views DB (Readonly)
View data
synchronization
View data
synchronization
Regular
operations on
Master data
Master DB (R/W)
More copies of view
data or more different
views.
Also, copies of view data
can be heterogeneous.
Views DB (Readonly)
Packages by
shipment
Package
tracking
Packages by
shipment
Package
tracking
Packages
Deliveries
Customers
CQRS & EVS with
• MongoDB replica sets and ReadPreference can
be used to segregate master and view data:
 Commands write on the PRIMARY.
 View data is also written on the PRIMARY.
 Queries read from SECONDARIES.
• Separate master and view data collections in
different databases (MongoDb write locking).
• Schema optimization and indexing in collections
storing view data also improve performance.
CQRS & EVS with
Shipment management core services
Queries are launched against
SECONDARIES (SECONDARY or
SECONDARY_PREFERRED read
preference)
MongoDB replication
Commands
Queries
View data synchronization
Packages per shipment
view synchronizer
Data optimized for views:
 Schema design.
 Indexing.
Multiple SECONDARIES
allows queries scaling.
Regular
operations on
Master data
Commands are launched against
PRIMARIES (PRIMARY or
PRIMARY_PREFERRED read preference)
View data ALSO goes
to PRIMARIES
Master
data
(affected by
commands)
goes to
PRIMARIES
PRIMARY
(Master and Views data)
SECONDARIES
(View data)
Packages by
shipment
Package
tracking
Packages
DeliveriesCustomers
Packages by
shipment
Package
tracking
Packages
DeliveriesCustomers
CQRS & EVS with
PRIMARY
(Master and
View data)
SECONDARY
(View data)
Packages
MongoDB replication
Packages per
shipment
Queries
Packages per
shipment
Shipment management
core services
Master and View
data are stored in
PRIMARY, in
different databases.
View data is replicated to
SECONDARY
Commands
Packages per shipment
view synchronizer
View data
synchronization
CQRS & EVS with
• Caveats:
Staleness of data read by queries.
Availability loss and overloads of PRIMARY in case
of SECONDARIES failures.
Balancer in sharding environments can introduce
additional staleness and duplication in data being
read.
CQRS & EVS with
EVS.
CQRS & EVS with
• EVS stands for EVent Sourcing.
• Closely related to DDD (Domain Driven Design) and
CQRS.
• Events are changes to the state of a domain model
subset of an application.
• Events occurred in the past, and are also referred as
Domain events.
• EVS consists in expressing the state of a domain
model subset as a sequence of events.
CQRS & EVS with
Shipment managment core service
EVS engine
Add package
Add package
Create
Add package
Assign courier
Add delivery
Add delivery
Add delivery
Last event
Store
Incoming Domain Events Last event
Delivery
Package
Customer
Courier
Promo
Rebuild
Retrieve
Event store
Apply
ALL retrieved events are
replayed to rebuild domain
model subset state
Last event is aplied after
domain model subset
rebuild, and stored in the
Event Store.
CQRS & EVS with
• Events are stored in a Event Store, that can be
huge (ideally infinite), depending on the domain
subset’s lifetime.
• To keep growth of the Event Store under control:
Store a point-in-time state of the domain model
subset (take a snapshot of it).
Store only events occurred after the last snapshot.
CQRS & EVS with
Shipment management core service
EVS engine
Add package
Add package
Create
Add package
Assign courier
Add delivery
Add delivery
Add delivery
Last event
Store
Incoming Domain Events Last event
Delivery
Package
Customer
Courier
Promo
Rebuild
Retrieve
Event store
Snapshot
Apply
Store snapshot
ONLY events after snapshot
are used to rebuild domain
model subset state.
A snapshot is taken after
replaying some events.
Remaining events (events
after th snapshot) are used
to rebuild the state of the
domain model subset and
remain stored in the Event
Store.
CQRS & EVS with
• Single collection event store:
Both snapshots and events conform a single
document => Single collection.
findAndModify can be well suited to add events
and update or create snapshots in a single
atomic operation.
Usable in scenarios with low frequency rate of
events.
CQRS & EVS with
Event
Event
Event
Event
Event
Event
Event
Event
Store
snapshot
AggregateId
AggregateId
Root
Entity
Value
object
Value
object
Entity
Root
Entity
Value
object
Value
object
Entity
Component / service
EVS
engine
StoreRetrieve
Event store
Event
Event
Documents include both
snapshot and events
pending to apply.
Events are added with a
$push operation in a
findAndModify atomic
operation.
Due to growth of
events array,
documents can
be moved often,
impacting
performance
CQRS & EVS with
• Multiple collection event store:
Snapshots and events are persisted in different
collections.
May require some locking and operations isolation
management in multithreaded environments.
CQRS & EVS with
Event
Event
Event
Event
Event
Event
Event
Event
Store
snapshot
AggregateId
AggregateId
AggregateId
AggregateId
AggregateId
AggregateId
AggregateId
AggregateId
AggregateId
AggregateId
Root
Entity
Value
object
Value
object
Entity
Root
Entity
Value
object
Value
object
Entity
Component / service
EVS
engine
StoreRetrieve
Event store
Snapshots and events are
stored in their respective
collection, separated from
each other.
Snapshots
and events
are stored in
a single
atomic
update
operation.
CQRS & EVS with
ESB.
CQRS & EVS with
• ESB = Enterprise Service Bus. It is an
infrastructure piece of software than a pattern
itself.
• Implements different messaging patterns:
Publish / Subscribe
Request / Reply
Dead letter channel.
Others.
CQRS & EVS with
Publisher Subscriber
ServiceService Service Service
Subscriber Subcriber
ESB config DB
Message published and
delivered to all subscribers.
ESB configuration data
persistence: subsciptions
database.
Requester DB Service DB Service DB
Request message, delivered to replier.
Replier info in message header.
Reply message
delivered to
requester.
CQRS & EVS with
• MongoDB is applicable as a persistence layer for
subscriptions store.
• In complex applications, with many services
interconnected:
Persistence layer for ESB usage statistics and
metrics (latency, msg/s, queue length, etc.).
Persistence layer for Dead Letter Channel
subscribers (logger for all services connected to
ESB).
CQRS & EVS with
Publisher Subscriber
ServiceMonitor Service Service
Subscriber Subcriber
ESB config DB
Metrics, heartbeat, statistics
sample message.
Statistics DB Service DB Service DB
Dead letter channel
message (error on
component captured)
Statistics database.
Dead letter channel
database (logger).
CQRS & EVS with
• Two main messaging streams: data and control.
• Control messages:
Monitoring metrics samples.
Start / pause / stop service processing.
Heartbeat messages (ping to services).
• Message traffic is lead by a transport tier.
• To prevent contention and service saturation, a
buffering or queuing system is recommended.
CQRS & EVS with
Service 2 Service 3
Control ControlProcess Process
Service 1
ControlProcess
Bus service
Process (Message Routing) Control
Action handling Action handling Action handling
Data
messages
Control
messages
Control
handling
Control
handling
Control
handling
Durable direct RabbitMQ exchange (Control)
Durable direct RabbitMQ exchange (Command, Events, Documents)
Service contracts
serialized as JSON
messages
Bus config DB
Service 3
Service 2
Mirrored RabbitMQ
queues
Mirrored RabbitMQ
queues
Mirrored RabbitMQ
queues
CQRS & EVS with
All together: An example of
distributed application.
CQRS & EVS with
• Main functional requirements:
Allow management of shipments generated online
by agencies.
Allow management of agency and corporate
customers.
Allow offline loading of shipments generated by
large customers.
Integrate with other line-of-business systems
(CRM, legacy applications, etc.).
CQRS & EVS with
• Main QoS requirements:
Nearly 550 agencies.
3K online users during office time.
Several thousands of customers.
Storage needs based on 50K shipments / day
(online and offline workloads) and 45 days of
operational shipment lifetime.
Estimation of 20 state changes per shipment
during its lifetime.
CQRS & EVS with
• Solution components:
Frontend: MVC UI.
A layer of CQRS WS interfaces frontend and
backend.
Backend: services (some implementing EVS)
interconnected by ESB.
A MongoDB Sharding Cluster as the persistence
tier for them all.
CQRS & EVS with
• Technologies stack:
UI: ASP.NET MVC + JQuery.
CQRS + REST facade: ASP.NET MVC
ESB + Services: .NET Framework based
Windows Services.
Messaging transport: RabbitMQ cluster.
Persistence: MongoDb sharding cluster.
CQRS & EVS with
Services
Commands
Events
Documents
Commands
Events
Documents
Commands
Events
Documents
Commands
Events
Documents
MongoDb Sharding Cluster
DDD
Services
Publishers Subscribers
EVS
Services
Queries
Commands
CQRS REST
WS
Domain data:
 Events.
 Aggregates.
 Snapshots.
Domain data:
 Entities.
 Value objects.
 Aggregates.
Domain data:
 Entities.
 Value objects.
 Aggregates.
 Specifications.
Master dataViews
Service contracts:
 Events.
 Commands.
 Documents.
CQRS & EVS with
Web Frontend
Web applications
CQRS WS
Load balancing
RabbitMQ client
MongoDB
IIS
NLB
.NET Framework
ASP.NET MVC
MongoDb Router
Services tier
Backend and core services
Application services
Integration services
.NET Framework
SQL Server Client
Cliente RabbitMQ
MongoDb Router (mongos)
Cluster config
Config 1
Config 2
Config 3
Shard 2
Node 1 Node 2
Arbiter
Shard 1
Node 1 Node 2
Arbiter
Persistence tier
CQRS view data.
Services Domain models persistence
ESB subscriptions DB persistence
MongoDB sharded cluster
(2 shards)
MongoDb Router
(mongos).
A router per
appserver.
They cache a local
copy of the cluster
config DB.
Two-phase commit replication
servers.
If one or two config servers fail,
cluster configuration DB goes
readonly (chuncks cannot be moved
between shards, no balancing), but
data remains writable and available.
Data partition and distribution
Sharded collections: distribution is
done in a per-collection basis.
Data is partitioned and distributed
across shards, attending to a
sharding (partition) key.
Each partition unit is called a
chunk.
EVS collections can be partitioned
by a hash on document _id.
Sharding keys for collections
persisting view data must be
choosed for each single case, to
guarantee queries performance.
CQRS & EVS with
Than you for your attention.

More Related Content

What's hot

Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices Bozhidar Bozhanov
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaAraf Karsh Hamid
 
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...Alex Cachia
 
Agile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven DesignAgile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven DesignAraf Karsh Hamid
 
RethinkConn 2022!
RethinkConn 2022!RethinkConn 2022!
RethinkConn 2022!NATS
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservicesAnil Allewar
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the bookCyrille Martraire
 
[오픈소스컨설팅] 서비스 메쉬(Service mesh)
[오픈소스컨설팅] 서비스 메쉬(Service mesh)[오픈소스컨설팅] 서비스 메쉬(Service mesh)
[오픈소스컨설팅] 서비스 메쉬(Service mesh)Open Source Consulting
 
From Monolithic to Microservices
From Monolithic to Microservices From Monolithic to Microservices
From Monolithic to Microservices Amazon Web Services
 
MSA 전략 1: 마이크로서비스, 어떻게 디자인 할 것인가?
MSA 전략 1: 마이크로서비스, 어떻게 디자인 할 것인가?MSA 전략 1: 마이크로서비스, 어떻게 디자인 할 것인가?
MSA 전략 1: 마이크로서비스, 어떻게 디자인 할 것인가?VMware Tanzu Korea
 
Building infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowBuilding infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowAnton Babenko
 
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍Chris Ohk
 
Monoliths to microservices workshop
Monoliths to microservices workshopMonoliths to microservices workshop
Monoliths to microservices workshopJudy Breedlove
 
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
[NDC17] Kubernetes로 개발서버 간단히 찍어내기[NDC17] Kubernetes로 개발서버 간단히 찍어내기
[NDC17] Kubernetes로 개발서버 간단히 찍어내기SeungYong Oh
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeMartin Schütte
 

What's hot (20)

Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
Docker swarm
Docker swarmDocker swarm
Docker swarm
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and Saga
 
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
 
Agile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven DesignAgile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven Design
 
RethinkConn 2022!
RethinkConn 2022!RethinkConn 2022!
RethinkConn 2022!
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the book
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
CQRS
CQRSCQRS
CQRS
 
[오픈소스컨설팅] 서비스 메쉬(Service mesh)
[오픈소스컨설팅] 서비스 메쉬(Service mesh)[오픈소스컨설팅] 서비스 메쉬(Service mesh)
[오픈소스컨설팅] 서비스 메쉬(Service mesh)
 
From Monolithic to Microservices
From Monolithic to Microservices From Monolithic to Microservices
From Monolithic to Microservices
 
MSA 전략 1: 마이크로서비스, 어떻게 디자인 할 것인가?
MSA 전략 1: 마이크로서비스, 어떻게 디자인 할 것인가?MSA 전략 1: 마이크로서비스, 어떻게 디자인 할 것인가?
MSA 전략 1: 마이크로서비스, 어떻게 디자인 할 것인가?
 
Building infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowBuilding infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps Krakow
 
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
 
Monoliths to microservices workshop
Monoliths to microservices workshopMonoliths to microservices workshop
Monoliths to microservices workshop
 
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
[NDC17] Kubernetes로 개발서버 간단히 찍어내기[NDC17] Kubernetes로 개발서버 간단히 찍어내기
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
 
Terraform
TerraformTerraform
Terraform
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as Code
 

Viewers also liked

CQRS and Event Sourcing with MongoDB and PHP
CQRS and Event Sourcing with MongoDB and PHPCQRS and Event Sourcing with MongoDB and PHP
CQRS and Event Sourcing with MongoDB and PHPDavide Bellettini
 
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...Chris Richardson
 
Cqrs journey guide
Cqrs journey guideCqrs journey guide
Cqrs journey guideSteve Xu
 
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 architectureThomas Jaskula
 
WSO2ConUS 2015 - Introduction to WSO2 Microservices Server (MSS)
WSO2ConUS 2015 - Introduction to WSO2 Microservices Server (MSS)WSO2ConUS 2015 - Introduction to WSO2 Microservices Server (MSS)
WSO2ConUS 2015 - Introduction to WSO2 Microservices Server (MSS)Afkham Azeez
 
A Crush on Design Thinking
A Crush on Design ThinkingA Crush on Design Thinking
A Crush on Design ThinkingMatteo Burgassi
 
Enterprise architectsview 2015-apr
Enterprise architectsview 2015-aprEnterprise architectsview 2015-apr
Enterprise architectsview 2015-aprMongoDB
 
How to use graphs to identify credit card thieves?
How to use graphs to identify credit card thieves?How to use graphs to identify credit card thieves?
How to use graphs to identify credit card thieves?Linkurious
 
GraphConnect Europe 2016 - Creating an Innovative Task Management Engine - Mi...
GraphConnect Europe 2016 - Creating an Innovative Task Management Engine - Mi...GraphConnect Europe 2016 - Creating an Innovative Task Management Engine - Mi...
GraphConnect Europe 2016 - Creating an Innovative Task Management Engine - Mi...Neo4j
 
A Related Matter: Optimizing your webapp by using django-debug-toolbar, selec...
A Related Matter: Optimizing your webapp by using django-debug-toolbar, selec...A Related Matter: Optimizing your webapp by using django-debug-toolbar, selec...
A Related Matter: Optimizing your webapp by using django-debug-toolbar, selec...Christopher Adams
 
Exploring the Great Olympian Graph
Exploring the Great Olympian GraphExploring the Great Olympian Graph
Exploring the Great Olympian GraphNeo4j
 
Presentation on Large Scale Data Management
Presentation on Large Scale Data ManagementPresentation on Large Scale Data Management
Presentation on Large Scale Data ManagementChris Bunch
 
Web valley talk - usability, visualization and mobile app development
Web valley talk - usability, visualization and mobile app developmentWeb valley talk - usability, visualization and mobile app development
Web valley talk - usability, visualization and mobile app developmentEamonn Maguire
 
How to establish a sustainable solution for data lineage
How to establish a sustainable solution for data lineageHow to establish a sustainable solution for data lineage
How to establish a sustainable solution for data lineageLeigh Hill
 
How to Search, Explore and Visualize Neo4j with Linkurious - Jean Villedieu @...
How to Search, Explore and Visualize Neo4j with Linkurious - Jean Villedieu @...How to Search, Explore and Visualize Neo4j with Linkurious - Jean Villedieu @...
How to Search, Explore and Visualize Neo4j with Linkurious - Jean Villedieu @...Neo4j
 
Km4City: how to make smart and resilient your city, beginner document
Km4City: how to make smart and resilient your city, beginner documentKm4City: how to make smart and resilient your city, beginner document
Km4City: how to make smart and resilient your city, beginner documentPaolo Nesi
 
The Five Graphs of Government: How Federal Agencies can Utilize Graph Technology
The Five Graphs of Government: How Federal Agencies can Utilize Graph TechnologyThe Five Graphs of Government: How Federal Agencies can Utilize Graph Technology
The Five Graphs of Government: How Federal Agencies can Utilize Graph TechnologyGreta Workman
 
Graphically understand and interactively explore your Data Lineage
Graphically understand and interactively explore your Data LineageGraphically understand and interactively explore your Data Lineage
Graphically understand and interactively explore your Data LineageMohammad Ahmed
 

Viewers also liked (20)

CQRS and Event Sourcing with MongoDB and PHP
CQRS and Event Sourcing with MongoDB and PHPCQRS and Event Sourcing with MongoDB and PHP
CQRS and Event Sourcing with MongoDB and PHP
 
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...
 
RabbitMQ in Sprayer
RabbitMQ in SprayerRabbitMQ in Sprayer
RabbitMQ in Sprayer
 
Cqrs journey guide
Cqrs journey guideCqrs journey guide
Cqrs journey guide
 
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
 
WSO2ConUS 2015 - Introduction to WSO2 Microservices Server (MSS)
WSO2ConUS 2015 - Introduction to WSO2 Microservices Server (MSS)WSO2ConUS 2015 - Introduction to WSO2 Microservices Server (MSS)
WSO2ConUS 2015 - Introduction to WSO2 Microservices Server (MSS)
 
A Crush on Design Thinking
A Crush on Design ThinkingA Crush on Design Thinking
A Crush on Design Thinking
 
Enterprise architectsview 2015-apr
Enterprise architectsview 2015-aprEnterprise architectsview 2015-apr
Enterprise architectsview 2015-apr
 
How to use graphs to identify credit card thieves?
How to use graphs to identify credit card thieves?How to use graphs to identify credit card thieves?
How to use graphs to identify credit card thieves?
 
GraphConnect Europe 2016 - Creating an Innovative Task Management Engine - Mi...
GraphConnect Europe 2016 - Creating an Innovative Task Management Engine - Mi...GraphConnect Europe 2016 - Creating an Innovative Task Management Engine - Mi...
GraphConnect Europe 2016 - Creating an Innovative Task Management Engine - Mi...
 
A Related Matter: Optimizing your webapp by using django-debug-toolbar, selec...
A Related Matter: Optimizing your webapp by using django-debug-toolbar, selec...A Related Matter: Optimizing your webapp by using django-debug-toolbar, selec...
A Related Matter: Optimizing your webapp by using django-debug-toolbar, selec...
 
Exploring the Great Olympian Graph
Exploring the Great Olympian GraphExploring the Great Olympian Graph
Exploring the Great Olympian Graph
 
Presentation on Large Scale Data Management
Presentation on Large Scale Data ManagementPresentation on Large Scale Data Management
Presentation on Large Scale Data Management
 
Web valley talk - usability, visualization and mobile app development
Web valley talk - usability, visualization and mobile app developmentWeb valley talk - usability, visualization and mobile app development
Web valley talk - usability, visualization and mobile app development
 
How to establish a sustainable solution for data lineage
How to establish a sustainable solution for data lineageHow to establish a sustainable solution for data lineage
How to establish a sustainable solution for data lineage
 
How to Search, Explore and Visualize Neo4j with Linkurious - Jean Villedieu @...
How to Search, Explore and Visualize Neo4j with Linkurious - Jean Villedieu @...How to Search, Explore and Visualize Neo4j with Linkurious - Jean Villedieu @...
How to Search, Explore and Visualize Neo4j with Linkurious - Jean Villedieu @...
 
Km4City: how to make smart and resilient your city, beginner document
Km4City: how to make smart and resilient your city, beginner documentKm4City: how to make smart and resilient your city, beginner document
Km4City: how to make smart and resilient your city, beginner document
 
The Five Graphs of Government: How Federal Agencies can Utilize Graph Technology
The Five Graphs of Government: How Federal Agencies can Utilize Graph TechnologyThe Five Graphs of Government: How Federal Agencies can Utilize Graph Technology
The Five Graphs of Government: How Federal Agencies can Utilize Graph Technology
 
Graphically understand and interactively explore your Data Lineage
Graphically understand and interactively explore your Data LineageGraphically understand and interactively explore your Data Lineage
Graphically understand and interactively explore your Data Lineage
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 

Similar to CQRS & EVS with MongoDb

Patterns & Practices of Microservices
Patterns & Practices of MicroservicesPatterns & Practices of Microservices
Patterns & Practices of MicroservicesWesley Reisz
 
Our way to microservices
Our way to microservicesOur way to microservices
Our way to microservicesAndi Pangeran
 
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdfSchema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdfseo18
 
數據庫遷移到雲端的成功秘訣
數據庫遷移到雲端的成功秘訣數據庫遷移到雲端的成功秘訣
數據庫遷移到雲端的成功秘訣Amazon Web Services
 
Migrate a successful transactional database to azure
Migrate a successful transactional database to azureMigrate a successful transactional database to azure
Migrate a successful transactional database to azureIke Ellis
 
OSS DB on Azure
OSS DB on AzureOSS DB on Azure
OSS DB on Azurerockplace
 
Case Study _Cloud Native Transformation Deploying Integration workloads to AK...
Case Study _Cloud Native Transformation Deploying Integration workloads to AK...Case Study _Cloud Native Transformation Deploying Integration workloads to AK...
Case Study _Cloud Native Transformation Deploying Integration workloads to AK...Srikanth Prathipati
 
A Tour of Azure SQL Databases (NOVA SQL UG 2020)
A Tour of Azure SQL Databases  (NOVA SQL UG 2020)A Tour of Azure SQL Databases  (NOVA SQL UG 2020)
A Tour of Azure SQL Databases (NOVA SQL UG 2020)Timothy McAliley
 
Resume_Ashok-updated (1) (1)
Resume_Ashok-updated (1) (1)Resume_Ashok-updated (1) (1)
Resume_Ashok-updated (1) (1)chimmili ashok
 
Festive Tech Calendar 2021
Festive Tech Calendar 2021Festive Tech Calendar 2021
Festive Tech Calendar 2021Callon Campbell
 
AWS Webcast - Introduction to Amazon RDS: Low Admin, High Performance Databas...
AWS Webcast - Introduction to Amazon RDS: Low Admin, High Performance Databas...AWS Webcast - Introduction to Amazon RDS: Low Admin, High Performance Databas...
AWS Webcast - Introduction to Amazon RDS: Low Admin, High Performance Databas...Amazon Web Services
 
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Deploying to and Configuring WebSphere Application Server with UrbanCode DeployDeploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Deploying to and Configuring WebSphere Application Server with UrbanCode DeployIBM DevOps
 
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Deploying to and Configuring WebSphere Application Server with UrbanCode DeployDeploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Deploying to and Configuring WebSphere Application Server with UrbanCode DeployClaudia Ring
 
Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?Amazon Web Services
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Emerson Eduardo Rodrigues Von Staffen
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...Amazon Web Services
 
Migrating your Databases to AWS: Deep Dive on Amazon RDS and AWS Database Mig...
Migrating your Databases to AWS: Deep Dive on Amazon RDS and AWS Database Mig...Migrating your Databases to AWS: Deep Dive on Amazon RDS and AWS Database Mig...
Migrating your Databases to AWS: Deep Dive on Amazon RDS and AWS Database Mig...Amazon Web Services
 
System design for video streaming service
System design for video streaming serviceSystem design for video streaming service
System design for video streaming serviceNirmik Kale
 

Similar to CQRS & EVS with MongoDb (20)

Patterns & Practices of Microservices
Patterns & Practices of MicroservicesPatterns & Practices of Microservices
Patterns & Practices of Microservices
 
Our way to microservices
Our way to microservicesOur way to microservices
Our way to microservices
 
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdfSchema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
 
數據庫遷移到雲端的成功秘訣
數據庫遷移到雲端的成功秘訣數據庫遷移到雲端的成功秘訣
數據庫遷移到雲端的成功秘訣
 
Migrate a successful transactional database to azure
Migrate a successful transactional database to azureMigrate a successful transactional database to azure
Migrate a successful transactional database to azure
 
OSS DB on Azure
OSS DB on AzureOSS DB on Azure
OSS DB on Azure
 
Case Study _Cloud Native Transformation Deploying Integration workloads to AK...
Case Study _Cloud Native Transformation Deploying Integration workloads to AK...Case Study _Cloud Native Transformation Deploying Integration workloads to AK...
Case Study _Cloud Native Transformation Deploying Integration workloads to AK...
 
A Tour of Azure SQL Databases (NOVA SQL UG 2020)
A Tour of Azure SQL Databases  (NOVA SQL UG 2020)A Tour of Azure SQL Databases  (NOVA SQL UG 2020)
A Tour of Azure SQL Databases (NOVA SQL UG 2020)
 
Resume_Ashok-updated (1) (1)
Resume_Ashok-updated (1) (1)Resume_Ashok-updated (1) (1)
Resume_Ashok-updated (1) (1)
 
Festive Tech Calendar 2021
Festive Tech Calendar 2021Festive Tech Calendar 2021
Festive Tech Calendar 2021
 
AWS Webcast - Introduction to Amazon RDS: Low Admin, High Performance Databas...
AWS Webcast - Introduction to Amazon RDS: Low Admin, High Performance Databas...AWS Webcast - Introduction to Amazon RDS: Low Admin, High Performance Databas...
AWS Webcast - Introduction to Amazon RDS: Low Admin, High Performance Databas...
 
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Deploying to and Configuring WebSphere Application Server with UrbanCode DeployDeploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
 
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Deploying to and Configuring WebSphere Application Server with UrbanCode DeployDeploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
 
Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
 
Migrating your Databases to AWS: Deep Dive on Amazon RDS and AWS Database Mig...
Migrating your Databases to AWS: Deep Dive on Amazon RDS and AWS Database Mig...Migrating your Databases to AWS: Deep Dive on Amazon RDS and AWS Database Mig...
Migrating your Databases to AWS: Deep Dive on Amazon RDS and AWS Database Mig...
 
System design for video streaming service
System design for video streaming serviceSystem design for video streaming service
System design for video streaming service
 
Advanced Container Scheduling
Advanced Container SchedulingAdvanced Container Scheduling
Advanced Container Scheduling
 
Azure data platform overview
Azure data platform overviewAzure data platform overview
Azure data platform overview
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

CQRS & EVS with MongoDb

  • 1. CQRS & EVS with Building of a modern distributed enterprise application
  • 2. CQRS & EVS with • My name is Lluis Fernández. • I’m involved in a tech group of freelancers named B-Team. • We offer consultancy on distributed system architectures. • Contact: llffernandez@gmail.com b-team_b-team@googlegroups.com
  • 3. • What’s this about. • The patterns: CQRS, EVS and ESB. • All together: An example of distributed enterprise application. CQRS & EVS with
  • 4. CQRS & EVS with What’s this about?
  • 5. CQRS & EVS with • NoSQL databases, like MongoDB, have contributed to the adoption and implementation of archetypes and patterns to develop distributed enterprise applications. • High read/write rates, huge data stores management, highly scalable read-only replication and schema-less document orientation, are well suited for those kind of patterns and techniques.
  • 6. CQRS & EVS with • This presentation is about how some of these patterns and archetypes had been applied during the implementation of real-word use case: a Shipment Management application for one of the most important Messaging and Packages Delivery companies in Spain.
  • 7. CQRS & EVS with CQRS.
  • 8. CQRS & EVS with • CQRS stands for Command-Query Responsibility Segregation. • Commands are expected to do writes of small portions of data. • Queries are expected to do reads of big portions of data. • CQRS encourages the separation of these different workloads.
  • 9. CQRS & EVS with CQRS facade Commands Queries Shipment management core services View data synchronization Regular operations on Master data Master DB (R/W) Views DB (Readonly) Replication Corporate shipment management web app. Packages Add package Add destination Add origin Add delivery Assign courier Pending deriveries Lost packages Packages by shipment Packages by shipment
  • 10. CQRS & EVS with • Reduces contention and collision between queries and commands persistence-level operations. • Allows the scaling-out of queries, usually the most common and expensive operations. • Allows the use of heterogeneous view data stores.
  • 11. CQRS & EVS with Shipment management core services Simple automatic synchronization (replication) Queries Commands Datasets optimized for expected queries (grouping, filtering, joins, etc.) Infrastructure-provided synchronization mechanism. No optimization: Master data = View data Regular datasets (packages, deliveries, etc.) These synchronization processes introduce staleness of data provided to the queries. Views DB (Readonly) Master DB (R/W) View data synchronization Regular operations on Master data Packages DeliveriesCustomers Packages by shipment Package tracking
  • 12. CQRS & EVS with Queries Commands Shipment management core services Queries Views DB (Readonly) View data synchronization View data synchronization Regular operations on Master data Master DB (R/W) More copies of view data or more different views. Also, copies of view data can be heterogeneous. Views DB (Readonly) Packages by shipment Package tracking Packages by shipment Package tracking Packages Deliveries Customers
  • 13. CQRS & EVS with • MongoDB replica sets and ReadPreference can be used to segregate master and view data:  Commands write on the PRIMARY.  View data is also written on the PRIMARY.  Queries read from SECONDARIES. • Separate master and view data collections in different databases (MongoDb write locking). • Schema optimization and indexing in collections storing view data also improve performance.
  • 14. CQRS & EVS with Shipment management core services Queries are launched against SECONDARIES (SECONDARY or SECONDARY_PREFERRED read preference) MongoDB replication Commands Queries View data synchronization Packages per shipment view synchronizer Data optimized for views:  Schema design.  Indexing. Multiple SECONDARIES allows queries scaling. Regular operations on Master data Commands are launched against PRIMARIES (PRIMARY or PRIMARY_PREFERRED read preference) View data ALSO goes to PRIMARIES Master data (affected by commands) goes to PRIMARIES PRIMARY (Master and Views data) SECONDARIES (View data) Packages by shipment Package tracking Packages DeliveriesCustomers Packages by shipment Package tracking Packages DeliveriesCustomers
  • 15. CQRS & EVS with PRIMARY (Master and View data) SECONDARY (View data) Packages MongoDB replication Packages per shipment Queries Packages per shipment Shipment management core services Master and View data are stored in PRIMARY, in different databases. View data is replicated to SECONDARY Commands Packages per shipment view synchronizer View data synchronization
  • 16. CQRS & EVS with • Caveats: Staleness of data read by queries. Availability loss and overloads of PRIMARY in case of SECONDARIES failures. Balancer in sharding environments can introduce additional staleness and duplication in data being read.
  • 17. CQRS & EVS with EVS.
  • 18. CQRS & EVS with • EVS stands for EVent Sourcing. • Closely related to DDD (Domain Driven Design) and CQRS. • Events are changes to the state of a domain model subset of an application. • Events occurred in the past, and are also referred as Domain events. • EVS consists in expressing the state of a domain model subset as a sequence of events.
  • 19. CQRS & EVS with Shipment managment core service EVS engine Add package Add package Create Add package Assign courier Add delivery Add delivery Add delivery Last event Store Incoming Domain Events Last event Delivery Package Customer Courier Promo Rebuild Retrieve Event store Apply ALL retrieved events are replayed to rebuild domain model subset state Last event is aplied after domain model subset rebuild, and stored in the Event Store.
  • 20. CQRS & EVS with • Events are stored in a Event Store, that can be huge (ideally infinite), depending on the domain subset’s lifetime. • To keep growth of the Event Store under control: Store a point-in-time state of the domain model subset (take a snapshot of it). Store only events occurred after the last snapshot.
  • 21. CQRS & EVS with Shipment management core service EVS engine Add package Add package Create Add package Assign courier Add delivery Add delivery Add delivery Last event Store Incoming Domain Events Last event Delivery Package Customer Courier Promo Rebuild Retrieve Event store Snapshot Apply Store snapshot ONLY events after snapshot are used to rebuild domain model subset state. A snapshot is taken after replaying some events. Remaining events (events after th snapshot) are used to rebuild the state of the domain model subset and remain stored in the Event Store.
  • 22. CQRS & EVS with • Single collection event store: Both snapshots and events conform a single document => Single collection. findAndModify can be well suited to add events and update or create snapshots in a single atomic operation. Usable in scenarios with low frequency rate of events.
  • 23. CQRS & EVS with Event Event Event Event Event Event Event Event Store snapshot AggregateId AggregateId Root Entity Value object Value object Entity Root Entity Value object Value object Entity Component / service EVS engine StoreRetrieve Event store Event Event Documents include both snapshot and events pending to apply. Events are added with a $push operation in a findAndModify atomic operation. Due to growth of events array, documents can be moved often, impacting performance
  • 24. CQRS & EVS with • Multiple collection event store: Snapshots and events are persisted in different collections. May require some locking and operations isolation management in multithreaded environments.
  • 25. CQRS & EVS with Event Event Event Event Event Event Event Event Store snapshot AggregateId AggregateId AggregateId AggregateId AggregateId AggregateId AggregateId AggregateId AggregateId AggregateId Root Entity Value object Value object Entity Root Entity Value object Value object Entity Component / service EVS engine StoreRetrieve Event store Snapshots and events are stored in their respective collection, separated from each other. Snapshots and events are stored in a single atomic update operation.
  • 26. CQRS & EVS with ESB.
  • 27. CQRS & EVS with • ESB = Enterprise Service Bus. It is an infrastructure piece of software than a pattern itself. • Implements different messaging patterns: Publish / Subscribe Request / Reply Dead letter channel. Others.
  • 28. CQRS & EVS with Publisher Subscriber ServiceService Service Service Subscriber Subcriber ESB config DB Message published and delivered to all subscribers. ESB configuration data persistence: subsciptions database. Requester DB Service DB Service DB Request message, delivered to replier. Replier info in message header. Reply message delivered to requester.
  • 29. CQRS & EVS with • MongoDB is applicable as a persistence layer for subscriptions store. • In complex applications, with many services interconnected: Persistence layer for ESB usage statistics and metrics (latency, msg/s, queue length, etc.). Persistence layer for Dead Letter Channel subscribers (logger for all services connected to ESB).
  • 30. CQRS & EVS with Publisher Subscriber ServiceMonitor Service Service Subscriber Subcriber ESB config DB Metrics, heartbeat, statistics sample message. Statistics DB Service DB Service DB Dead letter channel message (error on component captured) Statistics database. Dead letter channel database (logger).
  • 31. CQRS & EVS with • Two main messaging streams: data and control. • Control messages: Monitoring metrics samples. Start / pause / stop service processing. Heartbeat messages (ping to services). • Message traffic is lead by a transport tier. • To prevent contention and service saturation, a buffering or queuing system is recommended.
  • 32. CQRS & EVS with Service 2 Service 3 Control ControlProcess Process Service 1 ControlProcess Bus service Process (Message Routing) Control Action handling Action handling Action handling Data messages Control messages Control handling Control handling Control handling Durable direct RabbitMQ exchange (Control) Durable direct RabbitMQ exchange (Command, Events, Documents) Service contracts serialized as JSON messages Bus config DB Service 3 Service 2 Mirrored RabbitMQ queues Mirrored RabbitMQ queues Mirrored RabbitMQ queues
  • 33. CQRS & EVS with All together: An example of distributed application.
  • 34. CQRS & EVS with • Main functional requirements: Allow management of shipments generated online by agencies. Allow management of agency and corporate customers. Allow offline loading of shipments generated by large customers. Integrate with other line-of-business systems (CRM, legacy applications, etc.).
  • 35. CQRS & EVS with • Main QoS requirements: Nearly 550 agencies. 3K online users during office time. Several thousands of customers. Storage needs based on 50K shipments / day (online and offline workloads) and 45 days of operational shipment lifetime. Estimation of 20 state changes per shipment during its lifetime.
  • 36. CQRS & EVS with • Solution components: Frontend: MVC UI. A layer of CQRS WS interfaces frontend and backend. Backend: services (some implementing EVS) interconnected by ESB. A MongoDB Sharding Cluster as the persistence tier for them all.
  • 37. CQRS & EVS with • Technologies stack: UI: ASP.NET MVC + JQuery. CQRS + REST facade: ASP.NET MVC ESB + Services: .NET Framework based Windows Services. Messaging transport: RabbitMQ cluster. Persistence: MongoDb sharding cluster.
  • 38. CQRS & EVS with Services Commands Events Documents Commands Events Documents Commands Events Documents Commands Events Documents MongoDb Sharding Cluster DDD Services Publishers Subscribers EVS Services Queries Commands CQRS REST WS Domain data:  Events.  Aggregates.  Snapshots. Domain data:  Entities.  Value objects.  Aggregates. Domain data:  Entities.  Value objects.  Aggregates.  Specifications. Master dataViews Service contracts:  Events.  Commands.  Documents.
  • 39. CQRS & EVS with Web Frontend Web applications CQRS WS Load balancing RabbitMQ client MongoDB IIS NLB .NET Framework ASP.NET MVC MongoDb Router Services tier Backend and core services Application services Integration services .NET Framework SQL Server Client Cliente RabbitMQ MongoDb Router (mongos) Cluster config Config 1 Config 2 Config 3 Shard 2 Node 1 Node 2 Arbiter Shard 1 Node 1 Node 2 Arbiter Persistence tier CQRS view data. Services Domain models persistence ESB subscriptions DB persistence MongoDB sharded cluster (2 shards) MongoDb Router (mongos). A router per appserver. They cache a local copy of the cluster config DB. Two-phase commit replication servers. If one or two config servers fail, cluster configuration DB goes readonly (chuncks cannot be moved between shards, no balancing), but data remains writable and available. Data partition and distribution Sharded collections: distribution is done in a per-collection basis. Data is partitioned and distributed across shards, attending to a sharding (partition) key. Each partition unit is called a chunk. EVS collections can be partitioned by a hash on document _id. Sharding keys for collections persisting view data must be choosed for each single case, to guarantee queries performance.
  • 40. CQRS & EVS with Than you for your attention.