Micro Frontends - The Nitty Gritty Details or Frontend, Backend, 🌈 Happyend

A presentation at MicroCPH in May 2019 in Copenhagen, Denmark by Michael Geers

Slide 1

Slide 1

Micro Frontends the nitty gritty details OR frontend, backend, ! happyend

Slide 2

Slide 2

Michael Geers Frontend Engineer naltatis on Twitter & GitHub micro-frontends.org e-commerce Bremen, Germany

Slide 3

Slide 3

Frontend Monolith Black Diamond Royal Library, Copenhagen

Slide 4

Slide 4

faster feature development

Slide 5

Slide 5

Micro Frontends 1. what? 2. why? 3. how? 4. nitty gritty details “

Slide 6

Slide 6

but before … Where do we come from?

Slide 7

Slide 7

Frontend Backend The Monolith era of the full-stack developer

Slide 8

Slide 8

Frontend Backend Frontend Backend bye bye full stack

Slide 9

Slide 9

Frontend Backend specialists Team Inspire API Gateway (Rest, BFF, GraphQL) Product Service Teaser Service Team Search Team Decide Availability Service Price Service Team Checkout Basket Service Payment Service Customer Service Microservice Architecture Frontend

Slide 10

Slide 10

growing complexity no scaling Frontend Frontend Monoliths Frontend Frontend Frontend Backend API Gateway (Rest, BFF, GraphQL) Product Service Teaser Service The Monolith Front- & Backend Availability Service Price Service Basket Service Payment Service Microservices Customer Service

Slide 11

Slide 11

Backend Frontend Micro Frontends Team Inspire Team Search Team Decide Team Checkout

Slide 12

Slide 12

What are Micro Frontends?

Slide 13

Slide 13

Micro Frontends Definition … Our preferred (and proven) approach is to split the browser-based code into micro frontends. In this approach, the web application is broken down into its features, and each feature is owned, frontend to backend, by a different team. This ensures that every feature is developed, tested and deployed independently from other features. … ThoughtWorks Technology Radar https://www.thoughtworks.com/de/radar/techniques/micro-frontends Stages: Access (2016) > Trial (2017) > Adopt ⭐ (2019)

Slide 14

Slide 14

Autonomy own tech stack Team Inspire Team Decide self Team contained Checkout independent deployments

Slide 15

Slide 15

Team Missions „Make discovering and finding products easy.“ Team Inspire „Support the customer’s buying decision.“ Team Decide „Make the actual buying process happen.“ Team Checkout

Slide 16

Slide 16

technical organizational & Implications

Slide 17

Slide 17

Why Micro Frontends?

Slide 18

Slide 18

specialists team

Slide 19

Slide 19

cross functional team

Slide 20

Slide 20

Specialist Teams Cross Functional Teams Frontend Content Service Attributes Service Payment Service Team Inspire Business Team Decide Team Checkout Operations Platform grouped around a skill or technology grouped around a use case or customer need

Slide 21

Slide 21

Specialist Teams Cross Functional Teams Frontend Content Service Attributes Service Payment Service Team Inspire Business Team Decide Team Checkout Operations Platform grouped around a skill or technology grouped around a use case or customer need ⏳ inter-team developing a new feature communication

Slide 22

Slide 22

& Development Speed

Slide 23

Slide 23

Customer Focus direct feedback loop no pure api teams

Slide 24

Slide 24

Reduced Scope everything fits into memory again ❤ my

Slide 25

Slide 25

Frontend Renovation without throwing everything away

Slide 26

Slide 26

frontend tools change fast

Slide 27

Slide 27

Frontend be able to switch frameworks … React Vue.js React React → Elm Framework Switch MongoDB MySQL S3 Marco Architecture Phoenix Elixir AWS Lambda PostgreSQL Scala Play Spring Boot Java Scala Play Ruby on Rails Scala Play Database Backend GraphQL Cassandra Micro Architecture

Slide 28

Slide 28

… or upgrade at your own pace. Page 1.3 1.4 Database Backend Frontend 1.4 Fragment Wonder.js Wonder.js Wonder.js Wonder.js v1.3 v1.3 v1.3 v1.3 → v1.4 Spring Boot Java Spring Boot Java Spring Boot Java Spring Boot Java PostgreSQL PostgreSQL PostgreSQL PostgreSQL Version Upgrade

