Microservices Router

Architecture

Deploy ALB as a central router for microservices:

  • Host-based routing for service domains
  • Path-based routing for service endpoints
  • Independent target groups per microservice
  • Health checks for each service
  • Blue-green deployments with weighted target groups

When to Use

Use ALB as a microservices router when:

  • Running containerized workloads on ECS or EKS
  • Services need independent scaling and deployment
  • You want centralized traffic management
  • Services communicate over HTTP/HTTPS

Example Configuration

module "microservices_alb" {
  source  = "registry.patterneddesigns.ca/patterneddesigns/alb/aws"
  version = "3.0.0"

  name    = "microservices-alb"
  vpc_id  = module.vpc.vpc_id
  subnets = module.vpc.public_subnets

  https_listeners = [{
    port            = 443
    certificate_arn = aws_acm_certificate.wildcard.arn
  }]

  listener_rules = [
    # User service
    {
      priority   = 100
      conditions = [{ host_header = ["users.example.com"] }]
      actions    = [{ type = "forward", target_group_arn = aws_lb_target_group.users.arn }]
    },
    # Order service
    {
      priority   = 200
      conditions = [{ host_header = ["orders.example.com"] }]
      actions    = [{ type = "forward", target_group_arn = aws_lb_target_group.orders.arn }]
    },
    # Inventory service
    {
      priority   = 300
      conditions = [{ host_header = ["inventory.example.com"] }]
      actions    = [{ type = "forward", target_group_arn = aws_lb_target_group.inventory.arn }]
    },
    # API versioning with path
    {
      priority = 400
      conditions = [
        { host_header = ["api.example.com"] },
        { path_pattern = ["/v2/*"] }
      ]
      actions = [{ type = "forward", target_group_arn = aws_lb_target_group.api_v2.arn }]
    },
    {
      priority = 500
      conditions = [
        { host_header = ["api.example.com"] },
        { path_pattern = ["/v1/*"] }
      ]
      actions = [{ type = "forward", target_group_arn = aws_lb_target_group.api_v1.arn }]
    }
  ]
}

Considerations

  • Use wildcard SSL certificates for subdomain routing
  • Configure appropriate timeouts for long-running requests
  • Consider sticky sessions for stateful services
  • Monitor target group health in CloudWatch