All aboard the Service Bus!

All aboard the Service Bus!

We deal with complicated and complex applications on a daily basis, codebases that are filled with classes that do too many things. One design pattern that can help us with this is CQRS, Command Query Responsibility Seggregation. The idea behind CQRS is to split our models in two - the Command for writing, and the Query for reading. Applying CQRS can lead us to a more maintainable code, code that follows the SOLID principles more closely.

At the heart of CQRS lies the Service Bus - a transport mechanism responsible for dispatching our command, event, and query messages to their destinations.

This talk will give an overview of the CQRS pattern and take a closer look at the different types of service buses - command, event, and query ones. Main takeaway will be practical information on why, when, and how to use them, with emphasis on their differences. We'll also take a look at some of the PHP libraries out there that help us work with service buses like Prooph Service Bus, Simple Bus, Tactician, to name a few.

6d9ae403ee630c0e51ec79105a3b7af1?s=128

robertbasic

June 08, 2018
Tweet

Transcript

  1. All aboard the Service Bus! All aboard the Service Bus!

    Robert Basic Robert Basic @robertbasic @robertbasic https:/ /robertbasic.com/ https:/ /robertbasic.com/ 1
  2. PHP PHP Mockery Mockery Go Go Writing Writing Board games

    Board games D&D D&D 2
  3. Photo by Mike Erskine An introduction An introduction CQS &

    CQRS CQS & CQRS Service buses Service buses Command buses Command buses Event buses Event buses Query buses Query buses Recap Recap 3
  4. Been there. Been there. Done that. Done that. 4

  5. CQS CQS CQRS CQRS Command-query separation Command Query Responsibility Segregation

    5
  6. 6

  7. Before CQRS Before CQRS 7

  8. After CQRS I After CQRS I 8

  9. After CQRS II After CQRS II 9

  10. Smaller classes Smaller classes Separated responsibilities Separated responsibilities Faster writes

    and reads Faster writes and reads Easier database queries Easier database queries Photo by Aziz Acharki 10
  11. More classes More classes Translation Translation Complex syncing Complex syncing

    Eventual consistency Eventual consistency Photo by Daniel Páscoa 11
  12. Service Bus Service Bus Photo by Nick Baker 12

  13. 13

  14. Message type support Message type support Tactician Tactician SimpleBus SimpleBus

    Prooph Service Bus Prooph Service Bus Photo by Rob Allen 14
  15. 15

  16. Commands Commands Messages about user intention Messages about user intention

    CreateProduct, PutProductOnSale CreateProduct, PutProductOnSale Name reveals use case Name reveals use case One command, one action One command, one action 16
  17. A command is always valid A command is always valid

    17
  18. Dispatching commands, HTTP Dispatching commands, HTTP 18

  19. Dispatching commands,CLI Dispatching commands,CLI 19

  20. Command handlers Command handlers 20

  21. 21

  22. Events Events Messages about past events Messages about past events

    After a command was handled After a command was handled ProductCreated, ProductPriceUpdated ProductCreated, ProductPriceUpdated Once dispatched, can’t be stopped Once dispatched, can’t be stopped 22
  23. An event holds primitives An event holds primitives 23

  24. Dispatching events Dispatching events 24

  25. Event listeners Event listeners 25

  26. 26

  27. Queries Queries Not the same as database queries Not the

    same as database queries A query is a question A query is a question LatestProductsCreated, ProductsOnSale LatestProductsCreated, ProductsOnSale Answers from read models Answers from read models 27
  28. A query is always valid A query is always valid

    28
  29. Dispatching queries Dispatching queries 29

  30. Query handlers Query handlers 30

  31. Take away Take away Photo by Ian Usher 31

  32. ChimeraPHP ChimeraPHP https:/ /github.com/chimeraphp https:/ /github.com/chimeraphp https://gist.github.com/lcobucci/6c89a97ea9c11a6cccfc887afa15df81 32

  33. Thank you! Thank you! Robert Basic Robert Basic @robertbasic @robertbasic

    https:/ /robertbasic.com/ https:/ /robertbasic.com/ https:/ /joind.in/talk/5a9d7 https:/ /joind.in/talk/5a9d7 33