15

Module 15: Deploy Angular Micro Frontends Independently

Chapter 15 • Advanced

25 min

Deploy Angular Micro Frontends Independently

Each micro frontend:

  • Has its own CI/CD pipeline
  • Can be deployed without affecting others
  • Reduces production risk

Deployment Architecture

Production URLs

code
Host:      https://app.example.com
Products:  https://products.example.com
Checkout:  https://checkout.example.com

Module Federation URLs

typescript.js
// Production config
remotes: {
  products: 'products@https://products.example.com/remoteEntry.js',
  checkout: 'checkout@https://checkout.example.com/remoteEntry.js'
}

Build Configuration

Production Build

bash.js
# Build Host
cd host-app
npx ng build --configuration production

# Build Products
cd products-app
npx ng build --configuration production

# Build Checkout
cd checkout-app
npx ng build --configuration production

Output Structure

code
dist/
├── host-app/
│   ├── index.html
│   ├── main.js
│   └── ...
├── products-app/
│   ├── remoteEntry.js    # Exposed module
│   ├── main.js
│   └── ...
└── checkout-app/
    ├── remoteEntry.js    # Exposed module
    ├── main.js
    └── ...

CI/CD Pipeline

Host Pipeline

yaml.js
# .github/workflows/host-deploy.yml
name: Deploy Host
on:
  push:
    branches: [main]
    paths:
      - 'host-app/**'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '23'
      - run: npm install
      - run: cd host-app && npm run build
      - run: deploy-to-production

Products Pipeline

yaml.js
# .github/workflows/products-deploy.yml
name: Deploy Products
on:
  push:
    branches: [main]
    paths:
      - 'products-app/**'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '23'
      - run: npm install
      - run: cd products-app && npm run build
      - run: deploy-to-production

Independent Deployment

Deploy Products Only

bash.js
# Only Products app changes
git commit -m "Update products feature"
git push

# Only Products pipeline runs
# Host and Checkout unaffected

Benefits

  • ✅ Faster deployments
  • ✅ Lower risk
  • ✅ Independent release cycles
  • ✅ Team autonomy

Version Management

Versioned Deployments

typescript.js
// Use versioned URLs
remotes: {
  products: 'products@https://products.example.com/v1.2.3/remoteEntry.js'
}

Benefits

  • ✅ Rollback capability
  • ✅ A/B testing
  • ✅ Gradual rollout
  • ✅ Cache control

Environment Configuration

Environment Files

typescript.js
// environment.prod.ts
export const environment = {
  production: true,
  productsUrl: 'https://products.example.com',
  checkoutUrl: 'https://checkout.example.com'
}

Dynamic Configuration

typescript.js
// webpack.config.js
const isProduction = process.env.NODE_ENV === 'production'

const remotes = isProduction
  ? {
      products: 'products@https://products.example.com/remoteEntry.js',
      checkout: 'checkout@https://checkout.example.com/remoteEntry.js'
    }
  : {
      products: 'products@http://localhost:4201/remoteEntry.js',
      checkout: 'checkout@http://localhost:4202/remoteEntry.js'
    }

CDN Deployment

Use CDN for Remotes

typescript.js
remotes: {
  products: 'products@https://cdn.example.com/products/v1.2.3/remoteEntry.js',
  checkout: 'checkout@https://cdn.example.com/checkout/v1.2.3/remoteEntry.js'
}

Benefits

  • ✅ Faster loading
  • ✅ Better caching
  • ✅ Global distribution
  • ✅ Reduced server load

Rollback Strategy

Quick Rollback

bash.js
# Rollback Products to previous version
# Update Host config to point to old version
remotes: {
  products: 'products@https://products.example.com/v1.2.2/remoteEntry.js'
}

# Redeploy Host (no Products rebuild needed)

Blue-Green Deployment

Strategy

  1. Deploy new version alongside old
  2. Test new version
  3. Switch traffic to new version
  4. Keep old version for rollback

Implementation

typescript.js
// Host can switch between versions
remotes: {
  products: process.env.PRODUCTS_VERSION === 'new'
    ? 'products@https://products.example.com/v2.0.0/remoteEntry.js'
    : 'products@https://products.example.com/v1.2.3/remoteEntry.js'
}

Monitoring

Health Checks

typescript.js
// Check if remote is available
async function checkRemoteHealth(url: string): Promise<boolean> {
  try {
    const response = await fetch(url)
    return response.ok
  } catch {
    return false
  }
}

Error Tracking

typescript.js
// Track remote loading errors
loadChildren: () => import('products/ProductsModule')
  .then(m => m.ProductsModule)
  .catch(err => {
    // Log error
    errorTracking.log(err)
    // Fallback
    return import('./fallback/fallback.module')
      .then(m => m.FallbackModule)
  })

Best Practices

✅ Do

  • Deploy independently
  • Use versioned URLs
  • Monitor deployments
  • Have rollback plan
  • Use CDN for remotes
  • Test in staging first

❌ Don't

  • Don't deploy all apps together
  • Don't skip testing
  • Don't ignore errors
  • Don't forget rollback plan
  • Don't hardcode URLs

Deployment Checklist

  • [ ] Build configuration set
  • [ ] CI/CD pipelines configured
  • [ ] Environment variables set
  • [ ] URLs configured correctly
  • [ ] Versioning strategy defined
  • [ ] Rollback plan ready
  • [ ] Monitoring in place
  • [ ] Health checks configured

Summary

You've learned:

  • ✅ How to deploy independently
  • ✅ CI/CD pipeline setup
  • ✅ Version management
  • ✅ Rollback strategies
  • ✅ Best practices

Micro Frontends enable true independent deployment!


Course Conclusion

Congratulations! You've completed the Angular Micro Frontends course.

You now understand:

  • ✅ Why Micro Frontends matter
  • ✅ How Module Federation works
  • ✅ How to build Host and Remote apps
  • ✅ How to configure and deploy

Next steps:

  • Build your own Micro Frontend system
  • Experiment with different patterns
  • Share your learnings

Remember: Great architecture solves the right problem at the right time.