"Micro frontends: Unbelievably true life story", Dmytro Pavlov

fwdays 132 views 31 slides May 27, 2024
Slide 1
Slide 1 of 31
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31

About This Presentation

A real life story about the experience of using Micro frontends in an existing Enterprise product. Problems and their solutions on the way from the integration of a separate component to an extensible No-code platform.


Slide Content

2019 2020 2023 2024
AGENDA
... ...
Context
Micro frontends motivation
Issues & solutions
Carry outs
1.
2.
3.
4.

2019 2020 2023 2024
CONTEXT
... ...
Team: 100+ members
Application
Extensible / Customizable 
No-​Code Platform
Monolith
Tech stack
SPA
Custom JS Framework
AMD Architecture
MVVM Pattern

2019 2020 2023 2024
ISSUES
... ...
Maintenance
Optimizations
New features
Bugs

2019 2020 2023 2024
ISSUES
... ...
Specific knowledge required
Internal community limitation
Documentation
Hiring issues

2019 2020 2023 2024
CHANGE TECH STACK ISSUES
... ...
New tech stack issues
Existing functionality and plans
Ability to integrate new techs in monolith app
Lack of expertise & experience
Educate big team

2019 2020 2023 2024
MICRO FRONTENDS: General Info
... ...
Benefits
Incremental upgrades
Decoupled codebases
Independent deployment

2019 2020 2023 2024
MICRO FRONTENDS: First steps
... ...
Preliminary work
Identifу a suitable task
Make a PoC
Be ready to face issues

2019 2020 2023 2024
MICRO FRONTENDS: First steps
... ...
Created Component with Angular
Angular
Cmp

2019 2020 2023 2024
MICRO FRONTENDS: First steps
... ...
Packed as Web-​component
Web Cmp
Angular
Cmp

2019 2020 2023 2024
MICRO FRONTENDS: First steps
... ...
Packed as Web-​component
import {Component, Injector}  from '@angular/core';
import {createCustomElement}  from '@angular/elements';
//...
@Component({
 //...
})
export class AppComponent {
constructor(
injector: Injector,
 public forecast: ForecastComponent,
) {
 // Convert `ForecastComponent` to a custom element.
 const ForecastComponent = createCustomElement(ForecastComponent, 
{injector});
 // Register the custom element with the browser.
customElements.define( 'forecast', ForecastComponent);
}
}

2019 2020 2023 2024
MICRO FRONTENDS: First steps
... ...
Used proxy for integration into existing App
Proxy Cmp
Web Cmp
Angular
Cmp

2019 2020 2023 2024
MICRO FRONTENDS: First steps
... ...
Results
Unlocked new tech injection flow
Gained new expertise & experience
Faced new issues
Proxy Cmp
Web Cmp
Angular
Cmp
Proxy Cmp
Web Cmp
Angular
Cmp
Proxy Cmp
Web Cmp
Angular
Cmp

2019 2020 2023 2024
MICRO FRONTENDS: ISSUES
... ...
Issues
Each component loads own deps
Increases traffic
Downgrades performance
Proxy Cmp
Web Cmp
Angular
Cmp
Angular, RxJS
<code>
Component
<code>

2019 2020 2023 2024
MICRO FRONTENDS: Externals
... ...
The externals configuration option 
provides a way of excluding
dependencies from the output bundles.
Instead, the created bundle relies on
that dependency to be present in
application environment.
Angular, RxJS
<code>
Component
<code>
Component
<code>
Component
<code>

2019 2020 2023 2024
MICRO FRONTENDS: Externals
... ...
Build external deps
"ng-​core": {
 "builder": "ngx-​ build-​ plus:browser",
 "options": {
 "outputPath": "dist/libs/studio-​ enterprise/util/ng-​ core",
 //...
 "scripts": [
 //...
 "node_modules/rxjs/dist/bundles/rxjs.umd.js" ,
 "dist/@angular/core/bundles/core.umd.js" ,
 "dist/@angular/common/bundles/common.umd.js" ,
 "dist/@angular/common/bundles/common-​ http.umd.js",
 "dist/@angular/compiler/bundles/compiler.umd.js" ,
 "dist/@angular/elements/bundles/elements.umd.js" ,
 "dist/@angular/platform-​ browser/bundles/platform-​ browser.umd.js",
 "dist/@angular/platform-​ browser-​ dynamic/bundles/platform-​ browser-​ dynamic.umd.js"
],
},
 //...
},
Angular, RxJS
<code>

