Slide 1

Slide 1 text

Curious Code and Where to Find it .NET Day Switzerland 2024

Slide 2

Slide 2 text

The infamous microservice project .NET Day Switzerland 2024

Slide 3

Slide 3 text

an opinionated talk about my curious experience with a microservice project 05.09.2024 WE KNOW HOW. 3

Slide 4

Slide 4 text

an opinionated talk about my curious experience with a microservice project 05.09.2024 WE KNOW HOW. 4 your mileage may vary!

Slide 5

Slide 5 text

Alexander Kayed 05.09.2024 WE KNOW HOW. 5 Alex MSc ETH in Computer Science github.com/akade linkedin.com/alexander-kayed Senior Software Engineer / Architect / Trainer / Speaker

Slide 6

Slide 6 text

Alexander Kayed 05.09.2024 WE KNOW HOW. 6 Alex MSc ETH in Computer Science github.com/akade linkedin.com/alexander-kayed Senior Software Engineer / Architect / Trainer / Speaker

Slide 7

Slide 7 text

Alexander Kayed 05.09.2024 WE KNOW HOW. 7 Alex MSc ETH in Computer Science github.com/akade linkedin.com/alexander-kayed Senior Software Engineer / Architect / Trainer / Speaker

Slide 8

Slide 8 text

Alexander Kayed 05.09.2024 WE KNOW HOW. 8 Alex MSc ETH in Computer Science github.com/akade linkedin.com/alexander-kayed Senior Software Engineer / Architect / Trainer / Speaker

Slide 9

Slide 9 text

05.09.2024 WE KNOW HOW. 9

Slide 10

Slide 10 text

The Project 05.09.2024 WE KNOW HOW. 10 • SaaS / Multi-Tenant • Diverse clients • Based all over Switzerland

Slide 11

Slide 11 text

The Project 05.09.2024 WE KNOW HOW. 11 • Long-running inhouse project • Since fall 2017 • tech lead 2022 – 2024 • 3-5 engineers • Agile

Slide 12

Slide 12 text

The Project 05.09.2024 WE KNOW HOW. 12 • Long-running inhouse project • Since fall 2017 • tech lead 2022 – 2024 • 3-5 engineers • Agile • «Kanbanesque»

Slide 13

Slide 13 text

The Project 05.09.2024 WE KNOW HOW. 13 • Long-running inhouse project • Since fall 2017 • tech lead 2022 – 2024 • 3-5 engineers • Agile • «Kanbanesque» • Regular exchange with «working group»

Slide 14

Slide 14 text

The Project 05.09.2024 WE KNOW HOW. 14 • Long-running inhouse project • Since fall 2017 • tech lead 2022 – 2024 • 3-5 engineers • Agile • «Kanbanesque» • Regular exchange with «working group» • Happy clients and growing fast!

Slide 15

Slide 15 text

The Project 05.09.2024 WE KNOW HOW. 15 • Long-running inhouse project • Since fall 2017 • tech lead 2022 – 2024 • 3-5 engineers • Agile • «Kanbanesque» • Regular exchange with «working group» • Happy clients and growing fast! Public Domain – Battle of Dornach

Slide 16

Slide 16 text

The Project 05.09.2024 WE KNOW HOW. 16 • Microservices • CQRS – Command Query Separation Principle • Event Sourcing

Slide 17

Slide 17 text

The Project 05.09.2024 WE KNOW HOW. 17 • Microservices • CQRS – Command Query Separation Principle • Event Sourcing ~per aggregate

Slide 18

Slide 18 text

The Project 05.09.2024 WE KNOW HOW. 18 • Microservices • CQRS – Command Query Separation Principle • Event Sourcing Separated read / write service ~per aggregate

Slide 19

Slide 19 text

The Project 05.09.2024 WE KNOW HOW. 19 • Microservices • CQRS – Command Query Separation Principle • Event Sourcing Separated read / write service ~per aggregate All aggregates are materialized in-memory («hydrated»)

