SlideShare a Scribd company logo
Events & Microservices
Saul	
  Caganoff,	
  CTO	
  Sixtree
saul@sixtree.com.au
@scaganoff
Introduction
• Asynchrony	
  is	
  considered	
  a	
  microservice	
  
characteristic
– But	
  not	
  often	
  discussed
• In	
  the	
  top	
  20	
  Google	
  results
– 7	
  mentioned	
  async/choreography	
  or	
  events
– 3	
  of	
  those	
  by	
  Chris	
  Richardson	
  or	
  Martin	
  Fowler
• Mostly	
  mentioned	
  in	
  passing
• Honourable	
  Mentions:
– http://www.infoq.com/articles/microservices-­‐intro
– http://highscalability.com/blog/2014/4/8/microservices-­‐not-­‐a-­‐free-­‐
lunch.html
WHY EVENTS?
Bounded Contexts
Finance
Sales
Fulfilment
Product
Online	
  bookstore	
  is	
  
the	
  “Hello	
  World”	
  of	
  
enterprise	
  systems
http://maribyrnong.com.au
Sales Context
Wishlist
Book
ISBN
Title
Author
Price
Order
Status
Timestamp
Sub-­‐total
GST
Total
Item
Quantity
History
Customer
Name
Age
Loyalty	
  Status
Finance Context
Wishlist
Book
ISBN
Title
Author
Price
Order
Status
Timestamp
Sub-­‐total
GST
Total
Item
Quantity
History
Customer
Name
Age
Loyalty	
  Status
Credit	
  Card
Holder	
  Name
Number
Expiry
Code
Fulfilment Context
Book
ISBN
Title
Customer
Name
Receipt
Order	
  Number
Sub-­‐total
GST
Total
Address
Street	
  Number
Street	
  Name
Suburb
Postcode
Courier
Depot
Location
Driver
Shipment
Dispatch	
  Time
ETA
Location
Product Context
Book Description
Abstract
Picture
Review
Author
Name
Biography
Inventory
Location
Quantity
ISBN
Title
Price
Coupling & Cohesion
• Cohesion – how	
  well	
  a	
  subsystem	
  forms	
  a	
  
uniting	
  whole
– How	
  well	
  a	
  bounded	
  context	
  does	
  its	
  job
• Coupling – the	
  propensity	
  for	
  change	
  in	
  one	
  
part	
  of	
  a	
  system	
  to	
  disrupt	
  another
– how	
  badly	
  “stuff”	
  leaks	
  across	
  the	
  boundaries
• Coupling	
  is	
  evil	
  – it	
  sneaks	
  into	
  solutions	
  in	
  all	
  
kinds	
  of	
  insidious	
  ways
Events and microservices
Coupling & Cohesion
• Microservices strive to	
  eliminate	
  coupling
• Insidious	
  sources	
  of	
  coupling
– Shared	
  databases
– Single	
  Common	
  Data	
  Model	
  (vs	
  bounded	
  contexts)
– DRY	
  – shared	
  code
– APIs	
  generated	
  from	
  code
– Autogenerated client	
  SDKs
– Projects	
  – funding	
  and	
  scope
– Assumptions	
  about	
  business	
  processes
– Organizational	
  structure
Business Processes
• End-­‐to-­‐end	
  business	
  processes	
  require	
  
coordination	
  across	
  bounded	
  contexts
Finance
Sales
Ful-­‐
filment
Product
Business Processes
• Browse	
  the	
  inventory
• Create	
  order
• Enter	
  Shipping	
  Details
• Quote	
  shipping	
  charge
• Make	
  the	
  payment
• Update	
  inventory
• Create	
  Shipment
• Pick	
  &	
  Pack
• Courier
• Accept	
  delivery
GET	
  /products
POST	
  /order
PUT	
  /order/:id/address
GET	
  /3pl/charges?zip=…
POST	
  /finance/payment?order=
POST	
  /products
POST	
  /3pl/shipment
GET	
  /3pl/shipment/:id
GET	
  /3pl/shipment/:id/address
