Slide 1

Slide 1 text

by Victor Rentea victorrentea.ro

Slide 2

Slide 2 text

👋 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

Slide 3

Slide 3 text

3 VictorRentea.ro a training by 💁 That's wrong!

Slide 4

Slide 4 text

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🎶

Slide 5

Slide 5 text

5 VictorRentea.ro a training by It depends... Ask: - Depends on what? - Two opposite examples?

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

7 VictorRentea.ro a training by Image from Head First – So7ware Architecture

Slide 8

Slide 8 text

8 VictorRentea.ro a training by Simplicity is the ultimate sophistication -- Leonardo DaVinci Keep It Simple !

Slide 9

Slide 9 text

9 VictorRentea.ro a training by The code should always be a bit under-designed than the ideal. 🤔

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

14 VictorRentea.ro a training by Separate Contract from Implementa6on Stable convenient API for client(s) Evolving to keep core complexity simple

Slide 15

Slide 15 text

15 VictorRentea.ro a training by Dto ftw!

Slide 16

Slide 16 text

16 VictorRentea.ro a training by Dto The -Dto suffix is an an,-pa/ern

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

19 VictorRentea.ro a training by CQRS Command-Query Responsibility Segrega6on Update Data Read Data

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

22 VictorRentea.ro a training by Separate Commands from Queries Read Update CQRS

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

25 VictorRentea.ro a training by Adapter interface infrastructure domain Service Adapter ☠ call direcQon code dependency

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

27 VictorRentea.ro a training by Separate Domain from Infrastructure Core Complexity Accidental Complexity

Slide 28

Slide 28 text

28 VictorRentea.ro a training by Complexity

Slide 29

Slide 29 text

29 VictorRentea.ro a training by W ho is here?

Slide 30

Slide 30 text

30 VictorRentea.ro a training by

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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)

Slide 33

Slide 33 text

33 VictorRentea.ro a training by Separa5on by Layers of Abstrac5on High-level flow kept simple Low-level details kept decoupled "Facade"

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

35 VictorRentea.ro a training by Separate High-Level Policy from Low-Level Details SLAb

Slide 36

Slide 36 text

36 VictorRentea.ro a training by Language

Slide 37

Slide 37 text

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 ...

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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 ☠ ⚠ Cannot be Universal v17 Ubiquitous Language

Slide 40

Slide 40 text

40 VictorRentea.ro a training by To be useful, split Domain Model in Two interacting Models usually mean Three Languages Bounded Contexts

Slide 41

Slide 41 text

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:

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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 ☠ }

Slide 44

Slide 44 text

44 VictorRentea.ro Modules Modul ith ar Monol

Slide 45

Slide 45 text

45 VictorRentea.ro Modulith Deployed as a Monolith Logical decoupling of Microservices + Easy to extract a Module as Microservice

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

47 VictorRentea.ro Modulith ApplicaPon Catalog Module Orders Module Payment Module Single Database FK call schemas

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

49 VictorRentea.ro a training by Split Team on Modules to reduce CogniAve Load

Slide 50

Slide 50 text

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(); }

Slide 51

Slide 51 text

51 VictorRentea.ro Next Step? Microservices! 🦄

Slide 52

Slide 52 text

52 VictorRentea.ro CV/Résumé-Driven Development Hype: Do you do "microservices", "cloud" and "AI"? – customer They're cool 😎 Why Microservices?

Slide 53

Slide 53 text

53 VictorRentea.ro Benefits of Microservices

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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:

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

57 VictorRentea.ro a training by Extract a Microservice for Non-FuncAonal Requirements

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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?

Slide 60

Slide 60 text

60 VictorRentea.ro a training by Thank you!