Slide 20

Slide 20 text

The Project 05.09.2024 WE KNOW HOW. 20 • Microservices • CQRS – Command Query Separation Principle • Event Sourcing Separated read / write service ~per aggregate No Codesharing Multirepo All aggregates are materialized in-memory («hydrated»)

Slide 21

Slide 21 text

All aggregates are materialized in-memory («hydrated») The Project 05.09.2024 WE KNOW HOW. 21 • Microservices • CQRS – Command Query Separation Principle • Event Sourcing Separated read / write service ~per aggregate No codesharing

Slide 22

Slide 22 text

The Project 05.09.2024 WE KNOW HOW. 22

Slide 23

Slide 23 text

The Project 05.09.2024 WE KNOW HOW. 23

Slide 24

Slide 24 text

The Project 05.09.2024 WE KNOW HOW. 24

Slide 25

Slide 25 text

The Project 05.09.2024 WE KNOW HOW. 25 References via Nuget

Slide 26

Slide 26 text

The Project 05.09.2024 WE KNOW HOW. 26 Dev loop: Manual running of pipelines and manual updating of packages

Slide 27

Slide 27 text

The Project 05.09.2024 WE KNOW HOW. 27 Multirepo: 22x Pullrequests

Slide 28

Slide 28 text

The Project 05.09.2024 WE KNOW HOW. 28 To Release while (something changes) Update all packages & push Wait for CI-Builds to complete

Slide 29

Slide 29 text

The Project 05.09.2024 WE KNOW HOW. 29 Green = «In-Memory State Nugets»

Slide 30

Slide 30 text

The Project 05.09.2024 WE KNOW HOW. 30 Green = «In-Memory State Nugets»

Slide 31

Slide 31 text

The Project 05.09.2024 WE KNOW HOW. 31 Replicated state => Local debugging is impossible

Slide 32

Slide 32 text

The Project 05.09.2024 WE KNOW HOW. 32 Monolith

Slide 33

Slide 33 text

The Project 05.09.2024 WE KNOW HOW. 33 Monolith Distributed Monolith

Slide 34

Slide 34 text

The Project 05.09.2024 WE KNOW HOW. 34 https://wallpapercave.com/wp/wp7351908.jpg

Slide 35

Slide 35 text

Motivation 05.09.2024 WE KNOW HOW. 35

Slide 36

Slide 36 text

Motivation Microservices 05.09.2024 WE KNOW HOW. 36 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • Microservices are very small • No stable contracts • Tight coupling • Distributed tight coupling!! • Lackluster tooling support over multiple repos and nuget packages • Heterogeneity of services • Anticipating consequences is hard • Curious day-to-day development

Slide 37

Slide 37 text

Motivation Microservices 9/5/2024 WE KNOW HOW. 37 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • Microservices are very small • No stable contracts • Tight coupling • Distributed tight coupling!! • Lackluster tooling support over multiple repos and nuget packages • Heterogeneity of services • Anticipating consequences is hard • Curious day-to-day development

Slide 38

Slide 38 text

Motivation Microservices 9/5/2024 WE KNOW HOW. 38 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • Target: 99.999% • = ~5 min/y! • Rehydration of in-memory state (Event Sourcing) takes 2-3h • Clients work only 9 to 5

Slide 39

Slide 39 text

Motivation Microservices 05.09.2024 WE KNOW HOW. 39 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • Target: 99.999% • = ~5 min/y! • Rehydration of in-memory state (Event Sourcing) takes 2-3h • Clients work only 9 to 5

Slide 40

Slide 40 text

Motivation Microservices 05.09.2024 WE KNOW HOW. 40 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • Theoretically possible • But never used! • Different library versions in different services • => hard to debug / know, what is used where • => possibility of inconsistent data (in-memory state)

Slide 41

Slide 41 text

