SlideShare a Scribd company logo
EVENTS IN A
MICROSERVICES
ARCHITECTURE
HOW EVENT DRIVEN ARCHITECTURE COMPLEMENTS MICROSERVICES
MICROSERVICES FTW
• Autonomous
• Independently deployable
• Independently scalable
• Loosely coupled
• Fault tolerant
• Distributed
CONSISTENCY IS A CHALLENGE
• In a distributed architecture
• Each service with its own database
• How to maintain a consistent view of the world?
This is not just a microservices problem…
CONSISTENCY IS A CHALLENGE
• In a distributed architecture
• Each service with its own database
• How to maintain a consistent view of the world?
This is not just a microservices problem…
CONSISTENCY IS A CHALLENGE
• In a distributed architecture
• Each service with its own database
• How to maintain a consistent view of the world?
This is not just a microservices problem…
CONSISTENCY IS A CHALLENGE
• In a distributed architecture
• Each service with its own database
• How to maintain a consistent view of the world?
This is not just a microservices problem…
CONSISTENCY IS A CHALLENGE
• In a distributed architecture
• Each service with its own database
• How to maintain a consistent view of the world?
This is not just a microservices problem…
CONSISTENCY IS A CHALLENGE
• In a distributed architecture
• Each service with its own database
• How to maintain a consistent view of the world?
This is not just a microservices problem…
CONSISTENCY IS A CHALLENGE
• In a distributed architecture
• Each service with its own database
• How to maintain a consistent view of the world?
This is not just a microservices problem…
CONSISTENCY IS A CHALLENGE
• Distributed architecture
• Each service with its own database
• How to maintain a consistent view of the world?
This is not just a microservices problem…
THE 8 FALLACIES OF DISTRIBUTED SYSTEMS
• The network is reliable – calls over the network will fail
• Latency is zero – calls over the network take longer
• Bandwidth is infinite – bandwidth may limit or delay data movement
• The network is secure – you cannot trust all requests
• Topology doesn't change – constant topology changes require sophisticated routing and service
discovery
• There is one administrator – systems must be loosely coupled with sophisticated monitoring
• Transport cost is zero – marshalling carries a cost
• The network is homogeneous – different systems have different interfaces, protocols, data
representations
…. Distributed systems are HARD
API’S HAVE DRAWBACKS
• What happens if a service is offline (e.g. network partition)?
• Can build in redundancy, but:
• Redundancy doesn’t guarantee consistency
• Redundancy can be expensive
• Need complicated clustering protocols
• Need complicated consistency or cache-management protocols
OPTION: REDUNDANCY
Customer Inventory
Payments
Logistics
Marketing Orders
• Complicated protocols to coordinate services
• Sharding, master/slave, failover, etc
• Need to maintain consistency across redundant copies
OPTION: CACHING
Customer Inventory
PaymentsLogistics
Marketing Orders
• The two hardest problems in computer science
• Naming things
• Cache invalidation
• You need protocols to maintain consistency between master and cache
OPTION: OPERATIONAL
DATA STORE
Customer Inventory
PaymentsLogistics
Marketing Orders
• Each service holds a copy of the data it needs to do its work
• How to maintain consistency across those copies?
CAP THEOREM
Consistency
Availability Partition Tolerance
Choose any two…
CAP THEOREM
Consistency
Availability Partition Tolerance
Choose any two…
CAP THEOREM
Consistency
Availability Partition Tolerance
Choose any two…
CAP THEOREM
Consistency
Availability Partition Tolerance
Choose any two…
CAP THEOREM
Consistency
Availability Partition Tolerance
Choose any two…
CAP THEOREM
Consistency
Availability Partition Tolerance
Choose any two…
THERE ARE THREE TYPES OF SERVICE INTERACTION
• Command – action to change the state of a resource
• Query – request to give the current state of a resource
• Event – notify a change in state for a resource
• Events are often asynchronous (but not always – e.g. an RSS feed is a list of events obtained by query)
An event is a notification that something has happened
Command /
Query
Event
Interaction Style Synchronous Asynchronous
Consistency STRONG EVENTUAL
Temporal coupling HIGH LOW
Consumer coupling HIGH LOW
Visibility / Traceability GOOD POOR
Security BETTER WORSE
COMMANDS, QUERIES & EVENTS – TRADE-OFFS
Consider these trade-offs when designing
process coordination:
• Orchestration vs
• Choreography
Orchestration provides better visibility &
strong consistency at the cost of tighter
coupling.
Choreography is more loosely coupled but
has poor visibility and only guarantees
eventual consistency.
Active
Create order
Add itemRemove item
Add shipping address
Confirmed
Payment
accepted
Cancelled
Payment
declined
Quoted
Offer payment
Operation Command Event
Create order POST /orders Order created
Add item POST /orders/7e15449c/items Item added
Remove item DELETE /orders/7e15449c/items/3 Item removed
Add address PUT /orders/7e15449c
Offer payment POST /payments
Pmnt accepted
Pmnt declined
Order confirmed
Cancel order DELETE /orders/7e15449c Order cancelled
COMMANDS & EVENTS
Customer
InventoryPayments
Logistics
Marketing
Orders
BOOKSTORE EVENTS
Order created
Item added/removed
Order Confirmed
Payment confirmed
Payment declined
Order shipped
Order delivered
Order returned
Customer logged-in
Customer logged-out
Inventory low
Out of stock
Inventory replenished
Publisher Events Subscribers
Offers
Publisher Events Subscribers
EVENT SOURCING
A pattern where you derive the current state of a resource from its
history (ordered sequence of events).
Useful because events are immutable – means you can recover
the current state at any point in time.
Event Type Order ID Item ID
Add Item 7e15449c 5707255e
Add Item 7e15449c 491addd0
Confirm order 7e15449c
Create order 85c6ce51
Add item 85c6ce51 5707255e
Confirm order 85c6ce51
Order Stream Item ID Count
5707255e 6
491addd0 50
Item ID Count
5707255e 5
491addd0 49
Item ID Count
5707255e 4
491addd0 49
Inventory
Event Type Item ID
Low inventory 5707255e
DESIGN & MANAGE STREAMS LIKE APIS
• Events and APIs are complementary
• Manage your events in the same way that
you manage APIs
• Think about developer experience for event
streams consumers
• Make streams discoverable and self-service
• Design event streams “outside in”
• Implement version and lifecycle management
for streams
• Async API is an opensource project which
brings API concepts to event streams
https://asyncapi.io
CONCLUSION
• You have three awesome tools in your distributed systems tool-box: commands, queries and events
• Events provide loose-coupling at the cost of eventual consistency
• Events are a great way to communicate state across bounded contexts (e.g. domain boundaries)
• Events help communicate state across your information landscape – leads to better resilience and
evolvability
• Use commands and queries to provide strong consistency at the risk of tighter coupling

