SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
monolith to micro-services?

event sourcing can help
Doug English
legacy 

Culture Amp
(2012 - 2015)
Client
Rails App

(Murmur)
Query Server
DB
Read-write
Read-only
Our journey Our meandering path to CQRS & event sourcing
• Attempt 1 - Asynchronous micro-services

Event Log the monolith and introduce query services

• Attempt 2 - Greenfield systems of record

Rebuild part of the monolith as a stand alone command side service

• Attempt 3 - Refactor the monolith first 

And start with the least depended upon aggregates
Attempt 1:
Asynchronous
Micro-services
Why micro-services?
• Too many developers!
• Monolith was becoming too complex.
• Want teams to control their own assets.
• Flexibility to introduce fit for purpose technologies.

(for example, elastic search for our comments search)
• Scale different parts of the app independently.

(for example, capture has a very different profile)
Attempt 1:
Asynchronous
Micro-services
Why asynchronous?
• Resilience is architected into the platform. 

If a micro-service is down, all depended micro-services remain available 

and are eventually consistent. Also protects yourself from self inflicted DOS.
• Ability to replay history for consuming services

Much easier to refactor, or to introduce new services.
• Decoupled architecture enabling platform flexibility 

Consumers don’t necessarily need to know where the producers are deployed
Reporting Service Client
Rails App

(Murmur)
Query Server
DB
Read-write
Read-only
Reporting

Service
Event

Log
What went
wrong
• Plagued with bad data issues as we tried to convert

our current production database to a stream of events
• Ongoing source-of-truth issues between the 

monolith persistence layer and the synthesised event log.
• Events were generated at the wrong business points

intended for consumption but ironically problematic for consumers
• Events were too coarse-grained and slow to process.
• Some of the events weren't real business events.
• Multiple event streams - one for each event type - hurt. 

What we learned Asynchronous micro-services are the 

right long term aim.
But, don’t start with event consumers,

start with event producers.
Event logging is not event sourcing!
What is 

Event Sourcing?
Add
Employee A
Add
Employee B
Remove
Employee A
Add
Employee C
Add
Employee B
Add
Employee C
• Store the business events as the source of truth
• Can answer questions you don’t yet know you have.
• Legal, accounting, traditional professions have used 

event sourcing for centuries.
Every method should either be
a command that performs an action, or
a query that returns data to the caller, but

not both.
In other words,
asking a question should not 

change the answer.
— Bertrand Meyer (designer of Eiffel language) on CQS
“
Command Query Responsibility Segregation
What is CQRS?
Without CQRS With CQRS
EmployeeService
+ createEmployee(employee): void

+ getEmployee(id): Employee

+ updateEmployeeName(id, name): void

+ makeEmployeeAdmin(id) : void

+ getEmployees(account): List<Employee>

EmployeeReadService
+ getEmployee(id): Employee

+ getEmployees(account): List<Employee>
EmployeeWriteService
+ createEmployee(employee): void

+ updateEmployeeName(id, name): void

+ makeEmployeeAdmin(id) : void
CQRS & 

event sourcing

architecture
Client
Command
Handler
Aggregate
event

store
Projection
Query
Handler
Eventually

consistent!
Attempt 2:
Greenfield
systems of record
Client
Rails App

(Murmur)
Query Server
DB
Reporting

Service
Event

Store
Employee

SoR
Projector
Event

Log
What worked
well?
• CQRS and event sourcing helped us be clear about the

boundaries of context.
• The new service owns the validation, so bad data issues 

in accounts we migrated were found and fixed upfront
• We could treat the monolith as one massive projection

minimising work required on the Query side, and UI.
• Removed our source of truth problems. 

Domain models can be deterministically built from events, not vice versa.
• We could incrementally migrate accounts
What didn’t
work well?
• Required a leap of faith for the team to agree to try.
• Slow to develop as we were learning a new paradigm,

and rolling our own event sourcing system.
• Eventual consistency hurts:
• Upfront we needed to solve how to update 

the monolith in a reasonable timeframe.
• We needed to refactor parts of the UI to cope

with the eventual consistency.
• Disaster recovery becomes a distributed problem.
With all the troubles of evented architecture -
it is a blessing when "shit hits the fan”.