Motivation Microservices 05.09.2024 WE KNOW HOW. 41 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • Theoretically possible • But never used! • Different library versions in different services • => hard to debug / know, what is used where • => possibility of inconsistent data (in-memory state)

Slide 42

Slide 42 text

Motivation Microservices 05.09.2024 WE KNOW HOW. 42 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • Rehydration time • Dynamic, horizontal scaling not possible / slow • Concurrent Users: max. 1000 • Performance / Latency • In-Memory but often full-scans • Network Hops

Slide 43

Slide 43 text

Motivation Microservices 05.09.2024 WE KNOW HOW. 43 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • Rehydration time • Dynamic, horizontal scaling not possible / slow • Concurrent Users: max. 1000 • Performance / Latency • In-Memory but often full-scans • Network Hops

Slide 44

Slide 44 text

Motivation Microservices 05.09.2024 WE KNOW HOW. 44 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • All «own» services are .NET • Heterogeneity is more a disadvantage • But: • ElasticSearch • Kibana • Prometheus • Grafana • PowerShell Container • …

Slide 45

Slide 45 text

Motivation Microservices 05.09.2024 WE KNOW HOW. 45 • Changeability • Availability • Strong module boundaries • Independent deployment • Independent scalability • Independent technology choice • Traceability (Event Sourcing)

Slide 46

Slide 46 text

Lessons learned 05.09.2024 WE KNOW HOW. 46 • Concepts have trade-offs and effect each other • Data persistence (event sourcing) & queries affect each other • Queries over all aggregates  dynamic rehydration impossible • Always ask why • Horizontal Scaling • Fast responses during peak traffic cost-effectivity during low traffic

Slide 47

Slide 47 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 47 What id format should we use?

Slide 48

Slide 48 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 48 What id format should we use? distributed system

Slide 49

Slide 49 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 49 What id format should we use? distributed system database friendly

Slide 50

Slide 50 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 50 What id format should we use? distributed system database friendly Twitter Snowflake (64bit) 41 bit timestamp Machine id 10 bits 12 bits sequence

Slide 51

Slide 51 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 51 What id format should we use? distributed system database friendly Twitter Snowflake (52bit) 41 bit timestamp Machine id 10 bits 12 bits sequence No integers in JS-Land

Slide 52

Slide 52 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 52 What id format should we use? distributed system database friendly Twitter Snowflake (52bit) 41 bit timestamp 4 bits 6 bits No integers in JS-Land

Slide 53

Slide 53 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 53 52-bit snowflake ids Frontend needs offline support for new ids

Slide 54

Slide 54 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 54 52-bit snowflake ids

Slide 55

Slide 55 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 55 ID Prefetching 52-bit snowflake ids

Slide 56

Slide 56 text

Curious Code – an example 05.09.2024 WE KNOW HOW. 56 What id format should we use? distributed system database friendly Twitter Snowflake (52bit) 41 bit timestamp 4 bits 6 bits Guid? What indices would suffer? Max 16 services? Max 64 Ids/ms 52-bit snowflake ids

Slide 57

Slide 57 text

Lessons learned 05.09.2024 WE KNOW HOW. 57 • There are always dependencies!

Slide 58

Slide 58 text

Lessons learned 05.09.2024 WE KNOW HOW. 58 • There are always dependencies! HTTP Container

Slide 59

Slide 59 text

Lessons learned 05.09.2024 WE KNOW HOW. 59 • There are always dependencies! Method call on interface Class

Slide 60

Slide 60 text

Lessons learned 05.09.2024 WE KNOW HOW. 60 • There are always dependencies! Message Pod

Slide 61

Slide 61 text

Martin Fowler 05.09.2024 WE KNOW HOW. 61 1. Almost all the successful microservice stories have started with a monolith that got too big and was broken up.

Slide 62

Slide 62 text