More Related Content

What's hot

WSO2Con USA 2017: Providing a Pathway from Stovepipe Systems to a Secure SOA ...
WSO2Con USA 2017: Providing a Pathway from Stovepipe Systems to a Secure SOA ...WSO2Con USA 2017: Providing a Pathway from Stovepipe Systems to a Secure SOA ...
WSO2Con USA 2017: Providing a Pathway from Stovepipe Systems to a Secure SOA ...
WSO2
 

What's hot (20)

Microservice architecture case study
Microservice architecture case studyMicroservice architecture case study
Microservice architecture case study
 
How iPaaS Overcomes the Challenges of Cloud Integration
How iPaaS Overcomes the Challenges of Cloud IntegrationHow iPaaS Overcomes the Challenges of Cloud Integration
How iPaaS Overcomes the Challenges of Cloud Integration
 
What are Software Defined Application Services
What are Software Defined Application ServicesWhat are Software Defined Application Services
What are Software Defined Application Services
 
Webinar: Accelerate Business Automation with APPSeCONNECT iPaaS
Webinar: Accelerate Business Automation with APPSeCONNECT iPaaSWebinar: Accelerate Business Automation with APPSeCONNECT iPaaS
Webinar: Accelerate Business Automation with APPSeCONNECT iPaaS
 
