Rules of Micro-Frontends

参考资料:https://medium.com/swlh/rules-of-micro-frontends-7b96c10dde9

This is an opinionated list of best practices when designing applications that follow the Micro-frontend pattern. Each “rule” should be examined and its benefits/downsides evaluated against your specific use case.

Zero coupling between Micro-frontends

To achieve the benefits of this architecture, accidental coupling should be avoided as much as possible; this will unlock the flexibility and scalability that the Micro-Frontend pattern has to offer as well as future-proofing your applications by allowing incremental upgrades or future complete rewrites of parts of your application.

Each Micro-frontend should be able to render in isolation or inside a container application. The data required should be loaded by each Micro-Frontend and avoid data waterfalls.

Do:

  • ✅ Share libraries that can be swapped without affecting other Micro-frontends.

  • ✅ Load all the data it needs to render.

Do Not:

  • ❌ Have a centralised store/share data across different Micro-Frontends.

  • ❌ Share libraries that are in active development.

Separate Code Bases

Each Micro-Frontend should have its own codebase and the version control of choice shouldn’t have any impact on the way the project is developed or deployed. Having all projects under a single monorepo or individual repositories is fine.

Do:

  • ✅ Use Monorepos.

  • ✅ Use individual repos.

Each Micro-frontend should be deployed independently

Each Micro-Frontend should have it’s own CI/CD pipeline and be able to deploy to production on demand without any dependencies on other Micro-frontends. A common antipattern that should be avoided is “The deployment queue of hell” where different Micro-frontends are so tightly coupled that they need to be deployed in a specific order to avoid breaking the application.

Do:

  • ✅ Have separate CI/CD pipelines.

  • ✅ Release on demand.

Do Not:

  • ❌ Have Release schedules.

  • ❌ Have incremental/sequential deployments that require previous versions.

Micro-Frontends should be tested Independently

Because Micro-Frontends are required to render independently as well as inside a container application, it makes sense to also test them independently using unit and integration tests for both scenarios.

Do:

  • ✅ Have unit and integration tests for each Micro-Frontend rendering in isolation.

  • ✅ Run integration tests for Micro-Frontends rendering inside the container applications as part of end-to-end testing.

Micro-Frontends should be versioned

When a new Micro-Fronted is deployed to production, the previous version should not be deleted and the new version should be tagged with a version number using semantic versioning or similar. It is up to the container applications to decide what specific version of a particular Micro-Frontend to use (Managed) or always use the latest version instead (Evergreen).

Do:

  • ✅ Use Semantic versioning.

  • ✅ Use a specific version or “latest”.

Do Not:

  • ❌ Require a global deployment to change versions.

  • ❌ Delete previous versions.

Minimal Communication

Communication between Micro-Frontends should be minimal and simple, avoiding global state and framework-specific solutions as much as possible.

If two or more Micro-Frontends are sharing a lot of messages to provide their minimal functionality, they might be too tightly coupled and they could share a similar enough purpose that they should be considered to be integrated into one.

Do:

  • ✅ Keep messages small and simple.

  • ✅ Avoid state and communication frameworks if possible.

Do Not:

  • ❌ Share state.

  • ❌ Have unnecessary communication.

CSS should be scoped

CSS from loaded from one Micro-fronted should not affect others.

Do:

  • ✅ Scope your CSS.

  • ✅ Use a CSS-in-JS or namespacing library (like CSS Modules).

Do Not:

  • ❌ Use global CSS.

Final Recommendations

  • ✅ Try to create autonomous teams.

  • ✅ Try to arrange your Micro-Frontends around business functionality.

  • ✅ Reusability is a nice “side effect” not the target.

  • ❌ Don’t Force this architectural style just because it is “new”.

  • ❌ You don’t need multiple javascript frameworks.

  • ❌ You don’t need a “micro-frontend framework”.

  • ❌ Micro-Frontends don’t have to be “micro”.

(0)