Martin Fowler 05.09.2024 WE KNOW HOW. 62 1. Almost all the successful microservice stories have started with a monolith that got too big and was broken up. 2. Almost all the cases where I've heard of a system that was built as a microservice system from scratch, it has ended up in serious trouble. https://martinfowler.com/bliki/MonolithFirst.html

Slide 63

Slide 63 text

Modulith 05.09.2024 WE KNOW HOW. 63 Method call on interface Class

Slide 64

Slide 64 text

Modulith to Microservices 05.09.2024 WE KNOW HOW. 64

Slide 65

Slide 65 text

Modulith to Microservices 05.09.2024 WE KNOW HOW. 65

Slide 66

Slide 66 text

Microservices 05.09.2024 WE KNOW HOW. 66

Slide 67

Slide 67 text

Where are the people? 05.09.2024 WE KNOW HOW. 67 Refactoring Is Not Just Clickbait - Kevlin Henney - NDC Oslo 2022 “Software Architecture is for developers to live inside” Kevlin Henney

Slide 68

Slide 68 text

Why Microservices? 05.09.2024 WE KNOW HOW. 68 • […] One of its goals is that teams can develop and deploy their services independently of others. […] Quote from https://en.wikipedia.org/wiki/Microservices

Slide 69

Slide 69 text

Why Microservices? 05.09.2024 WE KNOW HOW. 69 • […] One of its goals is that teams can develop and deploy their services independently of others. […] Spotify: >3000 Engineers A single team (~4 members) Quote from https://en.wikipedia.org/wiki/Microservices

Slide 70

Slide 70 text

Improvements 05.09.2024 WE KNOW HOW. 70 • Code Sharing • Harmonize services • Merge tiny services • Automatization • Tracing & Logging

Slide 71

Slide 71 text

Improvements 05.09.2024 WE KNOW HOW. 71 • Monorepo • Project references • Automation: CLI • …

Slide 72

Slide 72 text

Multi- to Monorepo 05.09.2024 WE KNOW HOW. 72 • Matches organization • One team • One application • One deployment unit • One PR per feature • Main challenge: Hotfix & merging during transition Conclusion • Game changer • Easier day-to-day work • Productivity gains!

Slide 73

Slide 73 text

Nuget to project references 05.09.2024 WE KNOW HOW. 73 • Advantages project references • Tooling support • Direct builds & testing • Reasoning over changes and consequences much easier • Main challenge: complicated pipeline triggers

Slide 74

Slide 74 text

Project references 05.09.2024 WE KNOW HOW. 74 Conclusion • Even bigger game changer • Immensely easier day-to-day live • Huge productivity gains! Together with the monorepo: Essential for moving foward with refactoring & features

Slide 75

Slide 75 text

Automation via our own CLI 05.09.2024 WE KNOW HOW. 75 • Generates & validates pipelines • Trigger always match project references • Minimal friction for refactoring or bigger updates (i.e. .NET 9) • … • Build & Deploy • Reduces day-to-day toil • Minimizing errors due to cumbersome manual steps

Slide 76

Slide 76 text

CLI 05.09.2024 WE KNOW HOW. 76 Conclusion • Worthwhile • Less sources of errors • (Big) refactoring much easier

Slide 77

Slide 77 text

Conclusion 05.09.2024 WE KNOW HOW. 77 • Never stop asking why • Be curious! • Be mindful with complexity • There is no one size fits all! • Do not forget the people including developers • Improved dev live is a win-win situation

Slide 78

Slide 78 text

Conclusion 05.09.2024 WE KNOW HOW. 78 • Never stop asking why • Be curious! • Be mindful with complexity • There is no one size fits all! • Do not forget the people including developers • Improved dev live is a win-win situation • Interesting and complex but also very successful project. Keep calm and refactor!

Slide 79

Slide 79 text

Questions 05.09.2024 WE KNOW HOW. 79

Slide 80

Slide 80 text

Questions 05.09.2024 WE KNOW HOW. 80