swbanga.com
adr-003Proposedby Super Washington Banga

Azure Container Apps with Scale-to-Zero for Cloud-Native Microservices

  • med-core
  • ledger-core
  • azure
  • container-apps
  • scale-to-zero

Context

Both Ledger-Core and Med-Core run on Azure Container Apps with Terraform. Idle environments keep containers hot overnight, and Med-Core's first deployment missed the scale-to-zero configuration entirely, leaving the intake worker running at full capacity for a full night.

Decision

Adopt Azure Container Apps scale-to-zero as the standard deployment posture for background workers and non-critical APIs: minimum replicas of zero, HTTP-triggered scaling for APIs, and event-driven KEDA triggers for queue workers.

Consequences — Positive

  • Idle services consume zero compute, cutting overnight cost to storage only
  • KEDA event-driven scaling matches Redis queue depth and RabbitMQ delivery
  • A single Terraform module standardizes the posture across both services

Consequences — Negative

  • Cold starts add latency to first requests after idle (JWT key caches drop)
  • Scale-to-zero is not suitable for latency-critical ledger settlement paths
  • Monitoring must distinguish cold-start latency from regressions

Problem

The overnight cost report exposed it: the Med-Core intake worker stayed at one replica all night because the first deployment shipped without scaling rules. The platform needed an explicit, standard posture instead of a per-service accident.

Proposal

Standardize on scale-to-zero for workers and non-critical APIs, expressed in the shared Terraform module:

hcl
resource "azurerm_container_app" "worker" {
  ...
  template {
    min_replicas = 0
    max_replicas = 5
    scale {
      min_replicas = 0
      max_replicas = 5
      rule {
        name = "redis-queue-depth"
        custom { type = "keda" } # queue-based triggers
      }
    }
  }
}

Open questions

  • Scale-in delay: how long should idle replicas linger before the KEDA trigger releases them, and how is that tuned per workload?
  • Which paths are latency-critical enough to opt out of scale-to-zero? Ledger settlement is the early candidate.
  • What monitoring signal distinguishes a cold start from a regression, given that first-request latency is now a first-class metric?