Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Evolutionary Architecture - Discovering Boundar...

Evolutionary Architecture - Discovering Boundaries @DevTalks 24

At first, there was no structure. But then features grew complex, and developers started looking for ways to keep their code maintainable. This pragmatic talk explores the essential boundaries you can enforce in your architecture to address common pain-points you might be experiencing. You’ll learn about: Contract vs Implementation, CQRS, Separation by Layer of Abstraction, Agnostic Domain, Dependency Inversion, and the Modulith Architecture in an entertaining journey that overviews the main architectural guidelines for backend systems.

About the Author
With over two decades of experience, Victor is a Java Champion with extensive experience training mid-to-senior-level developers. Each week, Victor engages in intense workshops with talented engineers, addressing the challenges specific to their projects. He then regularly distills these insights into conference presentations and online meetups for the European Software Crafters, the world’s leading community focused on architecture, refactoring, and testing. Explore first-class training, consultancy services, and educational YouTube content with Victor. Learn more at https://victorrentea.ro

Victor Rentea

May 29, 2024
Tweet

More Decks by Victor Rentea

Other Decks in Technology

Transcript

  1. 👋 I'm Victor Rentea 🇷🇴 Java Champion, PhD(CS) 18 years

    of coding ☕ 10 years of training at 130+ companies on: ❤ Refactoring, Architecture, Unit Tes4ng 🛠 Spring, Hibernate, Performance, Reac4ve Lead of European So4ware Cra4ers Community (7K developers) Mee4ng monthly online from 1700 CET. Free. Channel: YouTube.com/vrentea Life += 👰 + 👧 + 🙇 + 🐈 @victorrentea victorrentea.ro 🇷🇴 recorded
  2. 4 VictorRentea.ro a training by First Law of Architecture Everything

    is a trade-off. A decision without trade-off? Look harder! 🔨 Golden Hammer Over-reliance on a familiar tool eg. PL/SQL ftw 🤩 Shiny Object Syndrome This new technology will solve all my problems eg. microservices 🚨 Sales Pitch Enthusiastic preach of pros with no cons eg. AWS Song🎶
  3. 6 VictorRentea.ro a training by Second Law of Architecture Why

    is more important than How. ⚠ Context & requirements might change. ↓ Document all architectural decisions, eg via .ADR Pros/Cons & Tradeoffs Implementa@on Details
  4. 9 VictorRentea.ro a training by The code should always be

    a bit under-designed than the ideal. 🤔
  5. 10 VictorRentea.ro a training by Time è Features Design Keep

    it Simple for as long as possible DESIGN DEBT 🚨 Alarms: Sonar, ArchUnit.org OVER-ENGINEERING The code should always be a bit under-designed than the ideal. Evolu&onary Architecture
  6. 11 VictorRentea.ro a training by Instead of religiously following a

    'classic' textbook architecture, Observe the growing pain points of the project, and select the most helpful 'design increment' (eg boundary). Evolu&onary Architecture
  7. 13 VictorRentea.ro a training by Expose Domain Model in your

    API (eg. as JSON via HTTP / Message) ⚠ DANGER ⚠ Ø Domain Model Freezes: ❄ as clients depend on it Ø Security Risk: 🔐 Excessive Data Exposure Ø Pollutes the Domain with presenta=on: @JsonIgnore... Only expose Data Transfer Objects (DTOs) in your API @GetMapping("...") // REST API public Customer findById(... // Domain Model ±@Entity public class Customer {... Opinions? 🧐 DON'T
  8. 14 VictorRentea.ro a training by Separate Contract from Implementa6on Stable

    convenient API for client(s) Evolving to keep core complexity simple
  9. 17 VictorRentea.ro a training by Reusing the same DTO for

    GET + POST/PUT InventoryItemDto { "id": 13, "name": "Chair", "supplierName": "ACME", "supplierId": 78, "description": "Soft friend", "stock": 10, "status": "ACTIVE", "deactivationReason": null, "creationDate": "2021-10-01", "createdBy": "Wonder Woman" } { "id": null, "supplierName": null, . "status": null, . "deactivationReason": null, "creationDate": null, . "createdBy": null . } @GetMapping("{id}") InventoryItemDto get(id) { @PostMapping void create(InventoryItemDto) { Ab ß always null in create flow What's wrong? The Contract (OpenAPI) is: – misleading for clients 🥴 – confusing to implement – couples endpoints
  10. 18 VictorRentea.ro a training by InventoryItemDto { "id": 13, "name":

    "Chair", "supplierName": "ACME", "supplierId": 78, "description": "Soft friend", "stock": 10, "status": "ACTIVE", "deactivationReason": null, "creationDate": "2021-10-01", "createdBy": "Wonder Woman" } CQRS Dedicated Request/Response Dtos = CQRS at the API Level CreateItemRequest { "name": "Chair", "supplierId": 78, "description": "Soft friend", "stock": 10 } GetItemResponse { "id": 13, "name": "Chair", "supplierName": "ACME", "supplierId": 78, "description": "Soft friend", "stock": 10, "status": "ACTIVE", "deactivationReason": null, "creationDate": "2021-10-01", "createdBy": "Wonder Woman" } @GetMapping("{id}") GetItemResponse get(id) { @PostMapping void create(CreateItemRequest){ @NotNull in dto package
  11. 20 VictorRentea.ro a training by Command-Query Responsibility Segrega6on Most people

    perceive soJware systems as stores of records: that they Create, Read, Update, Delete and Search As system grows complex: - When READING : - we aggregate (SUM..) or enrich data (JOIN, API calls..) - key concern: speed - When UPDATING: - we store addi=onal data than we receive (createdBy=) - key concern: preserving consistency CQRS = use separate WRITE / READ models https://www.eventstore.com/blog/transcript-of-greg-youngs-talk-at-code-on-the-beach-2014-cqrs-and-event-sourcing
  12. 21 VictorRentea.ro a training by CQRS Levels CQRS at API

    level to Clarify Contract 👍 eg. CreateItemRequest / GetItemResponse CQRS at DB InteracHon to Improve Performance eg. READ: SELECT new dto.SearchResult(e.id, e.name), NOT SELECT e WRITE: use full En==es enforcing domain constraints Read from a Cache or Materialized Views (poten=ally stale ⏱) CQRS at Storage ("Full-CQRS") 👉 Read from a separate DB (ES, Redis, Mongo, ...) updated async⏱ higher performance 🔼 Strong Consistency 🔽 Eventual⏱ Consistency
  13. 23 VictorRentea.ro a training by Imagine a package "domain" What

    makes your app unique. The reason for its budget💰. What should GO inside? central data structures complex domain rules
  14. 24 VictorRentea.ro a training by infrastructure (accidental complexity) security send

    email via SMTP call an ugly APIs export a file batch orchestraHon domain COMPLEXITY ✨ ✨ ✨ ✨ ✨ Keep Clean! Protect Your Complexity against the Outside World Use a Library
  15. 26 VictorRentea.ro a training by Adapter interface infrastructure domain Service

    Adapter ☠ call direcQon code dependency «implements» Dependency Inversion Principle API call AVRO Legacy/shared Database
  16. 31 VictorRentea.ro a training by Program to Abstrac5ons Abstractions should

    create a new semantic level in which to be absolutely precise. CsvWriter -- Edsger Dijkstra .writeCell(String) .endLine() ; " \r\n UTF-8 simplifications
  17. 32 VictorRentea.ro a training by A complex problem Any problem

    in computer science can be solved by introducing another Layer of Abstraction - David Wheeler (corrupted quote)
  18. 33 VictorRentea.ro a training by Separa5on by Layers of Abstrac5on

    High-level flow kept simple Low-level details kept decoupled "Facade"
  19. 34 VictorRentea.ro a training by What's wrong in this picture?

    Hey ChatGPT, draw me the CTO of a multinational company washing his socks in the hotel sink. Breaks SLAb, Separa&on by Layers of Abstrac&on
  20. 37 VictorRentea.ro a training by Language user that clicks in

    UI —FE Dev applicaPon using OAuth —SecuTeam Library to call HTTP —BE Dev Depends on who you ask! Meaning of "Client"? company that purchased our product —Sales ... client ...
  21. 38 VictorRentea.ro a training by 1) Useless Synonyms Customer client;

    🚫 2) External CorrupAon if (product.code == dto.materialNumber && ☠)... // in my core complexity Used by everyone in the team (BE, FE, QA, PO, BA): in requirements, diagrams, emails, Slack phone, mee=ngs, ☕ break in code 💖 Ubiquitous Language 1 1 Word Concept
  22. 39 VictorRentea.ro a training by Postal Domain, in the Age

    of SOA Canonical Model (to be shared by 7 teams) parcel-v01.xsd (📦 core business) - 120 abributes (mee=ngs+😭) - extensions: Map<String, ?> ☠ ⚠ Cannot be Universal v17 Ubiquitous Language
  23. 40 VictorRentea.ro a training by To be useful, split Domain

    Model in Two interacting Models usually mean Three Languages Bounded Contexts
  24. 41 VictorRentea.ro a training by What a5ributes does a Product

    have? Depends on who you ask! In an eShop we all agree what a Product is. But:
  25. 42 VictorRentea.ro a training by class Product { 50 attributes

    ☠ } class Product { } // 50 attributes id name description attributes price sku quantity locationCode Which are required?😱 Domain Dilu-on
  26. 43 VictorRentea.ro a training by Modules class Product { }

    Catalog photo +7 more PricedProduct { } Bundle {..} Pricing offers +5... id class Article { } Inventory locationCode id name Split the Domain name description attributes price sku quantity + 4... id class Product { 50 attributes ☠ }
  27. 45 VictorRentea.ro Modulith Deployed as a Monolith Logical decoupling of

    Microservices + Easy to extract a Module as Microservice
  28. 46 VictorRentea.ro Legacy Monolith aka Big Ball of Mud Microservices

    XXL Database eShop ApplicaPon Catalog Microservice Catalog DB Orders Microservice Orders DB REST REST/MQ Payment Microservice Payment DB
  29. 48 VictorRentea.ro = a stand-alone logical applicaQon, having its own:

    §business features (user value) §private implementaJon: domain model + business logic §internal API for other modules §external API for other systems: REST, Rabbit, Ka[a... §private schema in a shared database §micro-frontend?: screens & shared components What is a Module? è See more in my talk Modular Monolith @ DevoxxUK 2024
  30. 50 VictorRentea.ro §Build dura@on & shared libraries + versions §Process

    Crash eg. OutOfMemoryError §StarvaAon of thread/DB connec@on pool §Shared Database overload & deadlocks §Modules Share TransacAons 👍/👎 Modulith Weaknesses @Transactional public void dumb(){ restApi.call(); }
  31. 52 VictorRentea.ro CV/Résumé-Driven Development Hype: Do you do "microservices", "cloud"

    and "AI"? – customer They're cool 😎 Why Microservices?
  32. 54 VictorRentea.ro No@fica@on Service SMS Email Post 🔥100K requests/sec 💥

    Occasional Crash Uses old lib 🚫Java17 ↺ Weekly Release User-Pref Audit Cohesive Name ❌DOWN Bulkhead Boundary ✅UP
  33. 55 VictorRentea.ro Benefits of Microservices ü Lower CogniAve Load =>

    😁 Developers ü Faster Time-to-Market (Vola@lity) if independently deployable by autonomous teams ü Scalability for the hot🔥 parts that require it ü Availability: fault-tolerance to par@al failures ü Technology Freedom vs language/library/version ü Security / Compliance ß Modulith can also provide this and a few others:
  34. 56 VictorRentea.ro Drawbacks of Microservices §Expensive to Enter: Deploy, Debug

    & Trace §Network Latency & Reliability §Asynchronous CommunicaAon via messages/events §Eventual Consistency, Caching $M1 premium
  35. 58 VictorRentea.ro a training by §Contract | ImplementaAon §Command |

    Query – CQRS §Domain | Infrastructure: adapt vs APIs & old/shared DB §High-Level | Low-Level – SLAb §Modular Monolith for Smaller Teams §Microservices for NFRs §Bulkhead – Failure Boundary SoGware Design Boundaries
  36. 59 VictorRentea.ro a training by §Team design mee+ngs: /quarter, /sprint

    at the start of a new project §Pair Program, talk to other teams in your org, request a project rota6on §Ask about key decisions & constraints (5xWhy?s). Learn to listen. §Ar+culate old/new decisions in an ADR §Always be available for anyone looking for design advice/brainstorming §Change mindset from expert programmer to problem solver / generalist §Read about: DDD, Microservices, Event-Driven in books, InfoQ,or DZone §Interview prep: github.com/ashishps1/awesome-system-design-resources §Watch videos/talks, eg: developertoarchitect.com/lessons §Workout with a buddy an Architecture Kata (nealford.com/katas) §Enroll a solu+oning compe++on hOps://www.oreilly.com/live- events/architectural-katas/0636920458487/ How to grow your Architecture Skills?