Multi Team Architecture
Multi Team ArchitectureMulti Team Architecture
Multi Team Architecture
 
Who's Who in Container Land
Who's Who in Container LandWho's Who in Container Land
Who's Who in Container Land
 
Oscon2014 Netflix API - Top 10 Lessons Learned
Oscon2014 Netflix API - Top 10 Lessons LearnedOscon2014 Netflix API - Top 10 Lessons Learned
Oscon2014 Netflix API - Top 10 Lessons Learned
 
Webinar: Embracing REST APIs through APPSeCONNECT
Webinar: Embracing REST APIs through APPSeCONNECTWebinar: Embracing REST APIs through APPSeCONNECT
Webinar: Embracing REST APIs through APPSeCONNECT
 
Grokking microservices in 5 minutes
Grokking microservices in 5 minutesGrokking microservices in 5 minutes
Grokking microservices in 5 minutes
 
Building Highly Scalable Apps On Bluemix
Building Highly Scalable Apps On BluemixBuilding Highly Scalable Apps On Bluemix
Building Highly Scalable Apps On Bluemix
 
Customer-centric Metrics
Customer-centric MetricsCustomer-centric Metrics
Customer-centric Metrics
 
WSO2Con EU 2016: On the dot – Deliveries When You Want Them
WSO2Con EU 2016: On the dot – Deliveries When You Want ThemWSO2Con EU 2016: On the dot – Deliveries When You Want Them
WSO2Con EU 2016: On the dot – Deliveries When You Want Them
 
Will ServerLess kill containers and Operations
Will ServerLess kill containers and OperationsWill ServerLess kill containers and Operations
Will ServerLess kill containers and Operations
 
Webinar: APPSeCONNECT iPaaS Q3 2020 Release - Major Highlights and Walkthrough
Webinar: APPSeCONNECT iPaaS Q3 2020 Release - Major Highlights and WalkthroughWebinar: APPSeCONNECT iPaaS Q3 2020 Release - Major Highlights and Walkthrough
Webinar: APPSeCONNECT iPaaS Q3 2020 Release - Major Highlights and Walkthrough
 
The Serverless Native Mindset: Ben Kehoe, iRobot, Serverless NYC 2018
The Serverless Native Mindset: Ben Kehoe, iRobot, Serverless NYC 2018The Serverless Native Mindset: Ben Kehoe, iRobot, Serverless NYC 2018
The Serverless Native Mindset: Ben Kehoe, iRobot, Serverless NYC 2018
 
Microservices: an introduction
Microservices: an introductionMicroservices: an introduction
Microservices: an introduction
 
WSO2Con USA 2017: Providing a Pathway from Stovepipe Systems to a Secure SOA ...
WSO2Con USA 2017: Providing a Pathway from Stovepipe Systems to a Secure SOA ...WSO2Con USA 2017: Providing a Pathway from Stovepipe Systems to a Secure SOA ...
WSO2Con USA 2017: Providing a Pathway from Stovepipe Systems to a Secure SOA ...
 
When small problems become big problems
When small problems become big problemsWhen small problems become big problems
When small problems become big problems
 
Enterprise Architecture in Practice: from Datastore to APIs and Apps
Enterprise Architecture in Practice: from Datastore to APIs and AppsEnterprise Architecture in Practice: from Datastore to APIs and Apps
Enterprise Architecture in Practice: from Datastore to APIs and Apps
 
