Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

OReilly SACON2018 - Events on the outside, on the inside, and at the core

282 Aufrufe

Veröffentlicht am

Events are very much on the edge of traditional applications, which use them as an application integration mechanism. The classic example is an ecommerce system. When a customer places an order, the order management application publishes an event, which triggers the fulfillment application to action. But today, microservices and DDD—which is a great foundation for microservices—are at the core of the application.

Events play an essential role in modern applications. Chris Richardson explains why events are a key application integration mechanism and how they are used by applications to communicate with the outside world. You’ll learn how the microservices inside an application use events to maintain data consistency and discover how to go one step further and make events an integral part of your domain logic.

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

OReilly SACON2018 - Events on the outside, on the inside, and at the core

  1. 1. Chris Richardson Founder of Eventuate.io Founder of the original CloudFoundry.com Author of POJOs in Action and Microservices Patterns @crichardson chris@chrisrichardson.net http://learn.microservices.io Events on the outside, on the inside and at the core
  2. 2. @crichardson About Chris http://learn.microservices.io ctwsoftarchconf18
  3. 3. @crichardson What’s an event?
  4. 4. @crichardson http://www.merriam-webster.com/dictionary/event
  5. 5. @crichardson Examples of events
  6. 6. @crichardson Events play a role at every level of an architecture
  7. 7. @crichardson Events on the outside E-commerce Application Fulfilment Application
  8. 8. @crichardson An application emits an event when… OrderCreated E-commerce Application OrderShipped InvoiceBecameOverdue State changes Passage of time
  9. 9. @crichardson Who consumes an event? Notification Service Dashboard/ Monitoring OrderCreated Email SMS … E-commerce Application Fulfilment Application
  10. 10. @crichardson Implements the Open for extension/Closed for modification principle for applications Legacy Application New Feature
  11. 11. @crichardson How to transport events?
  12. 12. @crichardson messaging system Inside the firewall: Messaging-based IPC Sender Recipient message Channel AWS Kinesis
  13. 13. @crichardson Outside the firewall
  14. 14. @crichardson Polling for events HTTP Periodically poll for events Atom Publishing Protocol (AtomPub) Based on HTTP Head is constantly changing Tail is immutable and can be efficiently cached High-latency, inefficient
  15. 15. @crichardson Using WebSockets Browser Web Socket STOMP Client application Service Web Socket STOMP Application SUBSCRIBE MESSAGE MESSAGE Low latency, more efficient, but what about past events?
  16. 16. @crichardson Webhooks = web friendly publish/ subscribe Client Application register(events, callbackUrl) POST callbackUrl POST callbackUrl … Low latency, more efficient, but what about past events?
  17. 17. @crichardson Events on the inside E-commerce application Order Service Catalog Service
  18. 18. @crichardson The Microservice architecture enables the rapid, safe delivery of large, complex applications
  19. 19. @crichardson E-commerce application - refactored to services Order Service Catalog Service API API Customer Service API …. Service API But what about transactions and queries that span services? Private DBs
  20. 20. @crichardson How to implement transactions that span services?
  21. 21. @crichardson How to enforce the customer’s credit limit? Customer creditLimit ... has ordersbelongs toOrder total Invariant: sum(open order.total) <= customer.creditLimit ? placeOrder() Order Service updateCreditLimit() Customer Service No 2PC
  22. 22. @crichardson Use event-driven, choreography-based sagas Customer creditLimit creditReservations ... Order total placeOrder() Order Service Customer Service create() Order created Credit Reserved reserveCredit() approve()
  23. 23. @crichardson How to implement queries that span services?
  24. 24. @crichardson Find new customers who have placed high value orders that have shipped
  25. 25. @crichardson Use Command Query Responsibility Segregation Order Service Customer Service Message Broker Customer * Customer View Service Order * findNewHighValueCustomers() View database designed to support query
  26. 26. @crichardson Events at the core Order
 Service Order created ≪aggregate≫ Order
  27. 27. @crichardson DDD: Aggregates publish domain events Order OrderLine Item quantity productId productName productPrice customerId Address street city … Aggregate Order created Domain event Publishes when created or state changes
  28. 28. @crichardson Business logic explicitly invoking event publishing API ≪service≫ OrderService ≪aggregate≫ Order DomainEvent Publisher placeOrder(…) new(…) ≪event≫ OrderCreated publish(…) new(…) • Simple • Easy to adapt existing code But • Events are not automatic • Tricky to publish messages transactionally publish(…)
  29. 29. @crichardson Use event sourcing Event table Entity type Event id Entity id Event data Order 902101 …OrderApproved Order 903101 …OrderShipped Event type Order 901101 …OrderCreated ≪aggregate≫ Order List<Event> process(CreateOrderCommand) void apply (OrderCreatedEvent) List<Event> process(CancelOrderCommand) void apply (OrderCanceledEvent) Reliable publishing, aggregate history, auditing, …. YET radically different Event-based persistence Event-based business logic +
  30. 30. @crichardson Summary Events play a role at every level of an architecture Order created
  31. 31. @crichardson Summary: aggregates publish events Order created ≪aggregate≫ Order
  32. 32. @crichardson Summary: services publish events Order created ≪Aggregate≫ Order Order Service
  33. 33. @crichardson Summary: applications publish events Order created ≪Aggregate≫ Order Order Service E-commerce application
  34. 34. @crichardson @crichardson chris@chrisrichardson.net http://learn.microservices.io Questions?ctwsoftarchconf18