Slide 1

Slide 1 text

@ManfredSteyer ManfredSteyer

Slide 2

Slide 2 text

@ManfredSteyer Do you remember her?

Slide 3

Slide 3 text

@ManfredSteyer Software Engineering is a Team Sport

Slide 4

Slide 4 text

@ManfredSteyer Coordination b/w Teams

Slide 5

Slide 5 text

@ManfredSteyer Monolith Flight System

Slide 6

Slide 6 text

@ManfredSteyer Booking Service Check-in Service Boarding Service Luggage Service Microservices Sub-Domains (DDD)

Slide 7

Slide 7 text

@ManfredSteyer Booking App Check-in App Boarding App Luggage App Microfrontends

Slide 8

Slide 8 text

@ManfredSteyer How to implement Microfrontends? ?

Slide 9

Slide 9 text

@ManfredSteyer Webpack 5 Module Federation

Slide 10

Slide 10 text

@ManfredSteyer Contents #1: Consequences of Microfrontends #2: Module Federation #3: Microfrontends FAQ

Slide 11

Slide 11 text

@ManfredSteyer About me… Manfred Steyer, ANGULARarchitects.io (Remote) Angular Workshops and Consulting Google Developer Expert for Angular Trusted Collaborator in the Angular Team Manfred Steyer

Slide 12

Slide 12 text

@ManfredSteyer #1: Consequences of Microfrontends

Slide 13

Slide 13 text

@ManfredSteyer Booking App Check-in App Boarding App Luggage App Autonomous Teams

Slide 14

Slide 14 text

@ManfredSteyer Autonomous Teams Separate Development Separate Deployment Own architecture decisions Own technology descisions

Slide 15

Slide 15 text

@ManfredSteyer Microfrontends are first and foremost about scaling teams!

Slide 16

Slide 16 text

@ManfredSteyer Challenges

Slide 17

Slide 17 text

@ManfredSteyer Challenges UI Composition UI Consistency Bundle Size/ Sharing Dependencies Version Conflicts between Microfrontends …

Slide 18

Slide 18 text

@ManfredSteyer Module Federation Solves Some of Them! UI Composition UI Consistency Bundle Size/ Sharing Dependencies Version Conflicts between Microfrontends …

Slide 19

Slide 19 text

@ManfredSteyer #2: Webpack 5 Module Federation

Slide 20

Slide 20 text

@ManfredSteyer DEMO

Slide 21

Slide 21 text

@ManfredSteyer How to load separately compiled code?

Slide 22

Slide 22 text

@ManfredSteyer Idea const Component = import('http://other-app/xyz') Does not work with webpack/ Angular CLI Even lazy parts must be known at compile time!

Slide 23

Slide 23 text

@ManfredSteyer Webpack 5 Module Federation Shell (Host) Microfrontend (Remote) // Maps Urls in // webpack config remotes: { mfe1: "mfe1" } // Expose files in // webpack config exposes: { Cmp: './my.cmp.ts' } import('mfe1/Cmp')

Slide 24

Slide 24 text

@ManfredSteyer How to Get the Microfrontend's URL? Shell (Host) Microfrontend (Remote) RemoteEntrypoint.js

Slide 25

Slide 25 text

@ManfredSteyer How to Share Libs? Shell (Host) Microfrontend (Remote) shared: [ "@angular/core", "…" ] shared: [ "@angular/core", "…" ]

Slide 26

Slide 26 text

@ManfredSteyer Conflicting Shared Libs Option A: Reuse it anyway Option B: Load own Both might be bad Prevent organizationally (e. g. conventions, contracts, monorepos) Integration-Testing

Slide 27

Slide 27 text

@ManfredSteyer DEMO

Slide 28

Slide 28 text

@ManfredSteyer Challenge for You

Slide 29

Slide 29 text

@ManfredSteyer ngx-Snake MIT License Credits: Samir Hodzic

Slide 30

Slide 30 text

@ManfredSteyer DEMO

Slide 31

Slide 31 text

@ManfredSteyer Challenge • Create a proper snake strategy • Publish it as a Module Federation Remote • Award Ceremony: ngCopenhagen Online Meetup • June 23th, 2020 • https://www.meetup.com/de-DE/ngCopenhagen/ • All Details • https://github.com/manfredsteyer/snake

Slide 32

Slide 32 text

@ManfredSteyer When can we have it?

Slide 33

Slide 33 text

@ManfredSteyer Well … Webpack 5 is currently beta Shown examples: PoC w/ custom webpack conf + patched CLI lib CLI: Not before version 11 (fall 2020) Squeeze federation config into CLI's webpack config Custom Builder (e. g. ngx-build-plus)

Slide 34

Slide 34 text

@ManfredSteyer #3: FAQ

Slide 35

Slide 35 text

@ManfredSteyer How To Identify Good Sub-Domains and hence Microfrontends?

Slide 36

Slide 36 text

@ManfredSteyer Request Product Specify Order Approve Order Send Order Budget Hierarchy Employee IT-Expert Manager Buying Agent Product

Slide 37

Slide 37 text

@ManfredSteyer "Right" Domain Size Should mirror a real-world domain Large enough: Most use cases don't overlap domains Small enough: One team per domain

Slide 38

Slide 38 text

@ManfredSteyer Domain Driven Design gives a lot of advice! Also see blog at: http://angulararchitects.io

Slide 39

Slide 39 text

@ManfredSteyer Monorepo or Polyrepo

Slide 40

Slide 40 text

@ManfredSteyer Catalog Approval Shared Feature Feature Feature Feature Feature … … … … … … … … … @ManfredSteyer Catalog App Approval App Option 1: One Monorepo w/ several Domains