I don't know if in the past we would even be
able to tell the customers affected by the issue.
— Unsolicited feedback from our 

Tech Lead for the Employee Service
“
1. Start with the Command Side.

Treat your existing application like one big projection.
2. Tackle a single Aggregate at a time.

No need for a big-bang migration.
3. Generate UUIDS in the legacy monolith first. 

These will help you link the migration scripts back.
4. Start by synchronously updating your existing application.

Your legacy UI will thank you for it.
5. When all writes are through CQRS Commands, refactor 

the UI to use new dedicated asynchronous projections.
6. When nothing still uses the legacy domain model, 

remove it and remove it’s synchronous projector.
Attempt 3: 

Refactor the
monolith first
Account
Survey Response Comment
Question
Employee
Identifying 

aggregates
*
*
*
*
*1
1
1
1
1
Report
*
1
ActionItem*1
Demographic*
1
Start Here!
Monolith 

phase 1
Client
Survey 

C Handler
Survey

Aggregate
Event
Store
Legacy

Domain Models
Participant 

C Handler
Participant

Aggregate
Comment 

C Handler
Comment

Aggregate
Legacy

DBProjector
Monolith Rails Controllers
Synchronous 

update!
Monolith

phase 2
Client
Survey 

C Handler
Survey

Aggregate
PostGres
Question 

C Handler
Question

Aggregate
Participant 

C Handler
Participant

Aggregate Projection
Authentication layer
Client Client
Projection
Query

handler
Query

handler
Projector
Asynchronous 

updates Projector
Beyond the
monolith
Employees

Service
Ratings

Analitycs
Text
Analytics
Data Labs

Experiments
Message Bus
Capture

Service
Survey

Designer
Account

Admin
Email

Sender
Data

Warehouse
Public

APIs
Key learnings 1. Event Logging is not event sourcing 

and just leads to source of truth confusion.
2. CQRS and event sourcing can help you move to 

micro-services, but start by refactoring the monolith
3. If you choose to event source your monolith, take 

one step at a time, and focus on the command side. 

Questions?

Mais conteúdo relacionado

Semelhante a 2017 Melbourne YOW! CTO Summit - Monolith to micro-services with CQRS & Event Sourcing

Advance Microservice Patterns - Event Souring , CQRS
Advance Microservice Patterns - Event Souring , CQRSAdvance Microservice Patterns - Event Souring , CQRS
Advance Microservice Patterns - Event Souring , CQRSMohit Mittal
 
Monitoring Containerized Micro-Services In Azure
Monitoring Containerized Micro-Services In AzureMonitoring Containerized Micro-Services In Azure
Monitoring Containerized Micro-Services In AzureAlex Bulankou
 
Cloudsolutionday 2016: Docker & FAAS at getvero.com
Cloudsolutionday 2016: Docker & FAAS at getvero.comCloudsolutionday 2016: Docker & FAAS at getvero.com
Cloudsolutionday 2016: Docker & FAAS at getvero.comAWS Vietnam Community
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architectureFaren faren
 
Data Microservices with Spring Cloud
Data Microservices with Spring CloudData Microservices with Spring Cloud
Data Microservices with Spring CloudOrkhan Gasimov
 
Evolving to Cloud-Native - Nate Schutta 2/2
Evolving to Cloud-Native - Nate Schutta 2/2Evolving to Cloud-Native - Nate Schutta 2/2
Evolving to Cloud-Native - Nate Schutta 2/2VMware Tanzu
 
Evolving to Cloud-Native - Nate Schutta (2/2)
Evolving to Cloud-Native - Nate Schutta (2/2)Evolving to Cloud-Native - Nate Schutta (2/2)
Evolving to Cloud-Native - Nate Schutta (2/2)VMware Tanzu
 
Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201
Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201
Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201Amazon Web Services
 
Embracing Failure - AzureDay Rome
Embracing Failure - AzureDay RomeEmbracing Failure - AzureDay Rome
Embracing Failure - AzureDay RomeAlberto Acerbis
 
From prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.ioFrom prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.ioMáté Lang
 
The challenges of live events scalability
The challenges of live events scalabilityThe challenges of live events scalability
The challenges of live events scalabilityGuy Tomer
 
