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

SPAs and Micro Services: How does this come together?

SPAs and Micro Services: How does this come together?

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

January 24, 2019
Tweet

Transcript

  1. @ManfredSteyer SPAs and Micro Services: How does this come together?

    Manfred Steyer SOFTWAREarchitekt.at ManfredSteyer
  2. @ManfredSteyer Ever build a software from the scratch? Kick-off After

    some weeks After some years
  3. @ManfredSteyer Idea System

  4. @ManfredSteyer Idea µService µService µService

  5. @ManfredSteyer Idea µService µService µService Single Page Application ??

  6. @ManfredSteyer Contents 1) Why SPAs? 2) Deployment Monolith 3) Hyperlinks

    4) Shell 5) How to choose?
  7. @ManfredSteyer About me… • Manfred Steyer • SOFTWAREarchitekt.at • Angular

    Trainings and Consultancy • Google Developer Expert (GDE) Page ▪ 7 Manfred Steyer Public: Wien, München, Stuttgart, Frankfurt In-House: everywhere http://softwarearchitekt.at/workshops
  8. @ManfredSteyer

  9. @ManfredSteyer DEMO

  10. @ManfredSteyer 2) Deployment Monolith

  11. @ManfredSteyer Idea µService µService µService Client Fragment Client Fragment Client

    Fragment ✓ Easy (Tooling) ✓ One optimized bundle set ✓ Consistent  No separate deployment  Mixing Technologies: Difficult  Kopplung npm Packages ?
  12. @ManfredSteyer npm Registries Nexus Artifactory Team Foundation Server Verdaccio npm

    i -g verdaccio verdaccio
  13. @ManfredSteyer Advantages • Distribution • Versioning

  14. @ManfredSteyer Disadvantages • Distribution • Versioning ;-)

  15. @ManfredSteyer Disadvantages Distribution • Annoying within project Versioning • Old

    versions • Conflicts • How to force devs to use latest version?
  16. @ManfredSteyer Monorepo

  17. @ManfredSteyer Workspace

  18. @ManfredSteyer Advantages Everyone uses the latest versions No version conflicts

    No burden with distributing libs Creating new libs: Adding folder Experience: Successfully used at Google, Facebook, …
  19. @ManfredSteyer Moving back and forth Npm Registry

  20. @ManfredSteyer Advantages Sub Project Sub Project Sub Project Sub Project

    Sub Project Sub Project Sub Project Sub Project
  21. @ManfredSteyer Disadvantages Sub Project Sub Project Sub Project Sub Project

    Sub Project Sub Project Sub Project Sub Project
  22. @ManfredSteyer Disadvantages Sub Project Sub Project Sub Project Sub Project

    Sub Project Sub Project Sub Project Sub Project Team A Team B Contract
  23. @ManfredSteyer Disadvantages One Architecture One Technology Stack Hard to change

    No self- contained teams One size fits all?
  24. @ManfredSteyer 2) Hyperlinks

  25. @ManfredSteyer UI Composition w/ Hyperlinks µApp SPA µApp SPA µApp

    SPA <a href="…">…</a> <a href="…">…</a>
  26. @ManfredSteyer

  27. @ManfredSteyer

  28. @ManfredSteyer ✓ Simple  Loosing State  Load a new

    Application
  29. @ManfredSteyer

  30. @ManfredSteyer Web Components for Shared Widgets?

  31. @ManfredSteyer Framework independent Components

  32. @ManfredSteyer

  33. @ManfredSteyer Can be polyfilled down to IE11

  34. @ManfredSteyer Communication b/w µApps µApp µApp µApp Backend HTTP, Web

    Sockets, SSE, …
  35. @ManfredSteyer Communication b/w µApps µApp µApp /app2/xyz/17?p=42 /app1/abc/42

  36. @ManfredSteyer 3) Shell

  37. @ManfredSteyer µService Providing a (SPA based) Shell µApp µApp µApp

    Shell ▪ iframes ▪ Bootstrapping several SPAs ▪ + Lazy Loading
  38. @ManfredSteyer Wrap µApps into Web Components • Not a typical

    web component! • But: Unified API for Shell • Nesting
  39. @ManfredSteyer Loading MicroApps <script src="micro-app.bundle.js"></script> <micro-app></micro-app>

  40. @ManfredSteyer DEMO

  41. @ManfredSteyer Communication b/w Micro Apps (Web Components) <client-a [state]="appState" (message)="handle($event)"></client-a>

    <client-b [state]="appState" (message)="handle($event)"></client-b> JavaScript in Shell
  42. @ManfredSteyer Routing /client-a/this/that /client-b/this/that /client-c/this/that :

  43. @ManfredSteyer Routing /client-a/this/that /client-b/this/that /client-c/this/that :

  44. @ManfredSteyer Bundles Custom Element 1 Custom Element 2 Custom Element

    3 Libraries: Angular, Bootstrap, … Libraries: Angular, Bootstrap, …
  45. @ManfredSteyer Downlevel to VanillaJS (Angular Ivy, Stencil, lit-html, …) Custom

    Element 1 Custom Element 2 Custom Element 3
  46. @ManfredSteyer Sharing Libs Custom Element 1 Custom Element 2 Custom

    Element 3 Libraries: Angular, Bootstrap, … UMD Drawbacks: Complexity, no isolation
  47. @ManfredSteyer

  48. @ManfredSteyer Communication b/w Micro Apps (iframes) <iframe src="…"></iframe> <iframe src="…"></iframe>

    JavaScript in Shell postMessage(…) postMessage(…) message Event message Event
  49. @ManfredSteyer Further Challenges w/ iframes Routing: Sync routes b/w shell

    and iframes Resize iframes to prevent scrolling No overlapping
  50. @ManfredSteyer Advantage • Several small and decoupled Projects

  51. @ManfredSteyer Disadvantages • Several small and decoupled Projects ;-) •

    More Bundles • Less optimized Bundles/ duplicate Code? • UI Consistency?
  52. @ManfredSteyer 4) Choosing a Solution

  53. @ManfredSteyer Some General Advice Shared state, navigation b/w apps Hyperlinks

    Legacy Apps or *very very* strong isolation? iframes Separate Deployment/ mix Technologies? Web Components Monolith w/ Libs and Monorepo little much yes no yes no Not a good fit for public web sites
  54. @ManfredSteyer Architecture within Micro-Apps Packages Web Components Monorepo Inner Sourcing

    Separate Wey …
  55. @ManfredSteyer Blog > SOFTWAREarchitekt.at • A Software Architect's Approach Towards

    Using Angular (And SPAs In General) For Microservices Aka Microfrontends • A Lightweight And Solid Approach Towards Micro Frontends (Micro Service Clients) With Angular And/Or Other Frameworks • Micro Apps With Web Components Using Angular Elements
  56. @ManfredSteyer Conclusion Monorepo Hyper Links Shell You need to evaluate!

  57. @ManfredSteyer Beware the Frankenstein- Monster on the client too!

  58. @ManfredSteyer Contact and Downloads [mail] manfred.steyer@SOFTWAREarchitekt.at [web] SOFTWAREarchitekt.at [twitter] ManfredSteyer

    d http://softwarearchitekt.at/workshops Slides & Examples