Lesson 01-Micro Frontend Basic Concepts

Comparison of Monolithic Applications and Microservices Architecture

Monolithic Application

  • Architecture Characteristics: All functional modules are packaged into a single application.
  • Advantages:
    • Simple development and easy deployment.
    • Suitable for small projects or startups.
    • Easy to ensure transaction consistency.
  • Disadvantages:
    • As features grow, the codebase becomes large and hard to maintain.
    • Inflexible deployment; a small change requires redeploying the entire application.
    • Limited technology stack, making it difficult to adopt new technologies.
    • Challenging for team collaboration, as different modules may be handled by different teams.

Microservices Architecture

  • Architecture Characteristics: The application is split into a set of small, independent services.
  • Advantages:
    • Independent development, deployment, and scaling.
    • Flexible technology stack; different services can use different technologies.
    • Fault isolation; a failure in one service does not affect others.
    • Suitable for large, complex systems.
  • Disadvantages:
    • Increased complexity of distributed systems.
    • High cost of inter-service communication and coordination.
    • Requires a more robust monitoring and operations system.

Comparison Summary

CharacteristicMonolithic ApplicationMicroservices Architecture
Architectural ComplexityLowHigh
Development EfficiencyHigh (initially)Medium (requires supporting tools)
Deployment FlexibilityLowHigh
Technology StackSingleDiverse
Team CollaborationDifficultFlexible
PerformanceHigh (memory sharing)Potentially lower (network communication)
ScalabilityLimitedHigh

Definition and Core Concepts of Micro Frontends

Definition

Micro Frontends is an architectural style that decomposes a frontend application into multiple small, independent frontend applications. Each sub-application can be developed, deployed, and run independently, and they are combined at runtime to form a complete application.

Core Concepts

  1. Independent Development: Each team is responsible for its own sub-application, using its preferred technology stack.
  2. Independent Deployment: Sub-applications can be deployed independently without affecting others.
  3. Technology Agnostic: Different sub-applications can use different frameworks and technology stacks.
  4. Runtime Integration: Sub-applications are dynamically loaded and combined in the browser.
  5. Incremental Upgrades: Allows gradual migration of existing monolithic frontend applications to a micro frontend architecture.

Application Scenarios for Micro Frontends

  1. Large Enterprise Applications: Complex functionality requiring collaboration across multiple teams.
  2. Legacy System Modernization: Gradual replacement of old systems without disrupting existing functionality.
  3. Multi-Brand/Multi-Tenant Applications: Different brands or tenants require customized interfaces.
  4. Cross-Department Collaboration: Different departments manage different functional modules.
  5. Progressive Migration: Transitioning from a monolithic frontend to micro frontends incrementally.
  6. Function Isolation: Strict isolation of different functional modules (e.g., payment systems).

Main Advantages and Challenges of Micro Frontends

Main Advantages

  1. Independent Technology Stack: Different teams can use different technology stacks.
  2. Parallel Development: Multiple teams can work on different sub-applications simultaneously.
  3. Independent Deployment: Sub-applications can be deployed independently without affecting the overall system.
  4. Progressive Migration: Allows gradual decomposition of monolithic applications into micro frontends.
  5. Fault Isolation: A failure in one sub-application does not affect others.
  6. Team Autonomy: Each team can independently decide on technology choices and development pace.

Main Challenges

  1. Communication Mechanism: How sub-applications communicate with each other.
  2. Style Isolation: Avoiding style conflicts between sub-applications.
  3. State Management: How to share and manage global state.
  4. Performance Optimization: Overhead of loading multiple sub-applications.
  5. Routing Management: Coordinating routing across sub-applications.
  6. Build System: Need for a build process that supports micro frontends.
  7. Monitoring and Debugging: Monitoring and debugging distributed frontend applications.

Relationship Between Micro Frontends and Module Federation

Module Federation

  • A feature introduced in Webpack 5.
  • Allows dynamic loading of modules built by other applications at runtime.
  • Provides a standardized way to implement micro frontends.

Relationship

  • Module Federation is one technical solution for implementing micro frontends.
  • Micro Frontends is an architectural concept, while Module Federation is an implementation tool.
  • Module Federation addresses code sharing and dynamic loading in micro frontends.
  • Micro frontend architecture can be implemented without Module Federation (e.g., using iframes).

Differences

CharacteristicMicro FrontendsModule Federation
ScopeArchitectural StyleWebpack Feature
DependencyNot limited to WebpackBased on Webpack
FunctionOverall architectural guidanceCode sharing mechanism
DependenciesCan integrate with various technologiesRequires Webpack 5+

Comparison of Mainstream Micro Frontend Frameworks and Tools

