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

Modular vs Monolithic: No Holy Grails

Modular vs Monolithic: No Holy Grails

One of the biggest problems in web development today is scalability. It’s a big problem, and not always easy to solve. The sheer number of requests that large applications need to process is huge, and increasing every day.

One of the most elegant and widely adopted techniques to deal with this is favoring modular architectures over monolithic ones. Having a distributed network of tiny apps makes it easier to have a robust, maintainable codebase. Adopting the Unix philosophy of doing one thing right is a topic that has been coming up at conferences and on blog posts all over the world lately, and with good reason.

But is a modular architecture always the best solution? Is then a monolithic approach “wrong” from the get go? Sometimes building a modular system is worth it, sometimes it just isn’t. In this talk I put forward my thoughts and experiences dealing with refactoring your application into several small ones, how to build a monolithic app that can be easily split, how to approach the refactor gradually and incrementally, so as not to lose the ability to deliver new features, and how to decide when it’s simply not worth it.

Pablo Astigarraga

August 19, 2012
Tweet

More Decks by Pablo Astigarraga

Other Decks in Programming

Transcript

  1. Everyone today is using a computer. (because we are in

    the future) Monday, August 20, 12
  2. And we always want to design software in the best

    possible way. Monday, August 20, 12
  3. - Encourages separation of concerns. - Which helps keep codebases

    maintainable. Modular - Pros Monday, August 20, 12
  4. - Encourages separation of concerns. - Which helps keep codebases

    maintainable. - Easier to test and expand. Modular - Pros Monday, August 20, 12
  5. - Encourages separation of concerns. - Which helps keep codebases

    maintainable. - Easier to test and expand. - Simplifies scalability in terms of raw traffic. Modular - Pros Monday, August 20, 12
  6. - Encourages separation of concerns. - Which helps keep codebases

    maintainable. - Easier to test and expand. - Simplifies scalability in terms of raw traffic. - More flexibility, less coupling. Modular - Pros Monday, August 20, 12
  7. - Adds a new layer of code for each module.

    Modular - Cons Monday, August 20, 12
  8. - Adds a new layer of code for each module.

    - This introduces a certain level of complexity. Modular - Cons Monday, August 20, 12
  9. - Adds a new layer of code for each module.

    - This introduces a certain level of complexity. - Making the initial development slower. Modular - Cons Monday, August 20, 12
  10. - Adds a new layer of code for each module.

    - This introduces a certain level of complexity. - Making the initial development slower. - And your adaptability weaker (at first). Modular - Cons Monday, August 20, 12
  11. - Reduced complexity. - Simpler initial development and deployment. -

    Less worries mean more adaptability. Monolithic - Pros Monday, August 20, 12
  12. - Reduced complexity. - Simpler initial development and deployment. -

    Less worries mean more adaptability. - More time for features and client value. Monolithic - Pros Monday, August 20, 12
  13. - Less maintainable for large codebases. - Tendency to grow

    out of control. Monolithic - Cons Monday, August 20, 12
  14. - Less maintainable for large codebases. - Tendency to grow

    out of control. - Larger codebases means difficulty to test. Monolithic - Cons Monday, August 20, 12
  15. - Less maintainable for large codebases. - Tendency to grow

    out of control. - Larger codebases means difficulty to test. - Coupling, lots of coupling. Monolithic - Cons Monday, August 20, 12
  16. - Less maintainable for large codebases. - Tendency to grow

    out of control. - Larger codebases means difficulty to test. - Coupling, lots of coupling. Monolithic - Cons - Harder to scale for large traffic. Monday, August 20, 12
  17. Ask yourself: - Am I working on a startup? -

    Will this be a large app from the get-go? Monday, August 20, 12
  18. Ask yourself: - Am I working on a startup? -

    Will I be serving a huge amount of traffic in the near future? - Will this be a large app from the get-go? Monday, August 20, 12
  19. Ask yourself: - Am I working on a startup? -

    Will I be serving a huge amount of traffic in the near future? - Are you sure? ಠ_ಠ - Will this be a large app from the get-go? Monday, August 20, 12
  20. TL;DR Use your models to handle mainly persistence, put complex

    business logic in services you can call easily. James Golick Monday, August 20, 12
  21. class UserCreationService def initialize(user_klass = User, log_klass = Log) @user_klass

    = user_klass @log_klass = log_klass end def create(params) @user_klass.create(params).tap do |u| @log_klass.new_user(u) end end end Monday, August 20, 12
  22. Always code your logic thinking that it will be used

    in an API. Monday, August 20, 12
  23. Do: - Write new business logic in services. - When

    changing old logic, refactor it. Monday, August 20, 12
  24. Do: - Create API calls on a per need basis.

    - Write new business logic in services. - When changing old logic, refactor it. Monday, August 20, 12
  25. Do: - Create API calls on a per need basis.

    - Map API calls to _one_ service. - Write new business logic in services. - When changing old logic, refactor it. Monday, August 20, 12
  26. For the love of all that is holy: Never stop

    feature development to code a full API. Monday, August 20, 12
  27. Links: @poteland - Service Pattern: http://bit.ly/9hBela - Slides: http://bit.ly/Pf6u9O -

    Looking for a job? http://cuboxlabs.com Monday, August 20, 12