PUT	
  /3pl/shipment/:id?status=
Business Processes
• Orchestration	
  
– Centralized	
  coordination
– E.g.	
  the	
  user-­‐agent,	
  BPM	
  engine,	
  service	
  facade
– the	
  “god”	
  object
• Hypermedia
– HATEOAS
– But	
  what	
  about	
  at	
  the	
  edges?
– How	
  much	
  should	
  one	
  BC	
  know	
  about	
  another	
  BC?
“microservices architecture	
  will	
  never	
  be	
  SOA	
  done	
  right	
  unless	
  it	
  means	
  building	
  
hypermedia	
  systems	
  of	
  microservices”	
  – Jason	
  Bloomberg
http://intellyx.com/2015/07/20/are-­‐microservices-­‐soa-­‐done-­‐right/
Some Perspective
0
2
4
6
8
10
12
DB	
  Triggers Monolith Orchestration Hypermedia EDA
Coupling
Data Synchronization
• How	
  to	
  handle	
  data	
  “owned”	
  by	
  multiple	
  
domains
– Glibness: “don’t”	
  have	
  multiple	
  data	
  owners
– …in	
  reality	
  it	
  is	
  impossible	
  to	
  eliminate
– …especially	
  if	
  legacy	
  or	
  COTS	
  systems	
  involved.
• Some	
  data	
  synchronization	
  is	
  naturally	
  
conveyed	
  by	
  the	
  business	
  process
• …some	
  is	
  not.
Choreography
• Use	
  events	
  to	
  coordinate	
  activity	
  across	
  bounded	
  
contexts
• Publishers	
  &	
  Subscribers	
  are	
  highly	
  decoupled
– Event	
  subscribers	
  can	
  come	
  &	
  go	
  minimal	
  or	
  no	
  code	
  
or	
  configuration	
  changes
• Publishers	
  &	
  Subscribers	
  are	
  more	
  resilient	
  to	
  
change	
  – either	
  planned	
  or	
  unplanned
– E.g.	
  events	
  redelivered	
  in	
  the	
  event	
  of	
  subscriber	
  
failure	
  – either	
  to	
  the	
  restored	
  subscriber,	
  or	
  a	
  
replacement
Choreography
• But	
  trade-­‐offs
• Asynchronous	
  events	
  lie	
  at	
  the	
  heart	
  of	
  some	
  of	
  
the	
  microservices challenges
– Centralised	
  orchestration	
  is	
  harder	
  to	
  change,	
  but	
  
easier	
  to	
  control/monitor
– Event-­‐based	
  choreography	
  is	
  easier	
  to	
  change	
  but	
  
harder	
  to	
  control/monitor
• Distributed	
  logging/monitoring	
  systems	
  are	
  
needed	
  to	
  provide	
  a	
  view	
  into	
  asynchronous	
  
interactions
Coordination
• Think	
  about	
  hypermedia	
  inside	
  boundaries
• Events	
  outside	
  the	
  boundaries
Finance
Sales
Ful-­‐
filment
Product
MODELLING EVENTS
Commands & Events
• Duality	
  between	
  commands	
  &	
  events
– Commands	
  cause	
  state	
  transitions
– Events	
  reflect	
  state	
  transitions
• An	
  external	
  observer	
  can	
  infer	
  the	
  state	
  of	
  a	
  
resource	
  from	
  its	
  event-­‐stream
– This	
  is	
  the	
  essence	
  of	
  event-­‐sourcing	
  &	
  CQRS
State Modelling
Empty
Cart
Full
Cart
Quoted
Paid
POST	
  /cart
PUT	
  /cart/:id
{	
  book:	
  …	
  }
PUT	
  /cart/:id
{	
  book:	
  …	
  }
DELETE	
  /cart/:id/books/:id
PUT	
  /cart/:id
{	
  address:	
  …	
  }
POST	
  /payments
{	
  cart:	
  …,	
  card:	
  {…}}
