75
Introduction to Micro Frontends @ivanjov96

Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Introduction to Micro Frontends

@ivanjov96

Page 2: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 3: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 4: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

We want something new!

Page 5: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

But now we can!

Page 6: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

I present you The Micro Frontends! 🎉

Page 7: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 8: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Ivan JovanovicSenior software engineer @ nearForm

https://ivanjov.com

@ivanjov96

Page 9: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Serbia

Page 10: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

What are Micro Frontends?

Page 11: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Micro Frontends - a microservice approach to the modern web

Page 12: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

What are Microservices?

Page 13: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Microservices is an architectural style that structures an application as a

collection of loosely coupled services

Page 14: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 15: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Event bus

Page 16: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Event bus allows publish-subscribe-style communication between components without

requiring the components to explicitly register with one another

Page 17: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Microservice principles• Lightweight protocol between services

• Small services, one job per service

• Service independence

• Easier to understand, develop and test

• Speeds up development

• Enables continues delivery and deployment

Page 18: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 19: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 20: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 21: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

VS VS

Page 22: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

+ +

Page 23: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 24: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

App

FooterBodyHeader

Page 25: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Root app

App 3App 2App 1

Header Body Footer

Page 26: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

How did we get here?• Monolith full stack apps 😊

• Frontend and backend apps 😄

• Microservices in the backend 😅

• Components on the UI 😎

• Micro frontends 🤯

Page 27: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

We need to fight with the bad architecture!

Page 28: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

What problem does it solve?

• Use new frontend framework on the old architecture

• No more shared codebases and conflicts

• Independent deployments

• Each team can pick their own stack

• You can easily scale your frontend app

Page 29: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

How to split apps?

• By functionality on the page

• By page

• By section

Page 30: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Implementation 🎉

• External app bootstrapping

• IFrames

• Single-spa library

• Frint framework

Page 31: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

External app bootstrapping

Page 32: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

External app bootstrapping

• Code lives on different server

• Independent deployment

• Communication is done through:

• Window object

• Event bus

Page 33: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 34: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 35: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

React app

Page 36: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

React app export

Page 37: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Fetching React app in the Root app

Page 38: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Event bus - Eev

• https://github.com/chrisdavies/eev

• Less than 500 bytes minified + zipped

• Really fast

• Zero dependencies

• Simple

Page 39: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 40: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 41: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 42: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

IFrames

Page 43: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

IFrames

• Code lives on different server

• Independent deployment

• Communication is done through browser “Event bus”

Page 44: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 45: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 46: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 47: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 48: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 49: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Single-spa library

Page 50: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Single-spa library

• https://github.com/CanopyTax/single-spa

• Use multiple frameworks on the same page without refreshing the page

• Write code using a new framework, without rewriting your existing app

• Lazy load code for improved initial load time

Page 51: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 52: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Single-spa library• Code lives on the same server

• Everything is bundled and deployed at the same time

• Communication is done through:

• Window object

• Event bus

• Shared state (Redux etc.)

• Whatever works for you…

Page 53: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 54: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Loading function

Page 55: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Activity function

Page 56: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 57: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Single-spa app

Page 58: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Bootstrap

Page 59: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Mount

Page 60: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Unmount

Page 61: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 62: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 63: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 64: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Frint

Page 65: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Frint

• https://frint.js.org/

• CLI

• Routing

• State management

• Server side rendering supported

Page 66: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?
Page 67: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Frint CLI

Page 68: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Frint CLI

Page 69: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Reactive Programming 🎉

Page 70: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

It works with React Native!!!

Page 71: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Who is using Micro Frontends?

Page 72: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

And many more…

Page 73: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Everyone! 😎

Page 74: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Conclusion• Don’t use this if you have a simple app

• Use micro frontends to make things easier, not complicated

• Micro frontends architecture doesn’t mean to use every framework in the world

• Don’t forget to make standards across micro apps

Page 75: Introduction to Micro Frontendsconferences.oreilly.com/fluent/fl-ca/cdn.oreillystatic... · 2020. 7. 13. · We need to fight with the bad architecture! What problem does it solve?

Thank you! 😊

Blog ivanjov.com

Twitter @ivanjov96