1. Single-SPA

  • Characteristics: One of the earliest micro frontend frameworks, defining the concept of micro frontends.
  • Advantages:
    • Pure JavaScript implementation, independent of specific build tools.
    • Supports multiple frameworks (React, Angular, Vue, etc.).
    • Strong community support.
  • Disadvantages:
    • Requires manual handling of style isolation and communication issues.
    • Relatively complex configuration.
  • Applicable Scenarios: Highly customized micro frontend projects.

2. Module Federation

  • Characteristics: Webpack 5’s built-in micro frontend solution.
  • Advantages:
    • Official support, seamless integration with the Webpack ecosystem.
    • Automatic handling of code splitting and dynamic loading.
    • Supports runtime dependency sharing.
  • Disadvantages:
    • Limited to Webpack projects.
    • Limited support for non-Webpack projects.
  • Applicable Scenarios: Modern frontend projects based on Webpack.

3. Qiankun

  • Characteristics: An open-source micro frontend framework by Alibaba.
  • Advantages:
    • Based on Single-SPA with enhanced features.
    • Provides built-in style isolation and JavaScript sandboxing.
    • Rich documentation and active Chinese community.
  • Disadvantages:
    • Primarily focused on React/Vue applications.
    • Limited support for non-standard projects.
  • Applicable Scenarios: Medium to large-scale React/Vue projects.

4. Wujie

  • Characteristics: A next-generation micro frontend framework.
  • Advantages:
    • Supports all frameworks and pure HTML applications.
    • Provides robust sandboxing and style isolation.
    • Good performance optimization.
  • Disadvantages:
    • Smaller community.
    • Less comprehensive documentation compared to Qiankun.
  • Applicable Scenarios: Projects requiring support for multiple technology stacks.

5. Luigi

  • Characteristics: An open-source micro frontend framework by SAP.
  • Advantages:
    • Focused on enterprise applications.
    • Offers rich UI components and tools.
    • Strong permission management.
  • Disadvantages:
    • Steep learning curve.
    • Primarily tailored for the SAP ecosystem.
  • Applicable Scenarios: SAP-related enterprise applications.

6. Piral

  • Characteristics: A React-based micro frontend framework.
  • Advantages:
    • Focused on modular application development.
    • Introduces an application store concept.
    • Robust plugin system.
  • Disadvantages:
    • Primarily focused on React projects.
    • Limited support for non-React projects.
  • Applicable Scenarios: React modular applications.

Micro Frontend Architecture Patterns

1. Base Application Pattern (Base App + Sub-Apps)

  • Architecture Characteristics:
    • A main application (base app) handles the overall layout and routing.
    • Multiple sub-applications handle specific functionalities.
    • Sub-applications are dynamically loaded into the base app.
  • Advantages:
    • Simple implementation.
    • Centralized control.
  • Disadvantages:
    • The base app becomes a single point of failure.
    • Sub-applications depend on the base app’s environment.
  • Applicable Scenarios: Most micro frontend projects.

2. Module Federation Pattern

  • Architecture Characteristics:
    • Uses Webpack Module Federation.
    • Dynamically shares code between applications.
    • Loads modules on demand at runtime.
  • Advantages:
    • Official support.
    • Automatic dependency handling.
  • Disadvantages:
    • Limited to Webpack projects.
    • Complex configuration.
  • Applicable Scenarios: Modern frontend projects based on Webpack.

3. Self-Organizing Pattern

  • Architecture Characteristics:
    • No central base app.
    • Applications are equal and can discover each other.
    • Based on a service registry.
  • Advantages:
    • Decentralized.
    • Highly autonomous.
  • Disadvantages:
    • Complex implementation.
    • Requires additional infrastructure.
  • Applicable Scenarios: Large-scale distributed systems.

Pattern Comparison

CharacteristicBase App PatternModule Federation PatternSelf-Organizing Pattern
CentralizationYesNoNo
Technology StackFlexibleWebpack-dependentFlexible
Implementation ComplexityMediumHighHigh
Applicable ScaleSmall to mediumMedium to largeLarge distributed
Community SupportBroadEmergingLimited
Typical FrameworksQiankun, WujieWebpack 5Custom

Summary

Micro frontend architecture addresses the challenges of developing, deploying, and maintaining large-scale frontend applications by decomposing them into multiple independent parts. Different micro frontend frameworks and patterns have their own advantages and disadvantages, and the choice depends on factors such as project scale, technology stack, and team capabilities.

  • Small Projects: Consider simple iframe solutions.
  • Medium Projects: Qiankun or Wujie are good choices.
  • Large Enterprise Applications: May require self-organizing patterns or integration with Module Federation.
  • Webpack Projects: Module Federation provides an out-of-the-box solution.

The future trend of micro frontends is toward standardization and improved toolchains, with potential for more official support and a growing community ecosystem.

Share your love