Slide 41

Slide 41 text

@ManfredSteyer Consequences Easy to share code Decoupling b/w domains: Conventions or Tools (Linting) Easy to enforce one version policy Different technologies: possible

Slide 42

Slide 42 text

@ManfredSteyer Catalog Approval Shared Feature Feature Feature Feature Feature … … … … … … … … … @ManfredSteyer Catalog App Approval App Option 2: One Repo per Domains Publish shared libs seperately via npm

Slide 43

Slide 43 text

@ManfredSteyer Consequences Enforces decoupling b/w domains Allows different versions (good or bad?) Allows different technologies Needs lots of automation Sharing Code via npm and versioning might be a pain

Slide 44

Slide 44 text

@ManfredSteyer Recommentation, if you are not sure Start with a monorepo Enforce decoupling via linting Reconsider splitting into several repos later

Slide 45

Slide 45 text

@ManfredSteyer Pro Tip: Tooling for Monorepos https://nrwl.io/nx

Slide 46

Slide 46 text

@ManfredSteyer Communication

Slide 47

Slide 47 text

@ManfredSteyer Communication is a Trade-Off Decoupled Sub-Domains Communication b/w Sub-Domains

Slide 48

Slide 48 text

@ManfredSteyer Ideas As little as possible! Messaging/ Eventing: Loosly Coupling Trigger a (Domain) Event Don't expect an answer!

Slide 49

Slide 49 text

@ManfredSteyer Very Simple Message Bus @Injectable({ providedIn: 'root' }) export class MessageBus { events$ = new ReplaySubject(1); }

Slide 50

Slide 50 text

@ManfredSteyer Also Consider: Server-Side Messaging µService µFrontend µService µFrontend µService µFrontend

Slide 51

Slide 51 text

@ManfredSteyer Redux for Communication?

Slide 52

Slide 52 text

@ManfredSteyer Well … Don't directly share state b/w sub-domains (coupling!) You might use Redux for eventing (like a Message Bus)

Slide 53

Slide 53 text

@ManfredSteyer Sharing Widgets

Slide 54

Slide 54 text

@ManfredSteyer Sharing Widgets is a Trade-Off too Decoupled Sub-Domains Shared Widgets Prevent duplicate code (DRY) Separate Ways

Slide 55

Slide 55 text

@ManfredSteyer Recommentation Technical Widgets (e. g. Design System): Sharing ok Use Case-specific widgets: Try to avoid (coupling!)

Slide 56

Slide 56 text

@ManfredSteyer You can't have both: Decoupling and DRY ! Know your Architecture Goals!

Slide 57

Slide 57 text

@ManfredSteyer Good Message: Very often, Separate Ways DOES NOT mean duplicate code!

Slide 58

Slide 58 text

@ManfredSteyer Catalog Approval Bounded Context Ubiquitous Language

Slide 59

Slide 59 text

@ManfredSteyer Bounded Context per Sub-Domain Also see blog at: http://angulararchitects.io

Slide 60

Slide 60 text

@ManfredSteyer Web Components

Slide 61

Slide 61 text

@ManfredSteyer

Slide 62

Slide 62 text

@ManfredSteyer Recommentation Try to stick with one technology (e. g. Angular) --> Share framework-specific components Works in the short and mid run Eventually, when needed, export them as web components (e. g. w/ Angular Elements)

Slide 63

Slide 63 text

@ManfredSteyer Authentication and Authorization

Slide 64

Slide 64 text

@ManfredSteyer Possibilities HTTP Only Cookie: Tunnel through one origin (+XSRF Token) Token via Header: Different origins (consider OAuth2/OIDC) • Share token via message bus or session storage

Slide 65

Slide 65 text

@ManfredSteyer Microservice per Microfrontend?

Slide 66

Slide 66 text

@ManfredSteyer Recommendation: Verticals µService µFrontend µService µFrontend µService µFrontend

Slide 67

Slide 67 text

@ManfredSteyer Backend for Frontend (BFF) BFF µFrontend BFF µFrontend BFF µFrontend µServices µServices µServices µServices

Slide 68

Slide 68 text

@ManfredSteyer Nevertheless, try this approach if possible! µService µFrontend µService µFrontend µService µFrontend

Slide 69

Slide 69 text

@ManfredSteyer Dashboards

Slide 70

Slide 70 text

@ManfredSteyer Dashboard: Special Forces Decoupled Sub-Domains Dashboard Data and widgets from each subdomain

Slide 71

Slide 71 text

@ManfredSteyer Approaches Dashboard loads widgets from each sub-domain • Flexibility • Needs stable contracts • Agreements on common look and feel • Lots HTTP Calls Dashboard as a own sub-domain • Pros and Cons are inversed

Slide 72

Slide 72 text

@ManfredSteyer Backend for Frontend (BFF) Dashboard µBFF Dashboard µFrontend BFF µFrontend BFF µFrontend µServices µServices µServices µServices Messaging

Slide 73

Slide 73 text

@ManfredSteyer Free eBook ANGULARarchitects.io/book Updated for Module Federation and Alternatives

Slide 74

Slide 74 text

@ManfredSteyer Conclusion Main Purpose of µFrontends: Scaling Teams Decoupling Federation: Import From Other App Sharing Libs Take Care of Conflicts Know your Architecture Goals

Slide 75

Slide 75 text

@ManfredSteyer Be like Bonnie and think first! Evaluate whether you need µFrontends No: Majestic Monolith Yes: Consider Module Federation

Slide 76

Slide 76 text

@ManfredSteyer Contact and Downloads [web] ANGULARarchitects.io [twitter] ManfredSteyer d Slides & Examples Remote Company Workshops and Consulting