Commands	
  (HATEOAS)
{create:	
  {	
  cart:	
  …	
  }	
  …	
  }
{add:	
  {	
  cart:	
  …,	
  book:	
  {…}}	
  ..}
{add:	
  {	
  cart:	
  …,	
  book:	
  {…}}	
  ..}
{del:	
  {	
  cart:	
  …,	
  book:	
  {…}}	
  ..}
{quoted:	
  {	
  cart:	
  …	
  }	
  …	
  }
{paid:	
  {	
  cart:	
  …	
  }	
  …	
  }
Events	
  (EATNOAS)
Commands & Events
Finance
Sales
Ful-­‐
filment
Product
Inventory
Marketing
Commands
Events
Reporting
Logistics
Event Structure
• Immutable	
  structures
• Typical	
  properties
– Timestamp
– Source
– Entity	
  URI
– Action	
  (state	
  transition)
• The	
  MVP	
  is	
  to	
  notify	
  that	
  a	
  resource	
  has	
  
changed	
  and	
  allow	
  subscribers	
  to	
  pull	
  the	
  
update	
  if	
  needed.
Concurrency
• Race	
  Conditions
• The	
  importance	
  of	
  order
• Single	
  Master	
  vs	
  Multi-­‐Master
• Deltas	
  vs	
  Copies
• Action	
  indicators
• CRDTs	
  – conflict-­‐free	
  replicated	
  data	
  types
• …think	
  in	
  terms	
  of	
  events	
  rather	
  than	
  copies
EVENT TRANSPORTS
Syndication
• Service	
  exposes	
  an	
  RSS/atom	
  feed
• Consumers	
  do	
  all	
  the	
  hard	
  work:
– Subscription
– State	
  Management	
  (where	
  am	
  I	
  up	
  to?)
– Retries
• Positives
– Very	
  easy…well-­‐known	
  pattern
– Web-­‐scale
• Negatives
– Polling
– High	
  latency
Web Hooks
• Service	
  POSTs	
  events	
  to	
  subscribers
• Publishers	
  do	
  all	
  the	
  hard	
  work:
– Manage	
  subscribers
– Managed	
  guaranteed	
  delivery/	
  retries
• Positives
– Not	
  polling,	
  relatively	
  lower	
  latency
• Negatives
– Subscription	
  management	
  &	
  guaranteed	
  delivery	
  
must	
  be	
  done	
  yourself…can	
  be	
  tricky.
Message Queues
• Events	
  published	
  to	
  queues/topics
– E.g JMS,	
  AMQP,	
  ZMQ,	
  SQS/SNS,	
  IronMQ
• Positives
– Mature,	
  well-­‐known	
  technologies
– Good	
  open-­‐source	
  implementations	
  available
– Competing	
  consumer	
  pattern
• Negatives
– Extra	
  infrastructure
– Reliability	
  depends	
  on	
  reliable	
  file-­‐systems	
  
• SANs,	
  Distributed	
  file-­‐lock	
  managers
Apache Kafka
• Distributed	
  log
• Similar	
  model	
  to	
  syndication
– Single	
  node	
  shares	
  data	
  by	
  writing	
  to	
  logfiles
– Consumers	
  tail	
  the	
  logs
• Consumers	
  control	
  their	
  position	
  in	
  the	
  log
• Low	
  latency
• Reliability	
  handled	
  at	
  the	
  application	
  layer
– whether	
  Zookeeper	
  is	
  less	
  burdensome	
  than	
  clustered	
  
file	
  system	
  is	
  up	
  to	
  you
Event Processing
• Simple	
  events	
  are	
  very	
  useful	
  for	
  data	
  
synchronization	
  or	
  process	
  coordination
• Continuum	
  of	
  complexity
• Some	
  tools:	
  Drools,	
  Riemann.io,	
  Apache	
  Storm
• This	
  is	
  a	
  whole	
  ‘nother topic
Cardinality State Tools
Single	
  event Simple Event	
  processor
Multiple	
  events/stream Simple Stream	
  processor
Multiple	
  events/stream Complex	
  /	
  Rules Complex	
  Event	
  Processor
