Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micro Frontends - Think Smaller, Avoid the Monolith Love the Backend

Micro Frontends - Think Smaller, Avoid the Monolith Love the Backend

Michael Geers

June 04, 2018

More Decks by Michael Geers

Other Decks in Technology


  1. Team Inspire Team Search Team Decide Team Checkout Backend Frontend

    Frontend Teaser Service Product Service Price Service Availability Service Payment Service Basket Service Customer Service API Gateway (Rest, BFF, GraphQL, …) Microservice Architecture
  2. Backend Frontend Team Inspire Self Contained Systems Team Search Team

    Decide Team Checkout has its own Technology Stack ships its Own UI is run by a Cross Functional Team stores its Own Data is assigned a Specific Mission smells like a Fat & T all Microservice
  3. Others who work like this Ikea Zalando Otto O!ce 365

    AutoScout24 Facebook Amazon? Hello Fresh gutefrage Spotify
  4. Team Inspire Team Decide Team Checkout Homepage Product List Product

    Details Basket Success A Page is Owned by one Team connected via Links <html> … … </html>
  5. Team Decide owns the page Team Inspire provides a fragment

    Team Checkout
 provides two fragments
  6. class CheckoutBasket extends HTMLElement { connectedCallback() { this.innerHTML = 'mini

    basket ...';
 customElements.define('checkout-basket', CheckoutBasket); Custom Elements
  7. Element Lifecycle class CheckoutBasket extends HTMLElement { constructor() {...}

 attributeChangedCallback(attr, oldVal, newVal) {...}
 disconnectedCallback() {...}
 } is created attached to DOM removed from DOM, cleanup! someone change an attribute
  8. the DOM is the API Teams publish their Custom Elements

    documentation Element-Name, Attributes, Events
  9. Google Books 2001 The easiest way to import external content

    into a Web page is to use a server-side include.
  10. Server Side Includes Server Team Decide nginx Server Team Checkout

    /red-tractor <html> <!--#include virtual=“/checkout/basket“ --> <h1>Tractor</h1> <!--#include virtual=“/checkout/buy“ --> </html> /red-tractor
  11. Server Side Includes Server Team Decide nginx Server Team Checkout

    /red-tractor <html> <!--#include virtual=“/checkout/basket“ --> <h1>Tractor</h1> <!--#include virtual=“/checkout/buy“ --> </html> /checkout/basket /checkout/buy /red-tractor
  12. Server Side Includes Server Team Decide nginx Server Team Checkout

    /red-tractor <html> <!--#include virtual=“/checkout/basket“ --> <h1>Tractor</h1> <!--#include virtual=“/checkout/buy“ --> </html> /checkout/basket /checkout/buy /red-tractor <button> buy for 66 € </button> <em>0 items</em> <html> <em>0 items</em> <h1>Tractor</h1> <button>buy for 66 €</button> </html>
  13. <inspire-reco sku="t_red"></inspire-reco> el.innerHTML = "<h3>Related Products</h3><ul>…") Browser Rehydration & User

    Interaction /inspire-reco?sku=t_red res.send("<h3>Related Products</h3><ul>…") Server Initial Render
  14. <inspire-reco sku="t_red">
 <!--#include virtual="/inspire-reco?sku=t_red" -->
 </inspire-reco> <checkout-basket>
 <!--#include virtual="/checkout-basket" -->

    </checkout-basket> <checkout-buy sku="t_red">
 <!--#include virtual="/checkout-buy?sku=t_red" -->
  15. Only Inside a Team Team A One Router per Team

    Hard Navigation 
 Page Refresh Team B /product /list Soft
 Navigation Client Rendered /success /cart Soft
 Navigation Client Rendered
  16. Top Level Router Shared Universal Router & Page Fragments HTML

    Shell with Router <a-product id="12">
 </a-product> <a-list name="toy">
 </a-list> <b-success>
 </b-success> <b-cart>
 </b-cart> const routes = { '/:name': 'a-list', '/p/:id': 'a-product', '/cart': 'b-cart',
 '/success': 'b-success' } Page-Fragments also take a look at single-spa
  17. As Global Stylesheet one globally included css file includes only

    styling used via css classes Pros -simple solution / easy to use -consistent look Cons -global css tends to grow -no easy way to detect unused css -breaking changes are hard cdn.example.org/global/styleguide.css à la Bootstrap
  18. As Versioned Package distributed via npm
 components with template &

    styling Pros -only used css is shipped -teams can upgrade independently -fragments don’t relay on outer styles Cons -requires build process (webpack, …) -common html-templating needed -temporary visual inconsistencies v1.1 v1.3 v2-beta v1.3
  19. Colorful Wood Structure Alexas_Fotos
 https://pixabay.com/en/background-colorful-wood- structure-3412048/ Clocks Pixabay
 https://www.pexels.com/photo/london-new-york-tokyo-and- moscow-clocks-48770/

    Octan Tower The Lego Movie
 recaptioned by @peeofive Action Bicycling Roman Pohorecki
 https://www.pexels.com/photo/action-bicycling-bike- biking-287398/ Four Playing Pieces Pixabay
 https://www.pexels.com/photo/set-of-4-wooden-elongated- accessory-209651/ Wooden Counter David Siglin
 https://www.pexels.com/photo/blur-blurry-bokeh-close- up-347139/ The Tool Guy Tirachard Kumtanom
 https://unsplash.com/photos/UuW4psOb388 Woodshop Igor Ovsyannykov
 https://unsplash.com/photos/iXV0i4Wo4yc Unicorn d97jro
 https://pixabay.com/de/lego-einhorn-spielzeug-671593/ Browser Logos Cătălin Mariș
 https://github.com/alrra/browser-logos Broken Escalator Skitterphoto
 https://freesound.org/people/dobroide/sounds/15227/ https://freesound.org/people/sittstav/sounds/171665/ Sad Lego Benny Cheezburger
 http://gph.is/1BCRCKh Wired Elements
 https://wiredjs.com/ Tractors Manufactum
 https://www.manufactum.com/tin-toys-c193667/ Credits built with Micro Frontends