modular monoliths
play

Modular Monoliths @simonbrown An independent consultant - PowerPoint PPT Presentation

Modular Monoliths @simonbrown An independent consultant specialising in software architecture The Missing Chapter Also the creator of the Context C4 model, and Structurizr Containers Components Code The server-side of Structurizr is


  1. Modular Monoliths @simonbrown

  2. An independent consultant specialising in software architecture

  3. “The Missing Chapter”

  4. Also the creator of the Context C4 model, and Structurizr Containers Components Code

  5. The server-side of Structurizr is two Java/Spring modular monoliths , running on Pivotal Web Services’ Cloud Foundry PaaS (i.e. no Docker, Kubernetes, etc)

  6. A well structured codebase is easy to visualise

  7. C4 Context, Containers, Components and Code - c4model.com

  8. Context diagram (level 1) Container diagram (level 2) Component diagram (level 3) Class diagram (level 4)

  9. Context diagram (level 1) Container diagram (level 2) Component diagram (level 3) Class diagram (level 4)

  10. Context diagram (level 1) Container diagram (level 2) Component diagram (level 3) Class diagram (level 4)

  11. Context diagram (level 1) Container diagram (level 2) Component diagram (level 3) Class diagram (level 4)

  12. Where’s my “component”? (the “Tweet Component” doesn’t exist as a single thing; it’s a combination of interfaces and classes across a layered architecture)

  13. “ ” “the component exists conceptually ”

  14. Abstractions should re fl ect the code

  15. “model-code gap”

  16. “ ” Our architecture diagrams don’t match the code.

  17. “architecturally-evident coding style”

  18. The code structure should re fl ect the architectural intent

  19. Package by layer

  20. Organise code based upon what the code does from a technical perspective

  21. Package by layer is a “ horizontal” slicing

  22. Web Business Data

  23. Relaxed vs strict layering

  24. Also sample codebases, starter projects, demos at conferences, etc…

  25. “ ” Cargo cult programming can also refer to the results of applying a design pattern or coding style blindly without understanding the reasons behind that design principle. https://en.wikipedia.org/wiki/Cargo_cult_programming

  26. Changes to a layered architecture usually result in changes across all layers

  27. Package by feature

  28. Organise code based upon what the code does from a functional perspective

  29. Features, domain concepts, aggregate roots, etc

  30. Package by feature is a “ vertical” slicing

  31. Cited bene fi ts include higher cohesion, lower coupling, and related code is easier to fi nd

  32. Ports and adapters

  33. Keep domain related code separate from technical details

  34. Variations on this theme include “hexagonal architecture”, “clean architecture”, “onion architecture”, etc

  35. The “inside” is technology agnostic, and is often described in terms of a ubiquitous language

  36. The “outside” is technology speci fi c

  37. The “outside” depends upon the “inside”

  38. Infrastructure (outside) Domain (inside)

  39. This approach is also “cargo culted”, yet not all frameworks are equal

  40. But…

  41. Hi, can you add feature X to the orders functionality?

  42. Sure!

  43. “ ” A big ball of mud is a casually, even haphazardly, structured system. Its organization, if one can call it that, is dictated more by expediency than design. Big Ball of Mud Brian Foote and Joseph Yoder

  44. Architectural principles introduce consistency via constraints and guidelines

  45. “ ” web controllers should never access repositories directly

  46. “ ” we enforce this principle through good discipline and code reviews, because we trust our developers

  47. Responsible, professional software developers are still human :-)

  48. It’s 2018! In a world of arti fi cial intelligence and machine learning, why don’t we use tools to help us build “good” software?

  49. “Fitness functions” (e.g. cyclic complexity, coupling, etc)

  50. Tooling? Static analysis tools, architecture violation checking, etc

  51. “ ” types in package **/web should not access types in **/data

  52. Using tools to assert good code structure seems like a hack

  53. “ ” But Java’s access modi fi ers are fl awed…

  54. Package by component

  55. Organise code by bundling together everything related to a “component”

  56. Component? a grouping of related functionality behind a nice clean interface, which resides inside an execution environment like an application

  57. Software System Container Container Container . client-side web app, server-side web app, console application, (e.g. client-side web app, server-side web app, console application, (e.g. client-side web app, server-side web app, console applica obile app, microservice, database schema, fi le system, etc) mobile app, microservice, database schema, fi le system, etc) mobile app, microservice, database schema, fi le system, etc Component Component Component Code Code Code A software system is made up of one or more containers , each of which contains one or more components , which in turn are implemented by one or more code elements .

  58. Package by component is about applying component-based or service-oriented design thinking to a monolithic codebase

  59. Modularity as a principle

  60. Separating interface from implementation

  61. Public API Public API Business Business Impermeable boundaries Uses Uses Access modi fi ers vs network boundaries Data Data Component Microservice

  62. The devil is in the implementation details

  63. public

  64. Organisation vs encapsulation

  65. If you make all types public , architectural styles can be conceptually di ff erent , but syntactically identical

  66. Use encapsulation to minimise the number of potential dependencies

  67. The surface area of your internal public APIs should match your architectural intent

  68. If you’re building a monolithic application with a single codebase, try to use the compiler to enforce boundaries

  69. Or other decoupling modes such as a module framework that di ff erentiates public from published types

  70. Or split the source code tree into multiple parts

  71. Infrastructure Domain

  72. There are real-world trade-o ff s with many source code trees

  73. And, more generally, each decoupling mode has di ff erent trade-o ff s (modular monoliths vs microservices)

  74. A good architecture rarely happens through architecture-indi ff erent design

  75. Agility is a quality attribute

  76. A good architecture enables agility

  77. Modular Microservices monolith Modularity Monolithic Distributed big ball of mud big ball of mud Number of deployment units

  78. Class s Class s a l C Collaborators s r o t a r o Collaborators b a l l o C Responsibilities s e Responsibilities i t i l i b i s n o p s e R Class-Responsibility-Collaboration

  79. Well-de fi ned, in-process components is a stepping stone to out-of-process components (i.e. microservices) From components to microservices < All of that plus High cohesion Low coupling Individually deployable Focussed on a business capability Individually upgradeable Bounded context or aggregate Individually replaceable Encapsulated data Individually scalable Substitutable Heterogeneous technology stacks Composable

  80. Choose microservices for the bene fi ts, not because your monolithic codebase is a mess

  81. Whatever architectural approach you choose, don’t forget about the implementation details

  82. Beware of the model-code gap

  83. Thank you! simon.brown@codingthearchitecture.com @simonbrown

Recommend


More recommend