Scale it the easy way
Introduction to
micro frontends
...how to use all frameworks at once
Hi, I'm Kuba Holak
R&D Developer @
Front-end perspective
time
complexity
Monolith
View
Logic
Data
a large single upright block of stone, especially one shaped into or serving as a pillar or monument.
Microservices
single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API.
View
Feature logic + data
Feature logic + data
Feature logic + data
Feature logic + data
Microservice
Microservice
Microservice
API
Frontend SPA
Microservice
Microservice
Microservice
Microservice
Microservice
Feature
Feature
Feature
Feature
Feature
Front end
Backend
Data
Micro Frontends
The idea behind Micro Frontends is to think about a website or web app as a composition of features which are owned by independent teams. Each team has a distinct area of business or mission it cares about and specialises in.
micro-frontends.org
Let's split our UI into separate, self contained and independent feature apps.
User
Search
Job Offers
Brands
Benefits?
Increase productivity - ship features faster
Minimise tech debt
Increase autonomy of development teams
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5376639/1_fIX-pjpEW-CV9JFgiCBy2g-1.jpg)
Avoid tech stack lock-in
Progressive rewrites of big codebases
There is no single tech approach.
Let's see how others do it.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5337237/800px-Zalando_logo.svg.png)
Project Mosaic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5337238/2000px-Spotify_logo_with_text.svg.png)
Stich Framework
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5337260/allegro-logo-3ADC139AD1-seeklogo.com.png)
OpBox
SINGLE SPA
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5360889/introducing-the-element-registry.png)
Web components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in web pages and web apps.
Custom elements
class UserView extends HTMLElement {...}
window.customElements.define('user-view', UserView);
<user-widget />
<search-widget />
<job-offers-app />
<brands-widget />
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5383952/3d_group.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5383952/3d_group.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5383952/3d_group.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5383952/3d_group.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5383954/pasted-from-clipboard.png)
UI Shell
router and basic layout
Invoicing
Support
Backup
Scheduler
- small shell app responsible for providing user context and Amplify methods to each sub app
- every route is a sub app
- every sub app can provide sub routes
- each sub app is a js file exposing a factory of web component
Nordcloud Insight UI Shell
<Router history={history}>
<Home path="/" />
<UserPage path="/mysettings" />
<PageNotFound path="/404" />
<SubApp path="/:subappname" setup={{ ...amplifySetup }} />
</Router>
function initializeSubApp(routeDesc, setup) {
loadScriptFromUrl(routeDesc).then(({ routeDesc, setup }) =>
window.subAppFactory.init(
{ title: routeDesc.title, ...setup },
routeDesc.component
);
//...return store action with sub app creation success
)
}
Sub app setup
returns a factory with init() method, which should register a web-component under provided DOMString tags
function init(setup = {}, tag = "my-component"){
ReactCustomElement(<App setup={setup} />, tag);
}
ReactCustomElement is a custom tailored function that mounts a react app into shadow dom based web component.
Micro frontends - is it whorth it?
It depends.
Scale
Micro Frontends architecure
comes with initial costs.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/862318/images/5360924/productivity.png)
https://martinfowler.com
Final thoughts
- avoid shared state - use a "store" per micro app
- create shared UI elements library
- measure performance
- you may not need a framework :(
Thank you
Copy of Introduction to micro frontends - meetjs summit 2018
By Kuba Holak
Copy of Introduction to micro frontends - meetjs summit 2018
- 862