Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Microservices and Event-Driven Architecture

Leonardo
November 28, 2019

Microservices and Event-Driven Architecture

Some examples of how use Microservices approach and Event-Driven Architecture together.

Leonardo

November 28, 2019
Tweet

More Decks by Leonardo

Other Decks in Technology

Transcript

  1. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Microservices and Event-Driven Architecture Leonardo Piedade, Solutions Architect Luiz Yanai, Solutions Architect
  2. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. A Brief History of Time… • Traditional App (3 tiers) • SOA Approach • Microservices
  3. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Traditional Application UI Logic Shop UI E-commerce GUI Order DAO Checkout API E-commerce Backend Application E-commerce Single Database Search API Product DAO Customer DAO
  4. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. SOA Application UI Logic Shop UI E-commerce GUI Orders DB Database Products DB Database Order Logic Order API Orders Application Product Logic Product API Products Application
  5. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Microservices UI Logic Shop UI E-commerce GUI Order DAO Order API Orders Application Orders DB Product DAO Product API Products Application Products DB Custom. DAO Custom. API Customers Application Customers DB
  6. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Wait!... And DDD?
  7. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Microservices Communication Expectation
  8. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Microservices Communication Reality
  9. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Point-to-point Couplings Order Service UI Logic Shop UI E-commerce GUI Product Service Customer Service Checkout Service Some kind of problems: • Crash of service • Slow response time • Change of interface
  10. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Sync vs Async Synchronous Asynchronous
  11. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Reasons to Send a Message Command Query Event I want to do something I want to know something Something has happened
  12. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Reasons to Send a Message Command Query Event I want a Pizza Is my pizza ready!? Pizza delivered
  13. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Event-Driven Microservices Async Communication Order Service Product Service Customer Service Pub/Sub Pub/Sub Message Broker
  14. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Event-Driven Microservices Async Communication Application Message Broker Derived Event New Events State
  15. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. “We have an amazing API… …but please subscribe to our event streams instead.”
  16. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Event-Driven Simple Pattern for Streaming Data Data Producer Continuously creates data Continuously writes data to a stream Can be almost anything Durably stores data Provides temporary buffer that preps data Supports very high- throughput Continuously process data Cleans, prepares, and Aggregates Transforms data to information Streaming Service Data Consumer
  17. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Event Sourcing vs Event Store Persists the state of a entity as a sequence of state-changing events Whenever state of entity changes, a new event is appended to the list of events Saving an event is a single operation (atomic) The application reconstructs an entity’s current state by replaying the events
  18. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Event Sourcing - Example
  19. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Event-Driven Microservices Async Communication Application Message Broker Derived Event New Events State
  20. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Old Idea? Operational/Transactional Database vs Reporting/Analytical Database https://martinfowler.com/bliki/ReportingDatabase.html OLTP vs OLAP
  21. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. CQRS – Command Query Responsibility Segregation https://martinfowler.com/bliki/CQRS.html - 2011 Command Service Write Data Store Query Service Read Data Store Command that trigger change in state Query that provide read access to the state *One alternative for CQRS implementation
  22. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Event Sourcing & CQRS Command Service Data Store Query Service Materialized View Command Query *Another alternative for CQRS implementation Event Store Command Handler <projection> Optimize different nonfunctional requirements for read and write Write Delay Eventual Consistency Database as event publisher (optional) Data Projection and Materialized View
  23. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Eventual Consistency Credits: https://www.flaticon.com/br/autores/icongeek26 Drink = “beer” Drink = “vodka” Drink = “vodka” Drink = “beer” Drink = “beer” Drink = ? Drink = “beer” Drink = “vodka”
  24. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Expectation Reality Event Ordering
  25. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. “Don't do it, if you can avoid it.” Event Ordering
  26. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Event Ordering 0 0 100 0 Account Created Deposit: 100 Withdraw: 20 -20 0 +100 -20 +100 0 100 80 100 -20 Withdraw: 20
  27. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. Events are Immutable! Or not!?
  28. Governance and Event Catalog Temporal Semantics Channels and Data Security

    Event Versioning Clustered Event Sourcing and Assured Delivery Change Data Capture over Streams Monitoring and Fitness Functions for EDA We are here! Complex Event Processing Backpressure and Exponential Backoff Projections and Aggregates
  29. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. …and other books
  30. ® 2019 Amazon Web Services Inc. or its Affiliates. All

    rights reserved. … or just do this! bit.ly/tdcpoa-2019