The Most Common Errors That Aren’t Caught
The Most Common Errors That Aren’t CaughtThe Most Common Errors That Aren’t Caught
The Most Common Errors That Aren’t Caught
 

Similar to Events in a microservices architecture

Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)
Rick Hightower
 

Similar to Events in a microservices architecture (20)

Patterns of Distributed Application Design
Patterns of Distributed Application DesignPatterns of Distributed Application Design
Patterns of Distributed Application Design
 
Patterns of Distributed Application Design
Patterns of Distributed Application DesignPatterns of Distributed Application Design
Patterns of Distributed Application Design
 
Iot cloud service v2.0
Iot cloud service v2.0Iot cloud service v2.0
Iot cloud service v2.0
 
Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)
 
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
 
Introduction-to-Cloud-Computing.pdf
Introduction-to-Cloud-Computing.pdfIntroduction-to-Cloud-Computing.pdf
Introduction-to-Cloud-Computing.pdf
 
Service Fabric – building tomorrows applications today
Service Fabric – building tomorrows applications todayService Fabric – building tomorrows applications today
Service Fabric – building tomorrows applications today
 
Alex Thissen (Xpirit) - Een verschuiving in architectuur: op weg naar microse...
Alex Thissen (Xpirit) - Een verschuiving in architectuur: op weg naar microse...Alex Thissen (Xpirit) - Een verschuiving in architectuur: op weg naar microse...
Alex Thissen (Xpirit) - Een verschuiving in architectuur: op weg naar microse...
 
Concurrency at Scale: Evolution to Micro-Services
Concurrency at Scale:  Evolution to Micro-ServicesConcurrency at Scale:  Evolution to Micro-Services
Concurrency at Scale: Evolution to Micro-Services
 
Hard Truths About Streaming and Eventing (Dan Rosanova, Microsoft) Kafka Summ...
Hard Truths About Streaming and Eventing (Dan Rosanova, Microsoft) Kafka Summ...Hard Truths About Streaming and Eventing (Dan Rosanova, Microsoft) Kafka Summ...
Hard Truths About Streaming and Eventing (Dan Rosanova, Microsoft) Kafka Summ...
 
Service Mesh Talk for CTO Forum
Service Mesh Talk for CTO ForumService Mesh Talk for CTO Forum
Service Mesh Talk for CTO Forum
 
Event Driven Architectures - Net Conf UY 2018
Event Driven Architectures - Net Conf UY 2018Event Driven Architectures - Net Conf UY 2018
Event Driven Architectures - Net Conf UY 2018
 
Surviving as a Monolith in a Microservices World - by Blair Olynyk, Hyperwallet
Surviving as a Monolith in a Microservices World - by Blair Olynyk, HyperwalletSurviving as a Monolith in a Microservices World - by Blair Olynyk, Hyperwallet
Surviving as a Monolith in a Microservices World - by Blair Olynyk, Hyperwallet
 
Scaling Systems: Architectures that grow
Scaling Systems: Architectures that growScaling Systems: Architectures that grow
Scaling Systems: Architectures that grow
 
Why Distributed Databases?
Why Distributed Databases?Why Distributed Databases?
Why Distributed Databases?
 
Effective Microservices In a Data-centric World
Effective Microservices In a Data-centric WorldEffective Microservices In a Data-centric World
Effective Microservices In a Data-centric World
 
Hard Truths About Streaming and Eventing (Dan Rosanova, Microsoft) Kafka Summ...
Hard Truths About Streaming and Eventing (Dan Rosanova, Microsoft) Kafka Summ...Hard Truths About Streaming and Eventing (Dan Rosanova, Microsoft) Kafka Summ...
Hard Truths About Streaming and Eventing (Dan Rosanova, Microsoft) Kafka Summ...
 
Azure servicefabric
Azure servicefabricAzure servicefabric
Azure servicefabric
 
CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event Sourcing
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
 

More from Saul Caganoff

More from Saul Caganoff (7)