Week 4 Assignment - Software Development PlanScenario-Your team has be.docx
Week 4 Assignment - Software Development PlanScenario-Your team has be.docxWeek 4 Assignment - Software Development PlanScenario-Your team has be.docx
Week 4 Assignment - Software Development PlanScenario-Your team has be.docxestefana2345678
 
QCon 2015 - Microservices Track Notes
QCon 2015 - Microservices Track Notes QCon 2015 - Microservices Track Notes
QCon 2015 - Microservices Track Notes Abdul Basit Munda
 
Over view of software artitecture
Over view of software artitectureOver view of software artitecture
Over view of software artitectureABDEL RAHMAN KARIM
 
[WSO2Con USA 2018] Nightmare on SSO Street
[WSO2Con USA 2018] Nightmare on SSO Street[WSO2Con USA 2018] Nightmare on SSO Street
[WSO2Con USA 2018] Nightmare on SSO StreetWSO2
 
Automation, Audits, and Apps Tour
Automation, Audits, and Apps TourAutomation, Audits, and Apps Tour
Automation, Audits, and Apps TourChef
 
How to Migrate Applications Off a Mainframe
How to Migrate Applications Off a MainframeHow to Migrate Applications Off a Mainframe
How to Migrate Applications Off a MainframeVMware Tanzu
 
Micro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMicro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMiki Lombardi
 

Semelhante a 2017 Melbourne YOW! CTO Summit - Monolith to micro-services with CQRS & Event Sourcing (20)

Advance Microservice Patterns - Event Souring , CQRS
Advance Microservice Patterns - Event Souring , CQRSAdvance Microservice Patterns - Event Souring , CQRS
Advance Microservice Patterns - Event Souring , CQRS
 
Monitoring Containerized Micro-Services In Azure
Monitoring Containerized Micro-Services In AzureMonitoring Containerized Micro-Services In Azure
Monitoring Containerized Micro-Services In Azure
 
Cloudsolutionday 2016: Docker & FAAS at getvero.com
Cloudsolutionday 2016: Docker & FAAS at getvero.comCloudsolutionday 2016: Docker & FAAS at getvero.com
Cloudsolutionday 2016: Docker & FAAS at getvero.com
 
OOSE UNIT-1.pdf
OOSE UNIT-1.pdfOOSE UNIT-1.pdf
OOSE UNIT-1.pdf
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
Data Microservices with Spring Cloud
Data Microservices with Spring CloudData Microservices with Spring Cloud
Data Microservices with Spring Cloud
 
Evolving to Cloud-Native - Nate Schutta 2/2
Evolving to Cloud-Native - Nate Schutta 2/2Evolving to Cloud-Native - Nate Schutta 2/2
Evolving to Cloud-Native - Nate Schutta 2/2
 
Evolving to Cloud-Native - Nate Schutta (2/2)
Evolving to Cloud-Native - Nate Schutta (2/2)Evolving to Cloud-Native - Nate Schutta (2/2)
Evolving to Cloud-Native - Nate Schutta (2/2)
 
Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201
Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201
Smaller is Better - Exploiting Microservice Architectures on AWS - Technical 201
 
Embracing Failure - AzureDay Rome
Embracing Failure - AzureDay RomeEmbracing Failure - AzureDay Rome
Embracing Failure - AzureDay Rome
 
From prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.ioFrom prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.io
 
The challenges of live events scalability
The challenges of live events scalabilityThe challenges of live events scalability
The challenges of live events scalability
 
Week 4 Assignment - Software Development PlanScenario-Your team has be.docx
Week 4 Assignment - Software Development PlanScenario-Your team has be.docxWeek 4 Assignment - Software Development PlanScenario-Your team has be.docx
Week 4 Assignment - Software Development PlanScenario-Your team has be.docx
 
ravi kumar s
ravi kumar sravi kumar s
ravi kumar s
 
QCon 2015 - Microservices Track Notes
QCon 2015 - Microservices Track Notes QCon 2015 - Microservices Track Notes
QCon 2015 - Microservices Track Notes
 
Over view of software artitecture
Over view of software artitectureOver view of software artitecture
Over view of software artitecture
 