Slide 29

Slide 29

Who works like this?

Slide 30

Slide 30

What’s our experience?

Slide 31

Slide 31

New e-commerce platforms 116 department stores in Germany & Belgium 2014 5 teams 6-8 people/team premium material goods print catalogs & 9 stores 2016 2 teams 5-7 people/team premium fashion 11 department stores 2016 5 teams 6-10 people/team

Slide 32

Slide 32

Project: Next Level Commerce green field project fashion for best ager 15 brands in up to 12 countries ~ 65 online stores 2018 5 teams 7-10 people/team from 3 dev-companies after 2 month go-live with a newly created brand taschenherz.com 6 month later first migration of a real brand mona.de

Slide 33

Slide 33

How to implement?

Slide 34

Slide 34

A Page is Owned by one Team Customer Journey 1 1 1 2 2 33 $ 66 $ $$ 66 $ %% 99 $ home list Team Inspire detail Team Decide buy basket Team Checkout payment confirm

Slide 35

Slide 35

Including Fragments from other Teams Team Decide Team Inspire Fragment Page Team Checkout Fragment

Slide 36

Slide 36

Server Side Integration

Slide 37

Slide 37

via Links Customer Journey 1 1 1 2 2 33 $ 66 $ $$ 66 $ %% 99 $ home list Team Inspire detail Team Decide buy basket Team Checkout payment confirm

Slide 38

Slide 38

Team Decide owns the page Team Inspire provides a fragment Team Checkout provides two fragments

Slide 39

Slide 39

via iframes Advantages - strong isolation work everywhere Disadvantages - bad for SEO load performance layout constrains poor accessibility ? Y L R O

Slide 40

Slide 40

via iframes Spotify web player (until early 2019) & desktop app https://labs.spotify.com/2019/03/25/building-spotifys-new-web-player/

Slide 41

Slide 41

SSI Server Side Includes* <!—#include virtual=”/some-url” —> *or ESI Edge Side Includes - they have similar taste

Slide 42

Slide 42

The easiest way to import external content into a Web page is to use a server-side include. 2001 Google Books

Slide 43

Slide 43

Server Team Decide <button> buy for 66 € </button> /checkout/buy <em>0 items</em>

<html> <!—#include virtual=“/checkout/basket“ —> <h1>Tractor</h1> <!—#include virtual=“/checkout/buy“ —> </html> /checkout/basket /red-tractor nginx Server Team Checkout Server Side Includes /red-tractor <html> <em>0 items</em> <h1>Tractor</h1> <button>buy for 66 €</button> </html>

Slide 44

Slide 44

Client Side Integration

Slide 45

Slide 45

Team Decide Interactivity owns the page Team Inspire provides a fragment Team Checkout provides two fragments

Slide 46

Slide 46

Each Fragment as a Mini Application Team Decide Team Inspire Fragment Page Team Checkout Fragment

Slide 47

Slide 47

Web Components Custom Elements Shadow DOM HTML Template

Slide 48

Slide 48

Custom Elements <checkout-basket></checkout-basket> https://developers.google.com/web/fundamentals/getting-started/primers/customelements

Slide 49

Slide 49

Custom Elements class CheckoutBasket extends HTMLElement { connectedCallback() { this.innerHTML = ‘mini basket …’; } } ()) Choo customElements.define(‘checkout-basket’, CheckoutBasket);

Slide 50

Slide 50

Element Lifecycle class CheckoutBasket extends HTMLElement { constructor() {…} is created connectedCallback() {…} attached to DOM attributeChangedCallback(attr, oldVal, newVal) {…} disconnectedCallback() {…} } removed from DOM, cleanup! someone changed an attribute

Slide 51

Slide 51

Browser Support in Custom Elements v1 API stabilized end of 2016 t n e m p o l e v e d

Slide 52

Slide 52

Browser Support 11 with Polyfill (6KB) https://github.com/webcomponents/custom-elements

Slide 53

Slide 53

<checkout-basket> </checkout-basket> <inspire-reco sku=”t_red”> </inspire-reco> <checkout-buy sku=”t_red”> </checkout-buy>

Slide 54

Slide 54