Wrap-Up
• Bounded	
  contexts	
  are	
  important
– they	
  promote	
  cohesion	
  and	
  reduce	
  coupling
• You	
  need	
  to	
  decide	
  how	
  to	
  coordinate	
  data	
  &	
  
processes	
  across	
  boundaries
– Orchestration	
  (relatively	
  higher	
  coupling)
– Hypermedia	
  (couples	
  across	
  boundaries)
– Events
• Prefer	
  Hypermedia	
  within	
  bounded	
  contexts	
  &	
  events	
  
across	
  bounded	
  contexts
Events	
  have	
  many	
  benefits	
  but	
  also	
  some	
  downsides	
  -­‐
they	
  are	
  an	
  important	
  tool	
  in	
  your	
  toolbox.

More Related Content

PPTX
Melbourne Microservices Meetup: Agenda for a new Architecture
PDF
Automating Business Processes with APIs
PDF
Microservices: The View from the Peak of Expectations
PPTX
API Management, Meet Event Management
PDF
The Event Mesh: real-time, event-driven, responsive APIs and beyond
PPTX
Financial Event Sourcing at Enterprise Scale
PPTX
PubSub+ Event Portal for Apache Kafka
PDF
DataOps on Streaming Data: From Kafka to InfluxDB via Kubernetes Native Flows...
Melbourne Microservices Meetup: Agenda for a new Architecture
Automating Business Processes with APIs
Microservices: The View from the Peak of Expectations
API Management, Meet Event Management
The Event Mesh: real-time, event-driven, responsive APIs and beyond
Financial Event Sourcing at Enterprise Scale
PubSub+ Event Portal for Apache Kafka
DataOps on Streaming Data: From Kafka to InfluxDB via Kubernetes Native Flows...

What's hot (20)

PPTX
Gartner event mesh solace - phil scanlon - gold coast
PDF
Using Kafka in Your Organization with Real-Time User Insights for a Customer ...
PDF
WJAX 2013 Slides online: Big Data beyond Apache Hadoop - How to integrate ALL...
PPT
Data center world 2010 10 5 10
PPTX
Event-driven Business: How Leading Companies Are Adopting Streaming Strategies
PDF
Fast Data for Competitive Advantage: 4 Steps to Expand your Window of Opportu...
PDF
Analytics Patterns for Your Digital Enterprise
PPTX
Analyzing Billions of Data Rows with Alteryx, Amazon Redshift, and Tableau
PPTX
The Streaming Assessment – An Introduction
PDF
Lighning Talk: Event-Driven architecture for microservices
PDF
WSO2Con USA 2017: Driving Insights for Your Digital Business With Analytics
PPTX
Hybrid & Global Kafka Architecture
PDF
Event-Driven Microservices with Apache Kafka, Kafka Streams and KSQL
PDF
Event Streaming in Retail with Apache Kafka
PDF
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
PDF
Confluent & MongoDB APAC Lunch & Learn
PDF
Apache Kafka Landscape for Automotive and Manufacturing
PDF
Data reply sneak peek: real time decision engines
PDF
Connecting Apache Kafka to Cash
PDF
Apache Kafka for Automotive Industry, Mobility Services & Smart City
Gartner event mesh solace - phil scanlon - gold coast
Using Kafka in Your Organization with Real-Time User Insights for a Customer ...
WJAX 2013 Slides online: Big Data beyond Apache Hadoop - How to integrate ALL...
Data center world 2010 10 5 10
Event-driven Business: How Leading Companies Are Adopting Streaming Strategies
Fast Data for Competitive Advantage: 4 Steps to Expand your Window of Opportu...
Analytics Patterns for Your Digital Enterprise
Analyzing Billions of Data Rows with Alteryx, Amazon Redshift, and Tableau
The Streaming Assessment – An Introduction
Lighning Talk: Event-Driven architecture for microservices
WSO2Con USA 2017: Driving Insights for Your Digital Business With Analytics
Hybrid & Global Kafka Architecture
Event-Driven Microservices with Apache Kafka, Kafka Streams and KSQL
Event Streaming in Retail with Apache Kafka
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Confluent & MongoDB APAC Lunch & Learn
Apache Kafka Landscape for Automotive and Manufacturing
Data reply sneak peek: real time decision engines
Connecting Apache Kafka to Cash
Apache Kafka for Automotive Industry, Mobility Services & Smart City
Ad

