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

Building an Umbrella Project

Wojtek Mach
September 02, 2016

Building an Umbrella Project

One of the many goals that both Elixir & Phoenix share is developer’s productivity. There can be two aspects of productivity: short-term and long-term.
In this talk we’ll explore how using Elixir’s umbrella project feature can help with long-term productivity when working with potentially large codebases. As a example we’ll walk through building an imaginary system: Acme Bank. We will see how we can break up this system into a collection of smaller applications, each of which has a well defined boundary, domain model, set of responsibilities, and can be worked on independently. We’ll compare this approach to microservices-based architecture which is being adopted by many organizations and we’ll see if we can achieve some of the benefits without incurring some of the drawbacks.

Wojtek Mach

September 02, 2016
Tweet

More Decks by Wojtek Mach

Other Decks in Programming

Transcript

  1. Me • Ruby • GitHub API adapter for Ecto •

    OOP library for Elixir • Acme Bank
  2. Me • Ruby • GitHub API adapter for Ecto •

    OOP library for Elixir • Acme Bank
  3. Me • Ruby • GitHub API adapter for Ecto •

    OOP library for Elixir • Acme Bank
  4. Me • Ruby • GitHub API adapter for Ecto •

    OOP library for Elixir • Acme Bank
  5. Inspiration Architecture: The Lost Years
 Robert C. Martin, Midwest RubyConf

    2011
 • Typical Rails app • app/{models,controllers,view} • Top-level architecture should scream it’s intent
  6. Inspiration Architecture: The Lost Years
 Robert C. Martin, Midwest RubyConf

    2011
 • Typical Rails app • app/{models,controllers,view} • Top-level architecture should scream it’s intent
  7. Inspiration Architecture: The Lost Years
 Robert C. Martin, Midwest RubyConf

    2011
 • Typical Rails app • app/{models,controllers,views,…} • Top-level architecture should scream it’s intent
  8. Inspiration Architecture: The Lost Years
 Robert C. Martin, Midwest RubyConf

    2011
 • Typical Rails app • app/{models,controllers,views,…} • Top-level architecture should scream it’s intent
  9. Inspiration Wrangling Large Rails Codebases
 Stephan Hagemann, Rocky Mountain Ruby

    2012
 • Advice about writing large apps • Components
  10. Inspiration Wrangling Large Rails Codebases
 Stephan Hagemann, Rocky Mountain Ruby

    2012
 • Advice about writing a large app • Components
  11. Inspiration Wrangling Large Rails Codebases
 Stephan Hagemann, Rocky Mountain Ruby

    2012
 • Don’t write a large app • Components: gems & engines
  12. Inspiration The Art of Destroying Software
 Greg Young, Leetspeek 2014

    
 • organize your project in a way that makes it easy to delete code.
  13. Inspiration The Art of Destroying Software
 Greg Young, Leetspeek 2014

    
 • organize your project in a way that makes it easy to delete code.
  14. OTP application „In Elixir (actually, in Erlang/OTP), an application is

    a component implementing some specific functionality, that can be started and stopped as a unit, and which can be re-used in other systems.” — Elixir API docs
  15. OTP application • application dependencies • configuration: config.exs, Application.put_env, mix.exs

    • start/stop behaviour • regular applications & library applications
  16. OTP application • application dependencies • configuration • start/stop behaviour

    • regular applications & library applications • standard
  17. # mix.exs defmodule BankPlatform.Mixfile do use Mix.Project def project do

    [apps_path: "apps", deps: deps(), aliases: aliases()] end end Bank Platform
  18. # apps/bank/mix.exs defmodule Bank.Mixfile do use Mix.Project def project do

    [app: :bank, version: "0.1.0", build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", lockfile: "../../mix.lock", deps: deps()] end end Bank
  19. defmodule Bank.Account do defstruct name: "", balance: 0 def deposit(account,

    amount) do %Account{account | balance: account.balance + amount} end end Naive
  20. Accounting 101 • Any movement of money happens between at

    least 2 accounts: one account is debited and the other account is credited • Example: Alice transfers $100 to Bob
  21. Accounting 101 • Any movement of money happens between at

    least 2 accounts: one account is debited and the other account is credited • Example: Alice transfers $100 to Bob
  22. Alice transfers $100 to Bob | Bob | :credit |

    100.00 | Alice | :debit | 100.00 Accounting 101
  23. Bob transfers $20 to Alice | Bob | :credit |

    100.00 | Alice | :debit | 100.00 | Alice | :credit | 20.00 | Bob | :debit | 20.00 Accounting 101
  24. Bob transfers $10 to Alice | Bob | :credit |

    100.00 | Alice | :debit | 100.00 | Alice | :credit | 20.00 | Bob | :debit | 20.00 | Bob | :debit | 10.00 | Alice | :credit | 10.00 Accounting 101
  25. Bob’s balance = $100 - $20 - $10 = $70

    | Bob | :credit | 100.00 | Alice | :debit | 100.00 | Alice | :credit | 20.00 | Bob | :debit | 20.00 | Bob | :debit | 10.00 | Alice | :credit | 10.00 Accounting 101
  26. Bob’s balance = $100 - $20 - $10 = $70

    | Bob | :credit | 100.00 | Alice | :debit | 100.00 | Alice | :credit | 20.00 | Bob | :debit | 20.00 | Bob | :debit | 10.00 | Alice | :credit | 10.00 Accounting 101
  27. Alice’s balance = -$100 + $20 + $10 = -$70

    | Bob | :credit | 100.00 | Alice | :debit | 100.00 | Alice | :credit | 20.00 | Bob | :debit | 20.00 | Bob | :debit | 10.00 | Alice | :credit | 10.00 Accounting 101
  28. Alice’s balance = -$100 + $20 + $10 = -$70

    | Bob | :credit | 100.00 | Alice | :debit | 100.00 | Alice | :credit | 20.00 | Bob | :debit | 20.00 | Bob | :debit | 10.00 | Alice | :credit | 10.00 Double-entry accounting system Accounting 101
  29. Accounting 101 Why mention this? • it’s a Bank •

    it’s functional • mathematical properties • complexity
  30. Accounting 101 Why mention this? • it’s functional • eventual

    consistency [1] • complexity [1] http://highscalability.com/blog/2013/5/1/myth-eric-brewer-on-why-banks-are-base-not-acid-availability.html
  31. Accounting 101 Why mention this? • it’s functional • eventual

    consistency [1] • complexity [1] http://highscalability.com/blog/2013/5/1/myth-eric-brewer-on-why-banks-are-base-not-acid-availability.html
  32. Accounting 101 Why mention this? • it’s functional • eventual

    consistency [1] • complexity • complexity [1] http://highscalability.com/blog/2013/5/1/myth-eric-brewer-on-why-banks-are-base-not-acid-availability.html
  33. Backoffice • ExAdmin. Works with umbrellas out of the box

    • ports setup • deployment • Phoenix is Not Your Application
  34. Backoffice • ExAdmin. Works with umbrellas out of the box

    • setup different ports in development • deployment • Phoenix is Not Your Application
  35. Backoffice • ExAdmin. Works with umbrellas out of the box

    • setup different ports in development • deployment • Phoenix is Not Your Application
  36. Backoffice • ExAdmin. Works with umbrellas out of the box

    • setup different ports in development • deployment • Phoenix is Not Your Application
  37. Backoffice • ExAdmin. Works with umbrellas out of the box

    • setup different ports in development • deployment • Phoenix is Not Your Application
  38. Auth • Upfront design? • Features: strategies, 2FA, tracking •

    Separate Repo, separate DB • Thanks @chris_mccord!
  39. Microservices Benefits: • Strong Module Boundaries • Independent Deployments •

    Technology Diversity http://martinfowler.com/articles/microservice-trade-offs.html
  40. Microservices Benefits: • Strong Module Boundaries • Independent Deployments •

    Technology Diversity http://martinfowler.com/articles/microservice-trade-offs.html Drawbacks: • Distribution • Eventual Consistency • Operational Complexity
  41. Conclusion • keep an eye on the big picture •

    don’t write a large app • isolate by functionality and rate of change
  42. Conclusion • keep an eye on the big picture •

    don’t write a large app • isolate by functionality and rate of change • delete code liberally