<checkout-basket> </checkout-basket> n e e r g t_ <inspire-reco sku=”t_red”> </inspire-reco> n e e r g _ t <checkout-buy sku=”t_red”> </checkout-buy>

Slide 55

Slide 55

the DOM is the API Teams publish their Custom Elements documentation Element-Name, Attributes, Events

Slide 56

Slide 56

Page Transitions

Slide 57

Slide 57

Only Inside a Team one router per team Team B Team A Soft Navigation /list Client Rendered /product Hard Navigation Links Soft Navigation /cart Client Rendered /success

Slide 58

Slide 58

App Shell Across Teams meta router & router per team increased complexity! shared runtime code harder debugging Team B Team A Soft Navigation Client Rendered Soft Navigation /list Client Rendered /product Soft Navigation /cart Client Rendered /success

Slide 59

Slide 59

Short Integration Recap Pages Fragments Server Links SSI/ESI Client App-Shell Meta-Router Web Components

Slide 60

Slide 60

other Libraries & Meta Frameworks Podium https://github.com/CanopyTax/single-spa https://github.com/opencomponents/oc https://podium-lib.io https://github.com/onerzafer/microfe-client meta-spa-router https://github.com/zalando/tailor https://github.com/manfredsteyer/meta-router

Slide 61

Slide 61

nitty gritty details “

Slide 62

Slide 62

coherent ux & design

Slide 63

Slide 63

Have a Design System Design System / Pattern Library Contents Design Tokens (fonts, colors, …) Usable Components (buttons, …) Aspects Design Users Experience Performance Accessibility Dev Experience Tools: UIengine, Storybook, …

Slide 64

Slide 64

Distributed as Versioned Package v1.3 Shared Design System v1.1 v1.2 v1.3 v2-beta … v1.1 v2-beta Team Inspire v1.3 Team Checkout v1.1 Team Decide v1.3 v2-beta

Slide 65

Slide 65

  • web performance

Slide 66

Slide 66

Performance First measure regularly pick your metrics Tools Lighthouse Sitespeed.io WebpageTest Speedcurve … Metrics Lighthouse Scores Time to Interactive Visually Complete Page Weight …

Slide 67

Slide 67

integrate perf into you culture Break the build! set a budget and enforce it Discuss alternatives with team and product owner Attribution is not always easy due to fragments & 3rd party. Page-owner is in the lead!

Slide 68

Slide 68

make responsible tech choices large framework runtime hyperapp small runtimes

Slide 69

Slide 69

, quality & testing

Slide 70

Slide 70

testing in isolation dummy fragment product page works without fragments Team Decide owns & tests major ity of the te sts

Slide 71

Slide 71

testing in isolation dummy fragment header & footer are standalone fragments Team Search owns & tests product page works without fragments Team Decide owns & tests major ity of the te sts

Slide 72

Slide 72

testing accross boundaries … increments this. cross team tests exist but are the exception Clicking here … In som e cases

Slide 73

Slide 73

— knowledge sharing

Slide 74

Slide 74

regular rituals mostly weekly people from all teams talk on a specific topic guildes arch frontend tracking security kubernetes …

Slide 75

Slide 75

1 . 0 / vertical depth

Slide 76

Slide 76

How Deep Should a Vertical Team be? frontend only scaling development ✔ easier rebuilds ✔ 1 . 0 / Frontend Backend Operations Data Science Business & Stakeholder full-stack team faster development ✔ less coordination ✔ and these full autonomy fast trial of ideas ✔ adapt quickly ✔ and these

Slide 77

Slide 77

Want to learn more? Extensive Link Collection by Elisabeth Engel @lizzelo Microservice Websites by Gustav Nilsson Kotte @gustaf_nk Micro Frontends at DAZN by Luca Mezzalira @lucamezzalira micro-frontends.org by Me @naltatis 2 Self-Contained Systems by INNOQ Talk: Frontend Monolith by Stefan Tilkov @stilkov

Slide 78

Slide 78

I’m writing a book Michael Geers MEAP - Manning Early Access Program this summer follow @naltatis or @manningbooks for updates MANNING

Slide 79

Slide 79

Frontend lets’ blur this line! Backend

Slide 80

Slide 80

Frontend let’s blur this line! Backend

Slide 81

Slide 81

Thanks for listening! ! happyend Michael Geers @naltatis

Slide 82

Slide 82