Platform freedom with Micro-frontends
HolyJS Conference 2023
Saravana Balaji Srinivasan
Senior Software Engineer @Red Hat
Full-stack Developer
Intro
HolyJS Conference 2023
Red Hat Story
HolyJS Conference 2023
Landscape
We live in a world where web technologies have dominated software development.
�Default choice for most applications.
Software�Development Landscape
HolyJS Conference 2023
Foundation
Well though and understood set of Standards, Patterns and Techniques as a strong foundation.
Standards,
Patterns and Techniques
HolyJS Conference 2023
Ecosystem
Rich ecosystem that has been maturing over the years
Ecosystem
HolyJS Conference 2023
Static Typed Language
TypeScript created the perfect compromise for Static Type Languages believers.
Static
Typing
HolyJS Conference 2023
Browser Everywhere
Browser is now more than just the window for the internet.
Browsers became part of an important trend as the mechanism to distribute any Graphical User Interface based applications.
Browser
Everywhere
HolyJS Conference 2023
Multiple Distributions
HolyJS Conference 2023
Architectures
Evolutionary
An evolutionary architecture supports incremental, guided change as a first principle across multiple dimensions.
Micro Frontends
Design approach in which a front-end app is decomposed into individual,
semi-independent “microapps” working loosely together.
Serverless
Incorporate third-party “Backend as a Service”, and/or that include custom code
run as Functions.
Microservices
Architectural style that structures an application as a collection of independent services.
Architectures
HolyJS Conference 2023
Micro-frontends
HolyJS Conference 2023
Micro-frontends
HolyJS Conference 2023
"An architectural style where independently deliverable frontend applications are composed into a greater whole"
Cam Jackson
https://martinfowler.com/articles/micro-frontends.html
HolyJS Conference 2023
Goal
GOAL OF MICRO-FRONTENDS ?
HolyJS Conference 2023
Micro-frontends
HolyJS Conference 2023
Diversification
It is not only good for money but also for technology
Micro-frontends
HolyJS Conference 2023
Example
* DMN is a modeling language and notation for the precise specification of business decisions and business rules.
HolyJS Conference 2023
Micro-frontends
UI
Libraries
Frontend
Backend
UI
UI
UI
Library
Library
Application
Application
Application
Application
Application
Library
Library
Build time composition
Application
Application
Application
Application
Application
Application
Run time composition
Monolith
Modular monolith
Integrated applications
Micro-Frontends
HolyJS Conference 2023
Micro-frontends
Monolith Web Application
Datastore
Backend
Frontend
Web Application based on Microservices Architecture
API
Frontend
Microservice A
Microservice A
Microservice C
Datastore
Datastore
Datastore
Web Application based on Microservices and Micro-front end Architecture
API
Microservice A
Microservice B
Microservice C
Datastore
Datastore
Datastore
Micro-front end A
Micro-front end B
Micro-front end C
HolyJS Conference 2023
Micro-frontends
Container/
App Shell
Micro frontend A
Micro frontend C
Micro frontend B
Decides when/where to show each Micro frontend
BFF A
BFF B
BFF C
No Micro frontend communicate
directly to each other
Backend Microservice
BFF ensures seamless user interaction regardless of the platform the frontend application is running on
HolyJS Conference 2023
Micro-frontends
aka client-side integration:
After the container gets loaded in the browser, it gets access to micro front end source code
✅ A can be deployed independently at any time and can deploy different versions of it, and Container can decide which one to use
❌ tooling + setup is far more complicated
Independent deployment makes it challenging to test/verify (build a good test suite for it)
Run-Time integration
Types of Integration
Team A decides to develop a new version of Component C
Ready! Let's deploy it
Publishes C as https://mydomain.com/c.js
User navigates to�https://mydomain.com
Container app is loaded
Container apps fetches new C from
https://mydomain.com/c.js
HolyJS Conference 2023
Micro-frontends
22
aka compile-time integration:
Before the container gets loaded in the browser, it gets access to micro frontend source code;
Foreign modules are accessible during build
✅ Easy to setup and understand
❌ Container has to be re-deployed every time child has updated and tempting to tightly coupled Container + child together
Build-time integration
Types of Integration
Team A decides to develop a new version of Component C
Ready! Let's deploy it
Publishes C as NPM package
NPM Registry �[C]
Team B decides to upgrade C so install a new dependency
Team B builds a new Container with new C
Team B deploys a new Container with new C
HolyJS Conference 2023
Micro-frontends�Concerns
23
Another concerns - Styling
What you should do:
HolyJS Conference 2023
Micro-frontends�Concerns
24
HolyJS Conference 2023
Micro-frontends�Concerns
25
✅ Great degree of isolation;
Styling
Global variables
Shadow DOM was not a option in 2019
✅ Some libraries play directly with body of the page
✅ We only use it when necessary
Context Isolation via iframes
❌ Makes your app feel 'old'
❌ Less flexible than other options
❌ Hard to integrate routing, history;
❌ Challenging to make the app responsive
❌ Not Content-Security-Policy friendly
❌ Harder to make apps communicate
HolyJS Conference 2023
Why do we need a new
architecture?
HolyJS Conference 2023
Cloud Native Tooling
Minimize code changes
The components to be distributed should be preserved untouched and with avoiding feature flags.
Bridge
It has to embrace different generations of technology stack.
Multiple Distributions
The origin of multiplying architecture is rooted in the need to distribute the same set of components in a myriad of platforms.
requirements
Tooling
HolyJS Conference 2023
Introducing�Multiplying Architecture
HolyJS Conference 2023
What is
Software Architecture?
HolyJS Conference 2023
“Architecture is about the important stuff.
Whatever that is.”
Ralph Johnson
HolyJS Conference 2023
The Multiplying Architecture
What is important for the Multiplying Architecture is the abstraction.
HolyJS Conference 2023
The Multiplying Architecture
The Abstractions
Channel
Top level abstraction that represents the hosting environment, like a website or a desktop application.
Editor
Editor is a specialized type of View, that gets a file content as input and is able to serve the content state back to the Channel through the Envelope.
View
View is a portable set of widgets that are exposed as an unit to the Channel through the Envelope.
Envelope
Enable transparent communication between Components (View/Editor) and Channel
core
HolyJS Conference 2023
Online Channel
HolyJS Conference 2023
Desktop Channel
HolyJS Conference 2023
Github extension Channel
HolyJS Conference 2023
VSCode extension Channel
HolyJS Conference 2023
Components Interaction
<div>
Channel (VS Code, Desktop, Browser, …)
MyChannel
Implements: Channel, MyServiceApi
Consumes:
MyEnvelopeApi
MyEditor
Implements:
Editor
Consumes:
MyServiceApi
MyEnvelope
Defines: MyEnvelopeApi MyServiceApi
Implements:
MyEnvelopeApi
Consumes:
Editor
HolyJS Conference 2023
Components
Interaction
Envelope Advantages
Context Isolation (CSS and JS)�
Autonomous Teams Independent Release Cycles Type Safe Communication
Micro-frontend
HolyJS Conference 2023
Multiplying Architecture in
Practice
HolyJS Conference 2023
Build-time issues
Runtime-time issues with iframes
Built time x Runtime Integration
Integration Issues
HolyJS Conference 2023
Integration Issues
Container
Micro frontend A
Micro frontend C
Micro frontend B
Container fetches micro-frontends
React 17.0.1
React 17.0.1
React 17.0.1
http://domain/a.js
http://domain/c.js
HolyJS Conference 2023
Federated Modules �to the Rescue!
HolyJS Conference 2023
Federated Modules
HolyJS Conference 2023
Federated Modules
-> Remote Routes
-> ModuleFederation Plugin�On webpack config
-> shared dependencies
HolyJS Conference 2023
Federated Modules
-> Import of Federated Modules
-> Lazy loading via Route � + � Suspense
HolyJS Conference 2023
Goals of Multiplying Architecture
Minimize code changes
The components to be distributed should be preserved untouched and with avoiding feature flags.
Bridge
It has to embrace different generations of technology stack.
Multiple Distributions
The origin of multiplying architecture is rooted in the need to distribute the same set of components in a myriad of platforms.
Solve a problem
Goals
HolyJS Conference 2023
We Achieved Platform with Multiplying Architecture
Achievements
HolyJS Conference 2023
Code sample - https://github.com/kiegroup/kie-tools/tree/main/examples
HolyJS Conference 2023
Questions
HolyJS Conference 2023
Thank you
Saravana Balaji Srinivasan
HolyJS Conference 2023