2019 2020 2023 2024
MICRO FRONTENDS: Externals
... ...
External deps files
Angular, RxJS
<code>
Component
<code>
Component
<code>
Component
<code>

2019 2020 2023 2024
MICRO FRONTENDS: Externals
... ...
Build component
"forecast": {
 "builder": "ngx-​ build-​ plus:browser",
 "options": {
 "outputPath": "dist/libs/studio-​ enterprise/forecast/" ,
 //...
 "extraWebpackConfig": "libs/studio-​ enterprise/util/ng-​ core/webpack.externals.js"
},
 //...
},
Component
<code>
"externals": {
 "rxjs": "rxjs",
 "@angular/core": true,
 "@angular/common": true,
 "@angular/common/http" : true,
 "@angular/platform-​ browser": true,
 "@angular/platform-​ browser-​ dynamic": true,
 "@angular/compiler": true,
 "@angular/elements": true,
}
1
2

2019 2020 2023 2024
MICRO FRONTENDS: Externals
... ...
Component files

2019 2020 2023 2024
MICRO FRONTENDS: Externals
... ...
Optimization results
Angular, RxJS
<code>
Component
<code>
Component
<code>
Component
<code>
~1MB

2019 2020 2023 2024
MICRO FRONTENDS: Evolution
... ...
Since that time
Gained experience & expertise
Switched to new tech stack
for new features

2019 2020 2023 2024
MICRO FRONTENDS: Evolution
... ...
New issues
Increased Components
code size
Internal libs were not shared
between components
Angular
RxJS
<code>
Component
Dep4 Dep5
Dep1 Dep2 Dep3
Component
Dep4
Dep1 Dep2
Component
Dep5
Dep1 Dep3

2019 2020 2023 2024
MICRO FRONTENDS: MF
... ...
Module Federation is a feature introduced
in Webpack 5 that enables dynamic and 
decentralized sharing of JavaScript
modules between different
Webpack-​ bundles at runtime.
Component
<code>
Dep4 Dep5
Dep1 Dep2 Dep3
Component
<code>
Dep4
Dep1 Dep2
Component
<code>
Dep5
Dep1 Dep3Dep2

2019 2020 2023 2024
MICRO FRONTENDS: MF
... ...
Build config
withModuleFederationPlugin({
name: 'forecast_component',
filename: 'forecast-​ component.js',
exposes: {
 './Main': path.join(__dirname, './src/main.ts'),
},
shared: [
 '@creatio/sdk/util/common-​ types',
 '@creatio/sdk/util/utils' ,
 '@creatio/studio-​ enterprise/ui/components' ,
 '@creatio/studio-​ enterprise/feature/components-​ preprocessors',
 '@creatio/studio-​ enterprise/ui/cdk',
 '@creatio/studio-​ enterprise/ui/schema' ,
 '@creatio/studio-​ enterprise/ui/data-​ grid-​ cdk',
 '@creatio/studio-​ enterprise/ui/view',
 '@creatio/studio-​ enterprise/feature/schema-​ view',
 '@creatio/studio-​ enterprise/util/model' ,
 '@creatio/studio-​ enterprise/util/low-​ code',
],
});
Component
<code>
DepNDep1 ...

2019 2020 2023 2024
MICRO FRONTENDS: MF
... ...
Build result
Remote entry
Dependency
Component
<code>
DepNDep1 ...

2019 2020 2023 2024
MICRO FRONTENDS: MF
... ...
Loading schema
1
2

2019 2020 2023 2024
MICRO FRONTENDS: MF
... ...
Optimization results
Component Before, Mb After, Mb %
Forecast 9.2 2.7 71%
Analytics Dashboard 5.6 0.05 99%
Campaign Gallery 3.11 0.05 99%
Omnichannel Messaging 2.15 0.34 84%
... ... ... ...

2019 2020 2023 2024
MICRO FRONTENDS: Further plans
... ...
Plans for the future
Split libs into a smaller chunks for more advanced
lazy loading
Optimize build process

2019 2020 2023 2024
MICRO FRONTENDS: Carry outs
... ...
Micro frontends
Enabled possibility and added flexibility in using new
technologies
Led to new issues

Join Creatio