[WSO2Con USA 2018] Nightmare on SSO Street
[WSO2Con USA 2018] Nightmare on SSO Street[WSO2Con USA 2018] Nightmare on SSO Street
[WSO2Con USA 2018] Nightmare on SSO Street
 
Automation, Audits, and Apps Tour
Automation, Audits, and Apps TourAutomation, Audits, and Apps Tour
Automation, Audits, and Apps Tour
 
How to Migrate Applications Off a Mainframe
How to Migrate Applications Off a MainframeHow to Migrate Applications Off a Mainframe
How to Migrate Applications Off a Mainframe
 
Micro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMicro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - Plansoft
 

Último

Crushers to screens in aggregate production
Crushers to screens in aggregate productionCrushers to screens in aggregate production
Crushers to screens in aggregate productionChinnuNinan
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...Erbil Polytechnic University
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communicationpanditadesh123
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
BSNL Internship Training presentation.pptx
BSNL Internship Training presentation.pptxBSNL Internship Training presentation.pptx
BSNL Internship Training presentation.pptxNiranjanYadav41
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Crystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptxCrystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptxachiever3003
 
Risk Management in Engineering Construction Project
Risk Management in Engineering Construction ProjectRisk Management in Engineering Construction Project
Risk Management in Engineering Construction ProjectErbil Polytechnic University
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 

Último (20)

Crushers to screens in aggregate production
Crushers to screens in aggregate productionCrushers to screens in aggregate production
Crushers to screens in aggregate production
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communication
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
BSNL Internship Training presentation.pptx
BSNL Internship Training presentation.pptxBSNL Internship Training presentation.pptx
BSNL Internship Training presentation.pptx
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Crystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptxCrystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptx
 
Risk Management in Engineering Construction Project
Risk Management in Engineering Construction ProjectRisk Management in Engineering Construction Project
Risk Management in Engineering Construction Project
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 