Microservices: The View from the Peak of Expectations
Microservices: The View from the Peak of ExpectationsMicroservices: The View from the Peak of Expectations
Microservices: The View from the Peak of Expectations
 
Serverless Architecture
Serverless ArchitectureServerless Architecture
Serverless Architecture
 
Automating Business Processes with APIs
Automating Business Processes with APIsAutomating Business Processes with APIs
Automating Business Processes with APIs
 
Events and microservices
Events and microservicesEvents and microservices
Events and microservices
 
Docker in the Enterprise
Docker in the EnterpriseDocker in the Enterprise
Docker in the Enterprise
 
Delivering the Composable Enterprise
Delivering the Composable EnterpriseDelivering the Composable Enterprise
Delivering the Composable Enterprise
 
Melbourne Microservices Meetup: Agenda for a new Architecture
Melbourne Microservices Meetup: Agenda for a new ArchitectureMelbourne Microservices Meetup: Agenda for a new Architecture
Melbourne Microservices Meetup: Agenda for a new Architecture
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 

Events in a microservices architecture

  • 1. EVENTS IN A MICROSERVICES ARCHITECTURE HOW EVENT DRIVEN ARCHITECTURE COMPLEMENTS MICROSERVICES
  • 2. MICROSERVICES FTW • Autonomous • Independently deployable • Independently scalable • Loosely coupled • Fault tolerant • Distributed
  • 3. CONSISTENCY IS A CHALLENGE • In a distributed architecture • Each service with its own database • How to maintain a consistent view of the world? This is not just a microservices problem…
  • 4. CONSISTENCY IS A CHALLENGE • In a distributed architecture • Each service with its own database • How to maintain a consistent view of the world? This is not just a microservices problem…
  • 5. CONSISTENCY IS A CHALLENGE • In a distributed architecture • Each service with its own database • How to maintain a consistent view of the world? This is not just a microservices problem…
  • 6. CONSISTENCY IS A CHALLENGE • In a distributed architecture • Each service with its own database • How to maintain a consistent view of the world? This is not just a microservices problem…
  • 7. CONSISTENCY IS A CHALLENGE • In a distributed architecture • Each service with its own database • How to maintain a consistent view of the world? This is not just a microservices problem…
  • 8. CONSISTENCY IS A CHALLENGE • In a distributed architecture • Each service with its own database • How to maintain a consistent view of the world? This is not just a microservices problem…
  • 9. CONSISTENCY IS A CHALLENGE • In a distributed architecture • Each service with its own database • How to maintain a consistent view of the world? This is not just a microservices problem…
  • 10. CONSISTENCY IS A CHALLENGE • Distributed architecture • Each service with its own database • How to maintain a consistent view of the world? This is not just a microservices problem…
  • 11. THE 8 FALLACIES OF DISTRIBUTED SYSTEMS • The network is reliable – calls over the network will fail • Latency is zero – calls over the network take longer • Bandwidth is infinite – bandwidth may limit or delay data movement • The network is secure – you cannot trust all requests • Topology doesn't change – constant topology changes require sophisticated routing and service discovery • There is one administrator – systems must be loosely coupled with sophisticated monitoring • Transport cost is zero – marshalling carries a cost • The network is homogeneous – different systems have different interfaces, protocols, data representations …. Distributed systems are HARD
  • 12. API’S HAVE DRAWBACKS • What happens if a service is offline (e.g. network partition)? • Can build in redundancy, but: • Redundancy doesn’t guarantee consistency • Redundancy can be expensive • Need complicated clustering protocols • Need complicated consistency or cache-management protocols
  • 13. OPTION: REDUNDANCY Customer Inventory Payments Logistics Marketing Orders • Complicated protocols to coordinate services • Sharding, master/slave, failover, etc • Need to maintain consistency across redundant copies
  • 14. OPTION: CACHING Customer Inventory PaymentsLogistics Marketing Orders • The two hardest problems in computer science • Naming things • Cache invalidation • You need protocols to maintain consistency between master and cache
  • 15. OPTION: OPERATIONAL DATA STORE Customer Inventory PaymentsLogistics Marketing Orders • Each service holds a copy of the data it needs to do its work • How to maintain consistency across those copies?
  • 16. CAP THEOREM Consistency Availability Partition Tolerance Choose any two… CAP THEOREM Consistency Availability Partition Tolerance Choose any two…
  • 17. CAP THEOREM Consistency Availability Partition Tolerance Choose any two… CAP THEOREM Consistency Availability Partition Tolerance Choose any two…
  • 18. CAP THEOREM Consistency Availability Partition Tolerance Choose any two… CAP THEOREM Consistency Availability Partition Tolerance Choose any two…
  • 19. THERE ARE THREE TYPES OF SERVICE INTERACTION • Command – action to change the state of a resource • Query – request to give the current state of a resource • Event – notify a change in state for a resource • Events are often asynchronous (but not always – e.g. an RSS feed is a list of events obtained by query) An event is a notification that something has happened
  • 20. Command / Query Event Interaction Style Synchronous Asynchronous Consistency STRONG EVENTUAL Temporal coupling HIGH LOW Consumer coupling HIGH LOW Visibility / Traceability GOOD POOR Security BETTER WORSE COMMANDS, QUERIES & EVENTS – TRADE-OFFS Consider these trade-offs when designing process coordination: • Orchestration vs • Choreography Orchestration provides better visibility & strong consistency at the cost of tighter coupling. Choreography is more loosely coupled but has poor visibility and only guarantees eventual consistency.
  • 21. Active Create order Add itemRemove item Add shipping address Confirmed Payment accepted Cancelled Payment declined Quoted Offer payment Operation Command Event Create order POST /orders Order created Add item POST /orders/7e15449c/items Item added Remove item DELETE /orders/7e15449c/items/3 Item removed Add address PUT /orders/7e15449c Offer payment POST /payments Pmnt accepted Pmnt declined Order confirmed Cancel order DELETE /orders/7e15449c Order cancelled COMMANDS & EVENTS
  • 22. Customer InventoryPayments Logistics Marketing Orders BOOKSTORE EVENTS Order created Item added/removed Order Confirmed Payment confirmed Payment declined Order shipped Order delivered Order returned Customer logged-in Customer logged-out Inventory low Out of stock Inventory replenished Publisher Events Subscribers Offers Publisher Events Subscribers
  • 23. EVENT SOURCING A pattern where you derive the current state of a resource from its history (ordered sequence of events). Useful because events are immutable – means you can recover the current state at any point in time. Event Type Order ID Item ID Add Item 7e15449c 5707255e Add Item 7e15449c 491addd0 Confirm order 7e15449c Create order 85c6ce51 Add item 85c6ce51 5707255e Confirm order 85c6ce51 Order Stream Item ID Count 5707255e 6 491addd0 50 Item ID Count 5707255e 5 491addd0 49 Item ID Count 5707255e 4 491addd0 49 Inventory Event Type Item ID Low inventory 5707255e
  • 24. DESIGN & MANAGE STREAMS LIKE APIS • Events and APIs are complementary • Manage your events in the same way that you manage APIs • Think about developer experience for event streams consumers • Make streams discoverable and self-service • Design event streams “outside in” • Implement version and lifecycle management for streams • Async API is an opensource project which brings API concepts to event streams https://asyncapi.io
  • 25. CONCLUSION • You have three awesome tools in your distributed systems tool-box: commands, queries and events • Events provide loose-coupling at the cost of eventual consistency • Events are a great way to communicate state across bounded contexts (e.g. domain boundaries) • Events help communicate state across your information landscape – leads to better resilience and evolvability • Use commands and queries to provide strong consistency at the risk of tighter coupling