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”.

posted on   荣锋亮  阅读(84)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-01-02 honest-profiler+hprof2flamegraph 基础的扩展
2020-01-02 honest-profiler+hprof2flamegraph 查看java 应用火焰图信息
2019-01-02 vorpal 又一个方便的cli 开发包
2019-01-02 gogs wekan 集成试用
2019-01-02 Creating Node.js Command Line Utilities to Improve Your Workflow
2018-01-02 rollupjs 基本试用
2018-01-02 hapi lab测试框架简单使用

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示