2017 Melbourne YOW! CTO Summit - Monolith to micro-services with CQRS & Event Sourcing

  • 1. monolith to micro-services?
 event sourcing can help Doug English
  • 2. legacy 
 Culture Amp (2012 - 2015) Client Rails App
 (Murmur) Query Server DB Read-write Read-only
  • 3. Our journey Our meandering path to CQRS & event sourcing • Attempt 1 - Asynchronous micro-services
 Event Log the monolith and introduce query services
 • Attempt 2 - Greenfield systems of record
 Rebuild part of the monolith as a stand alone command side service
 • Attempt 3 - Refactor the monolith first 
 And start with the least depended upon aggregates
  • 4. Attempt 1: Asynchronous Micro-services Why micro-services? • Too many developers! • Monolith was becoming too complex. • Want teams to control their own assets. • Flexibility to introduce fit for purpose technologies.
 (for example, elastic search for our comments search) • Scale different parts of the app independently.
 (for example, capture has a very different profile)
  • 5. Attempt 1: Asynchronous Micro-services Why asynchronous? • Resilience is architected into the platform. 
 If a micro-service is down, all depended micro-services remain available 
 and are eventually consistent. Also protects yourself from self inflicted DOS. • Ability to replay history for consuming services
 Much easier to refactor, or to introduce new services. • Decoupled architecture enabling platform flexibility 
 Consumers don’t necessarily need to know where the producers are deployed
  • 6. Reporting Service Client Rails App
 (Murmur) Query Server DB Read-write Read-only Reporting
 Service Event
 Log
  • 7. What went wrong • Plagued with bad data issues as we tried to convert
 our current production database to a stream of events • Ongoing source-of-truth issues between the 
 monolith persistence layer and the synthesised event log. • Events were generated at the wrong business points
 intended for consumption but ironically problematic for consumers • Events were too coarse-grained and slow to process. • Some of the events weren't real business events. • Multiple event streams - one for each event type - hurt. 

  • 8. What we learned Asynchronous micro-services are the 
 right long term aim. But, don’t start with event consumers,
 start with event producers. Event logging is not event sourcing!
  • 9. What is 
 Event Sourcing? Add Employee A Add Employee B Remove Employee A Add Employee C Add Employee B Add Employee C • Store the business events as the source of truth • Can answer questions you don’t yet know you have. • Legal, accounting, traditional professions have used 
 event sourcing for centuries.
  • 10. Every method should either be a command that performs an action, or a query that returns data to the caller, but
 not both. In other words, asking a question should not 
 change the answer. — Bertrand Meyer (designer of Eiffel language) on CQS “
  • 11. Command Query Responsibility Segregation What is CQRS? Without CQRS With CQRS EmployeeService + createEmployee(employee): void
 + getEmployee(id): Employee
 + updateEmployeeName(id, name): void
 + makeEmployeeAdmin(id) : void
 + getEmployees(account): List<Employee>
 EmployeeReadService + getEmployee(id): Employee
 + getEmployees(account): List<Employee> EmployeeWriteService + createEmployee(employee): void
 + updateEmployeeName(id, name): void
 + makeEmployeeAdmin(id) : void
  • 12. CQRS & 
 event sourcing
 architecture Client Command Handler Aggregate event
 store Projection Query Handler Eventually
 consistent!
  • 13. Attempt 2: Greenfield systems of record Client Rails App
 (Murmur) Query Server DB Reporting
 Service Event
 Store Employee
 SoR Projector Event
 Log
  • 14. What worked well? • CQRS and event sourcing helped us be clear about the
 boundaries of context. • The new service owns the validation, so bad data issues 
 in accounts we migrated were found and fixed upfront • We could treat the monolith as one massive projection
 minimising work required on the Query side, and UI. • Removed our source of truth problems. 
 Domain models can be deterministically built from events, not vice versa. • We could incrementally migrate accounts
  • 15. What didn’t work well? • Required a leap of faith for the team to agree to try. • Slow to develop as we were learning a new paradigm,
 and rolling our own event sourcing system. • Eventual consistency hurts: • Upfront we needed to solve how to update 
 the monolith in a reasonable timeframe. • We needed to refactor parts of the UI to cope
 with the eventual consistency. • Disaster recovery becomes a distributed problem.
  • 16. With all the troubles of evented architecture - it is a blessing when "shit hits the fan”.
 
 I don't know if in the past we would even be able to tell the customers affected by the issue. — Unsolicited feedback from our 
 Tech Lead for the Employee Service “
  • 17. 1. Start with the Command Side.
 Treat your existing application like one big projection. 2. Tackle a single Aggregate at a time.
 No need for a big-bang migration. 3. Generate UUIDS in the legacy monolith first. 
 These will help you link the migration scripts back. 4. Start by synchronously updating your existing application.
 Your legacy UI will thank you for it. 5. When all writes are through CQRS Commands, refactor 
 the UI to use new dedicated asynchronous projections. 6. When nothing still uses the legacy domain model, 
 remove it and remove it’s synchronous projector. Attempt 3: 
 Refactor the monolith first
  • 18. Account Survey Response Comment Question Employee Identifying 
 aggregates * * * * *1 1 1 1 1 Report * 1 ActionItem*1 Demographic* 1 Start Here!
  • 19. Monolith 
 phase 1 Client Survey 
 C Handler Survey
 Aggregate Event Store Legacy
 Domain Models Participant 
 C Handler Participant
 Aggregate Comment 
 C Handler Comment
 Aggregate Legacy
 DBProjector Monolith Rails Controllers Synchronous 
 update!
  • 20. Monolith
 phase 2 Client Survey 
 C Handler Survey
 Aggregate PostGres Question 
 C Handler Question
 Aggregate Participant 
 C Handler Participant
 Aggregate Projection Authentication layer Client Client Projection Query
 handler Query
 handler Projector Asynchronous 
 updates Projector
  • 21. Beyond the monolith Employees
 Service Ratings
 Analitycs Text Analytics Data Labs
 Experiments Message Bus Capture
 Service Survey
 Designer Account
 Admin Email
 Sender Data
 Warehouse Public
 APIs
  • 22. Key learnings 1. Event Logging is not event sourcing 
 and just leads to source of truth confusion. 2. CQRS and event sourcing can help you move to 
 micro-services, but start by refactoring the monolith 3. If you choose to event source your monolith, take 
 one step at a time, and focus on the command side.