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

Applying Microservices Patterns to a Modular Mo...

Applying Microservices Patterns to a Modular Monolith

Dealing with legacy monoliths can be challenging due to accumulated technical debt. When faced with this situation, we usually start looking at different strategies to solve this, like microservices, engines, and modularization, just to name a few.

When choosing to follow a modular approach, I explored applying microservices patterns to our modular monolith. In this talk, I’ll share my experience in adopting this approach, focusing on ensuring data consistency and distributed transactions, as well as the pitfalls and insights I discovered along the way.

Guillermo Aguirre

April 26, 2023
Tweet

Other Decks in Programming

Transcript

  1. Applying Microservices Patterns to a Modular Monolith 1 | class

    User < ApplicationRecord ... | ... 2473 | end Monoliths My experience
  2. Applying Microservices Patterns to a Modular Monolith Long deployment times

    Monoliths The bad Tightly coupled code => Harder to maintain & extend
  3. Applying Microservices Patterns to a Modular Monolith Data inconsistencies Hot-

    f ix issues in production Microservices My experience
  4. Applying Microservices Patterns to a Modular Monolith Signi f icantly

    higher infrastructure complexity Microservices The bad
  5. Applying Microservices Patterns to a Modular Monolith Signi f icantly

    higher infrastructure complexity Distributed mess Microservices The bad
  6. Applying Microservices Patterns to a Modular Monolith Cross-pollination between architectures

    Leverage and reuse work from the microservices world into our modular app
  7. Applying Microservices Patterns to a Modular Monolith Problems when leaving

    one database A 
 C 
 I 
 D Local transactions are ensured by
  8. Applying Microservices Patterns to a Modular Monolith Problems when leaving

    one database A 
 C 
 I 
 D Atomicity 
 Consistency 
 Isolation 
 Durability Local transactions are ensured by
  9. Applying Microservices Patterns to a Modular Monolith Problems when leaving

    one database A 
 C 
 I 
 D Atomicity 
 Consistency 
 Isolation 
 Durability Local transactions are ensured by
  10. Applying Microservices Patterns to a Modular Monolith Not handling transactions

    Consistency issues Devolve into f ixing data issues in production
  11. Applying Microservices Patterns to a Modular Monolith Not handling transactions

    Consistency issues Devolve into f ixing data issues in production Important f lows break and we have no way of noticing
  12. Applying Microservices Patterns to a Modular Monolith What patterns are

    we going to use? One database per service/domain
  13. Applying Microservices Patterns to a Modular Monolith What patterns are

    we going to use? One database per service/domain Saga
  14. Applying Microservices Patterns to a Modular Monolith What patterns are

    we going to use? One database per service/domain Saga Transactional Outbox
  15. Applying Microservices Patterns to a Modular Monolith One database per

    service/domain Private tables per service Isolation of data structure
  16. Applying Microservices Patterns to a Modular Monolith One database per

    service/domain Private tables per service Schema per service Isolation of data structure
  17. Applying Microservices Patterns to a Modular Monolith One database per

    service/domain Private tables per service Schema per service Database per service Isolation of data structure
  18. Applying Microservices Patterns to a Modular Monolith Saga Chris Richardson

    - https://microservices.io/patterns/data/saga.html Eventual consistency across systems
  19. Applying Microservices Patterns to a Modular Monolith Saga Chris Richardson

    - https://microservices.io/patterns/data/saga.html Sequence of local transactions Eventual consistency across systems
  20. Applying Microservices Patterns to a Modular Monolith Transactional Outbox Chris

    Richardson - https://microservices.io/patterns/data/transactional-outbox.html Atomically update state and publish events
  21. Applying Microservices Patterns to a Modular Monolith Transactional Outbox Chris

    Richardson - https://microservices.io/patterns/data/transactional-outbox.html Atomically update state and publish events
  22. Applying Microservices Patterns to a Modular Monolith Modular architecture To

    be able to reference a User entity indirectly, it will have the same identi f ier across domains and databases.
  23. Applying Microservices Patterns to a Modular Monolith Saga f low

    User con f irms email We update the status_code attribute to con f irmed
  24. Applying Microservices Patterns to a Modular Monolith Saga f low

    Successful sequence Outbox record gets created
  25. Applying Microservices Patterns to a Modular Monolith Saga f low

    Rollback sequence Outbox record gets created
  26. Applying Microservices Patterns to a Modular Monolith Saga f low

    Rollback sequence Update UserRegistration to its previous waiting_for_con f irmation state
  27. Applying Microservices Patterns to a Modular Monolith Saga f low

    Rollback sequence Update UserRegistration to its previous waiting_for_con f irmation state User record gets destroyed
  28. Applying Microservices Patterns to a Modular Monolith Demo Implementation of

    the mentioned domain and app Rails multi-database support
  29. Applying Microservices Patterns to a Modular Monolith Demo Implementation of

    the mentioned domain and app Rails multi-database support Ka f ka as a message bus
  30. Applying Microservices Patterns to a Modular Monolith Demo Implementation of

    the mentioned domain and app Rails multi-database support Ka f ka as a message bus Ka f ka Connect as the outbox publisher
  31. Applying Microservices Patterns to a Modular Monolith Demo Implementation of

    the mentioned domain and app Rails multi-database support Ka f ka as a message bus Ka f ka Connect as the outbox publisher Kara f ka for consumers
  32. Applying Microservices Patterns to a Modular Monolith Where to f

    ind the code github.com/ rootstrap/ rails-modular-monolith-with-ddd/ tree/ main-saga
  33. Guillermo Aguirre - RailsConf 2023 What to take away Applying

    Microservices Patterns to a Modular Monolith
  34. Guillermo Aguirre - RailsConf 2023 What to take away 3

    widely used patterns Applying Microservices Patterns to a Modular Monolith
  35. Guillermo Aguirre - RailsConf 2023 What to take away 3

    widely used patterns Dealing with distributed transactions Applying Microservices Patterns to a Modular Monolith
  36. Guillermo Aguirre - RailsConf 2023 What to take away 3

    widely used patterns Dealing with distributed transactions It's possible to leverage di ff erent solutions Applying Microservices Patterns to a Modular Monolith
  37. Guillermo Aguirre - RailsConf 2023 What to take away 3

    widely used patterns Dealing with distributed transactions It's possible to leverage di ff erent solutions Not a silver bullet Applying Microservices Patterns to a Modular Monolith
  38. Guillermo Aguirre - RailsConf 2023 What to take away 3

    widely used patterns Dealing with distributed transactions It's possible to leverage di ff erent solutions Not a silver bullet Inspiring others Applying Microservices Patterns to a Modular Monolith
  39. Guillermo Aguirre - RailsConf 2023 Thank you! Applying Microservices Patterns

    to a Modular Monolith @guillermoap @guillermoap_ @guillermo.aguirre Guillermo Aguirre /gee-SHER-moh ah-GHEE-rreh/