相关推荐

  • 使用 Visual Studio Code SQLite 扩展来浏览 SAP Cloud Application Programming 数据库

    在 SAP Cloud Application Programming 编程模型里,我们可以使用下面的命令行,使用持久化数据库( persistent database ) 来存储 entity 的数 ...

  • 微前端(Micro Frontend ) 落地实施的一些具体例子

    前文微前端概述(Micro Frontends) 以及相比单体应用,微前端能带来什么好处 简单介绍了微前端的概念,本文来看一个具体的应用例子. 原文地址 想象一个网站,客户可以在其中订购外卖食品.从表 ...

  • 如何配置webpack让浏览器自动补全前缀

    一.postcss-loader有什么用? PostCSS 本身是一个功能比较单一的工具.它提供了一种方式用 JavaScript 代码来处理 CSS.它负责把 CSS 代码解析成抽象语法树结构(Ab ...

  • 微前端概述(Micro Frontends) 以及相比单体应用,微前端能带来什么好处

    原文地址 好的前端开发很难. 扩展前端开发,让多个团队可以同时开发一个大型复杂的产品就更难了.在本文中,我们将描述将前端单体分解成许多更小.更易于管理的部分的最新趋势,以及这种架构如何提高处理前端代码 ...

  • Micro LED:显示王朝的明日之星!

    专业做知识,认真做自己! 3月31日,财政部.海关总署和税务总局等发布了2021-2030年支持新型显示产业发展进口税收政策的通知,目的在于加快壮大新一代信息技术,支持新型显示产业的发展. 自2021 ...

  • Micro Usb将逐渐退出主流应用市场

    感觉就在一瞬间,曾经的王者掉落人间,虽然不适应,但这就是江湖,Micro Usb将逐渐退出主流应用市场,瞅瞅你身边好友的移动设备的数据接口,主要分为两个阵营,一个安卓的TYPE C一个苹果的,现在开始 ...

  • Micro CT中的骨分析参数解读

    一.背景简述 MicroCT是一种结合了影像学检查无创性和组织学检测高分辨率特点的技术,由于骨骼与其它身体组织在X射线衰减性能方面有相对明显差别,因此Micro CT特别适合骨骼成像,骨骼参数的研究也 ...

  • 宏德旺:一流钢网技术 助推Mini/Micro LED产品高速发展

    近年来,Mini/Micro LED市场被十分看好,随着三星.索尼.TCL等头部企业的布局,加速了行业发展速度,预计三五年之后将迎来万亿级的市场!作为过渡技术, Mini LED去年迎来了量产元年,预 ...

  • Micro LED等芯片企业显芯科技完成A轮融资

    日前,国内领先的显示芯片设计公司北京显芯科技有限公司(下称:显芯科技)完成A轮融资,本轮融资由知名硬科技产业投资机构海林投资参投.凭借在显示驱动方案及芯片设计上的独到优势,显芯科技有望在资本推力下加速 ...

  • 2021年中国Mini/Micro LED行业产业链全景图上中下游市场及企业剖析

    2021年3月25日上午,工信部财务司财经处处长何年初在中国电子视像行业协会Mini/Micro LED显示产业分会第一次成员大会上表示,财务司一直积极推进新型显示产业发展,促进相关新技术.新业态.新 ...

  • Micro SD卡

    存储卡封面的秘密! 1.44万播放 01:47 Micro SD卡 体积极小的闪存卡 Micro SD卡(原名:Trans-flash Card(TF卡))是由SanDisk公司发明的一种极细小的闪存 ...

  • Micro%20SD%20Card是什么

    TF Card 是 TrashFlash 卡的缩写,现称为 Micro SD Card,由 SanDisk 公司于 2004 年推出,尺寸接近指甲的微安全数字卡被认为是世界上最小的存储卡.可在 iPo ...

  • 拉伸幅度可达130%!柔宇科技发布业内首个Micro

    柔宇科技新型超薄彩色柔性显示技术壁垒高,市场前景巨大,被国际学术界和工业界认为是21世纪最具颠覆性和代表性的电子信息革命者之一.回看其发展历程,柔宇科技每年都有新产品新技术发布. 近日,柔宇科技在&q ...