Viewers also liked (7)

PDF
Concevoir et déployer vos applications a base de microservices sur Cloud Foundry
PPTX
What's new in Pivotal Cloud Foundry 1.6
PPTX
Neuro4j Workflow Overview
PPTX
Breaking the Monolith
PDF
Building microservices with Scala, functional domain models and Spring Boot
PDF
The Journey from Monolith to Microservices: a Guided Adventure
PPTX
The Cloud Native Journey
Concevoir et déployer vos applications a base de microservices sur Cloud Foundry
What's new in Pivotal Cloud Foundry 1.6
Neuro4j Workflow Overview
Breaking the Monolith
Building microservices with Scala, functional domain models and Spring Boot
The Journey from Monolith to Microservices: a Guided Adventure
The Cloud Native Journey
Ad

Similar to Events and microservices (20)

PPTX
Events & Microservices
PDF
Moving To MicroServices
PDF
Event Sourcing, Stream Processing and Serverless (Benjamin Stopford, Confluen...
PDF
Introduction to Stream Processing
PDF
Stream Processing in Action
PPTX
Understanding event data
PPTX
WebAction In-Memory Computing Summit 2015
PDF
Smart Process Automation - Connected Brains 2018
PPT
Kafka-and-event-driven-architecture-OGYatra20.ppt
PPT
BigData & CDN - OOP2011 (Pavlo Baron)
PPTX
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
PDF
Kalix: Tackling the The Cloud to Edge Continuum
PDF
How to Realize the Benefits of Cloud Services Brokerage
PDF
Resource-Oriented Architecture (ROA)
PDF
Extending your applications to the edge with CDNs
PPTX
Crack the Domain with Event Storming By Vivek
PPTX
Kafka and event driven architecture -og yatra20
PPTX
Kafka and event driven architecture -apacoug20
PDF
Event Driven Architecture with a RESTful Microservices Architecture (Kyle Ben...
PDF
Responsive Innovation in a Local Context
Events & Microservices
Moving To MicroServices
Event Sourcing, Stream Processing and Serverless (Benjamin Stopford, Confluen...
Introduction to Stream Processing
Stream Processing in Action
Understanding event data
WebAction In-Memory Computing Summit 2015
Smart Process Automation - Connected Brains 2018
Kafka-and-event-driven-architecture-OGYatra20.ppt
BigData & CDN - OOP2011 (Pavlo Baron)
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
Kalix: Tackling the The Cloud to Edge Continuum
How to Realize the Benefits of Cloud Services Brokerage
Resource-Oriented Architecture (ROA)
Extending your applications to the edge with CDNs
Crack the Domain with Event Storming By Vivek
Kafka and event driven architecture -og yatra20
Kafka and event driven architecture -apacoug20
Event Driven Architecture with a RESTful Microservices Architecture (Kyle Ben...
Responsive Innovation in a Local Context

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Big Data Technologies - Introduction.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Cloud computing and distributed systems.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Modernizing your data center with Dell and AMD
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
KodekX | Application Modernization Development
Empathic Computing: Creating Shared Understanding
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Understanding_Digital_Forensics_Presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Big Data Technologies - Introduction.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Cloud computing and distributed systems.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
The AUB Centre for AI in Media Proposal.docx
Modernizing your data center with Dell and AMD
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Events and microservices

  • 1. Events & Microservices Saul  Caganoff,  CTO  Sixtree saul@sixtree.com.au @scaganoff
  • 2. Introduction • Asynchrony  is  considered  a  microservice   characteristic – But  not  often  discussed • In  the  top  20  Google  results – 7  mentioned  async/choreography  or  events – 3  of  those  by  Chris  Richardson  or  Martin  Fowler • Mostly  mentioned  in  passing • Honourable  Mentions: – http://www.infoq.com/articles/microservices-­‐intro – http://highscalability.com/blog/2014/4/8/microservices-­‐not-­‐a-­‐free-­‐ lunch.html
  • 4. Bounded Contexts Finance Sales Fulfilment Product Online  bookstore  is   the  “Hello  World”  of   enterprise  systems http://maribyrnong.com.au
  • 7. Fulfilment Context Book ISBN Title Customer Name Receipt Order  Number Sub-­‐total GST Total Address Street  Number Street  Name Suburb Postcode Courier Depot Location Driver Shipment Dispatch  Time ETA Location
  • 9. Coupling & Cohesion • Cohesion – how  well  a  subsystem  forms  a   uniting  whole – How  well  a  bounded  context  does  its  job • Coupling – the  propensity  for  change  in  one   part  of  a  system  to  disrupt  another – how  badly  “stuff”  leaks  across  the  boundaries • Coupling  is  evil  – it  sneaks  into  solutions  in  all   kinds  of  insidious  ways
  • 11. Coupling & Cohesion • Microservices strive to  eliminate  coupling • Insidious  sources  of  coupling – Shared  databases – Single  Common  Data  Model  (vs  bounded  contexts) – DRY  – shared  code – APIs  generated  from  code – Autogenerated client  SDKs – Projects  – funding  and  scope – Assumptions  about  business  processes – Organizational  structure
  • 12. Business Processes • End-­‐to-­‐end  business  processes  require   coordination  across  bounded  contexts Finance Sales Ful-­‐ filment Product
  • 13. Business Processes • Browse  the  inventory • Create  order • Enter  Shipping  Details • Quote  shipping  charge • Make  the  payment • Update  inventory • Create  Shipment • Pick  &  Pack • Courier • Accept  delivery GET  /products POST  /order PUT  /order/:id/address GET  /3pl/charges?zip=… POST  /finance/payment?order= POST  /products POST  /3pl/shipment GET  /3pl/shipment/:id GET  /3pl/shipment/:id/address PUT  /3pl/shipment/:id?status=
  • 14. Business Processes • Orchestration   – Centralized  coordination – E.g.  the  user-­‐agent,  BPM  engine,  service  facade – the  “god”  object • Hypermedia – HATEOAS – But  what  about  at  the  edges? – How  much  should  one  BC  know  about  another  BC? “microservices architecture  will  never  be  SOA  done  right  unless  it  means  building   hypermedia  systems  of  microservices”  – Jason  Bloomberg http://intellyx.com/2015/07/20/are-­‐microservices-­‐soa-­‐done-­‐right/
  • 15. Some Perspective 0 2 4 6 8 10 12 DB  Triggers Monolith Orchestration Hypermedia EDA Coupling
  • 16. Data Synchronization • How  to  handle  data  “owned”  by  multiple   domains – Glibness: “don’t”  have  multiple  data  owners – …in  reality  it  is  impossible  to  eliminate – …especially  if  legacy  or  COTS  systems  involved. • Some  data  synchronization  is  naturally   conveyed  by  the  business  process • …some  is  not.
  • 17. Choreography • Use  events  to  coordinate  activity  across  bounded   contexts • Publishers  &  Subscribers  are  highly  decoupled – Event  subscribers  can  come  &  go  minimal  or  no  code   or  configuration  changes • Publishers  &  Subscribers  are  more  resilient  to   change  – either  planned  or  unplanned – E.g.  events  redelivered  in  the  event  of  subscriber   failure  – either  to  the  restored  subscriber,  or  a   replacement
  • 18. Choreography • But  trade-­‐offs • Asynchronous  events  lie  at  the  heart  of  some  of   the  microservices challenges – Centralised  orchestration  is  harder  to  change,  but   easier  to  control/monitor – Event-­‐based  choreography  is  easier  to  change  but   harder  to  control/monitor • Distributed  logging/monitoring  systems  are   needed  to  provide  a  view  into  asynchronous   interactions
  • 19. Coordination • Think  about  hypermedia  inside  boundaries • Events  outside  the  boundaries Finance Sales Ful-­‐ filment Product
  • 21. Commands & Events • Duality  between  commands  &  events – Commands  cause  state  transitions – Events  reflect  state  transitions • An  external  observer  can  infer  the  state  of  a   resource  from  its  event-­‐stream – This  is  the  essence  of  event-­‐sourcing  &  CQRS
  • 22. State Modelling Empty Cart Full Cart Quoted Paid POST  /cart PUT  /cart/:id {  book:  …  } PUT  /cart/:id {  book:  …  } DELETE  /cart/:id/books/:id PUT  /cart/:id {  address:  …  } POST  /payments {  cart:  …,  card:  {…}} Commands  (HATEOAS) {create:  {  cart:  …  }  …  } {add:  {  cart:  …,  book:  {…}}  ..} {add:  {  cart:  …,  book:  {…}}  ..} {del:  {  cart:  …,  book:  {…}}  ..} {quoted:  {  cart:  …  }  …  } {paid:  {  cart:  …  }  …  } Events  (EATNOAS)
  • 24. Event Structure • Immutable  structures • Typical  properties – Timestamp – Source – Entity  URI – Action  (state  transition) • The  MVP  is  to  notify  that  a  resource  has   changed  and  allow  subscribers  to  pull  the   update  if  needed.
  • 25. Concurrency • Race  Conditions • The  importance  of  order • Single  Master  vs  Multi-­‐Master • Deltas  vs  Copies • Action  indicators • CRDTs  – conflict-­‐free  replicated  data  types • …think  in  terms  of  events  rather  than  copies
  • 27. Syndication • Service  exposes  an  RSS/atom  feed • Consumers  do  all  the  hard  work: – Subscription – State  Management  (where  am  I  up  to?) – Retries • Positives – Very  easy…well-­‐known  pattern – Web-­‐scale • Negatives – Polling – High  latency
  • 28. Web Hooks • Service  POSTs  events  to  subscribers • Publishers  do  all  the  hard  work: – Manage  subscribers – Managed  guaranteed  delivery/  retries • Positives – Not  polling,  relatively  lower  latency • Negatives – Subscription  management  &  guaranteed  delivery   must  be  done  yourself…can  be  tricky.
  • 29. Message Queues • Events  published  to  queues/topics – E.g JMS,  AMQP,  ZMQ,  SQS/SNS,  IronMQ • Positives – Mature,  well-­‐known  technologies – Good  open-­‐source  implementations  available – Competing  consumer  pattern • Negatives – Extra  infrastructure – Reliability  depends  on  reliable  file-­‐systems   • SANs,  Distributed  file-­‐lock  managers
  • 30. Apache Kafka • Distributed  log • Similar  model  to  syndication – Single  node  shares  data  by  writing  to  logfiles – Consumers  tail  the  logs • Consumers  control  their  position  in  the  log • Low  latency • Reliability  handled  at  the  application  layer – whether  Zookeeper  is  less  burdensome  than  clustered   file  system  is  up  to  you
  • 31. Event Processing • Simple  events  are  very  useful  for  data   synchronization  or  process  coordination • Continuum  of  complexity • Some  tools:  Drools,  Riemann.io,  Apache  Storm • This  is  a  whole  ‘nother topic Cardinality State Tools Single  event Simple Event  processor Multiple  events/stream Simple Stream  processor Multiple  events/stream Complex  /  Rules Complex  Event  Processor
  • 32. Wrap-Up • Bounded  contexts  are  important – they  promote  cohesion  and  reduce  coupling • You  need  to  decide  how  to  coordinate  data  &   processes  across  boundaries – Orchestration  (relatively  higher  coupling) – Hypermedia  (couples  across  boundaries) – Events • Prefer  Hypermedia  within  bounded  contexts  &  events   across  bounded  contexts Events  have  many  benefits  but  also  some  downsides  -­‐ they  are  an  important  tool  in  your  toolbox.