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

When Microservices met Event Sourcing

When Microservices met Event Sourcing

Talk presented at the O'Reilly Software Architecture Conference 2017 https://conferences.oreilly.com/software-architecture/sa-ny/public/schedule/detail/56806

439e623c5d770ae0da8e61ec08452032?s=128

Vinicius Gomes

April 04, 2017
Tweet

Transcript

  1. When Microservices met Event Sourcing Vinicius Gomes

  2. Vinicius Gomes ! Software developer at ThoughtWorks ! vvgomes.com/blog !

    twitter.com/vvgomes
  3. Agenda ! The Traditional Approach ! Introduction to Event Sourcing

    ! Command Query Responsibility Segregation ! Implementing the "Event Sourced Microservices" Architecture
  4. The Traditional Approach

  5. Example: Online Restaurant

  6. Online Restaurant

  7. Online Restaurant ! Open an order

  8. Online Restaurant ! Add Menu Item

  9. Benefits ! Simple ! HTTP ! Technology agnostic

  10. Challenges ! Coupling

  11. Challenges ! Coupling ! Resilience

  12. Challenges ! Coupling ! Resilience ! Response time

  13. Challenges ! Coupling ! Resilience ! Response time ! User

    intent POST /orders/8659a0d6/items/ “Add item to order”
  14. Challenges ! Coupling ! Resilience ! Response time ! User

    intent ! Current / mutable state
  15. Event Sourcing

  16. Domain Events ! Model the past ! Immutable ! Immortal

  17. Event Store ! Append only ! Sequential ! History

  18. Aggregates ! Applying events

  19. Aggregates ! Applying events

  20. Aggregates ! Applying events

  21. Aggregates ! Applying events

  22. Aggregates ! Applying events

  23. Aggregates ! Applying events

  24. Aggregates ! Applying events

  25. Commands ! Represent user intent ! Cause new events

  26. Commands ! Commands are more meaningful than HTTP methods POST

    /orders/8659a0d6/items/ AddItemToOrderCommand as opposed to
  27. Commands How do clients send commands?

  28. Commands ! A collection resource that accepts multiple commands POST

    /orders/8659a0d6/commands/
  29. Commands ! Command URI POST /orders/8659a0d6/orderItems/commands/add

  30. Commands

  31. Commands

  32. Commands Queries?

  33. Queries ! Event Store is not good for queries !

    Most applications ! A few writes ! A lot of reads
  34. Command Query Responsibility Segregation

  35. CQRS

  36. CQRS

  37. CQRS ! Command Model ! Commands definitions ! Events definitions

    ! The aggregate ! Aggregate repository ! Write only API ! Query Model ! Event listeners ! Query entities ! Repositories ! Read only API
  38. Sample Implementation

  39. Example: Online Restaurant

  40. Example: Online Restaurant

  41. Example: Online Restaurant

  42. Example: Online Restaurant

  43. Technologies ! Java 8 ! Spring Boot ! Axon Framework

    ! Spring Data REST ! RabbitMQ
  44. Conclusions

  45. Microservices + Event Sourcing ! Benefits

  46. Microservices + Event Sourcing ! Benefits ! History based queries

  47. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design
  48. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability
  49. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability ! User intent
  50. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability ! User intent ! Decoupling
  51. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability ! User intent ! Decoupling ! Resilience
  52. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability ! User intent ! Decoupling ! Resilience ! Challenges
  53. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability ! User intent ! Decoupling ! Resilience ! Challenges ! Complexity ! Snapshots
  54. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability ! User intent ! Decoupling ! Resilience ! Challenges ! Complexity ! Snapshots ! Upcasting
  55. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability ! User intent ! Decoupling ! Resilience ! Challenges ! Complexity ! Snapshots ! Upcasting ! Race conditions
  56. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability ! User intent ! Decoupling ! Resilience ! Challenges ! Complexity ! Snapshots ! Upcasting ! Race conditions ! Event contracts
  57. Microservices + Event Sourcing ! Benefits ! History based queries

    ! Audit log by design ! Immutability ! User intent ! Decoupling ! Resilience ! Challenges ! Complexity ! Snapshots ! Upcasting ! Race conditions ! Event contracts ! Eventual consistency
  58. When Microservices met Event Sourcing Vinicius Gomes