Volume 8 · Chapter 2 — Azure Cloud Architecture & Enterprise DevOps for .NET Engineers
Azure Compute Services
2.1 Introduction
Azure offers a spectrum of compute options that trade control for operational simplicity. At one end, Virtual Machines give you the whole operating system and maximum control; at the other, Azure Functions run your code with no server to manage at all. Choosing well is one of the highest-leverage architectural decisions because it sets the cost model, scaling behavior, and operational burden for the life of the workload. The guiding principle is to move as far up the managed-service stack as your requirements allow.
2.2 The Control-vs-Managed Spectrum
flowchart LR VM["Virtual Machines\n(full OS control)"] --> VMSS["VM Scale Sets"] VMSS --> AKS["AKS\n(managed Kubernetes)"] AKS --> ACA["Container Apps\n(serverless containers)"] ACA --> App["App Service\n(managed PaaS)"] App --> Fn["Functions\n(serverless / event-driven)"] VM -. "more control, more ops" .- Fn Fn -. "less ops, less control" .- VM
2.3 Virtual Machines and Scale Sets
VMs suit lift-and-shift migrations, legacy software with specific OS requirements, and workloads needing kernel-level control. Virtual Machine Scale Sets add automatic horizontal scaling and zone distribution. The cost is that you own patching, hardening, and availability engineering - the most operational overhead of any option.
2.4 Azure App Service
App Service is a managed platform for web apps and APIs: you deploy your .NET build and it handles the OS, runtime, load balancing, TLS, and autoscaling. It is the pragmatic default for most enterprise web workloads because it removes almost all infrastructure toil while still supporting VNet integration, deployment slots, and scale rules.
// Deployment slots enable zero-downtime releases: deploy to "staging", warm it,
// then swap. The swap is a routing change, not a redeploy.
// az webapp deployment slot create -n payments-api -g rg --slot staging
// az webapp deploy -n payments-api -g rg --slot staging --src-path app.zip
// az webapp deployment slot swap -n payments-api -g rg --slot staging --target-slot production
2.5 Azure Functions and Serverless
Functions run event-driven code with per-execution billing on the Consumption plan, scaling to zero when idle and out automatically under load. They excel at glue and background work - queue processing, scheduled jobs, event reactions. The trade-offs are cold starts (mitigated by Premium plans or pre-warmed instances) and a stateless, short-execution model.
// An isolated-worker Azure Function triggered by a Service Bus queue.
public class SettlementFunction
{
private readonly ISettlementService _service;
public SettlementFunction(ISettlementService service) => _service = service;
[Function("ProcessSettlement")]
public async Task Run(
[ServiceBusTrigger("settlements", Connection = "Bus")] SettlementMessage msg,
FunctionContext ctx)
{
await _service.SettleAsync(msg.PaymentId, ctx.CancellationToken);
}
}
2.6 Container Options: ACI, Container Apps, AKS
Azure Container Instances run a single container quickly for simple or burst jobs. Azure Container Apps offer serverless containers with built-in autoscaling (including scale-to-zero via KEDA), ingress, and revisions - ideal for microservices that do not need full Kubernetes control. AKS (Chapter 6) gives the full Kubernetes API for teams that need its power and are ready for its complexity.
2.7 Choosing a Compute Service
| Service | Choose when | Main trade-off |
|---|---|---|
| Virtual Machines | Full OS control, legacy, lift-and-shift | Most operational overhead |
| App Service | Standard web apps/APIs, fast delivery | Less low-level control |
| Functions | Event-driven, bursty, pay-per-use | Cold starts, stateless short runs |
| Container Apps | Microservices without full K8s | Less control than AKS |
| AKS | Complex orchestration, portability | Highest complexity |
2.8 Scaling and Availability
Prefer horizontal autoscaling driven by real signals - CPU, queue length, request rate - over manual vertical scaling. Distribute instances across availability zones and front them with a load balancer or Front Door for resilience. Design services to be stateless so any instance can serve any request and scaling is frictionless.
2.9 Cost Optimization
Compute is usually the largest cloud bill. Right-size instances from real metrics, use autoscaling to avoid paying for idle capacity, choose serverless for spiky or low-duty workloads, and apply reservations or savings plans for steady baseline load. Scale-to-zero options (Functions, Container Apps) eliminate cost for idle services entirely.
How do you choose between App Service, Functions, and VMs?
I match the workload to the least-operational option that satisfies its constraints. A standard, always-on web app or API goes to App Service - managed platform, autoscaling, deployment slots, minimal ops. Event-driven or bursty work with idle periods goes to Functions, which scales to zero and bills per execution, accepting cold starts. VMs are the fallback for workloads that need full OS control, specific kernel/software requirements, or lift-and-shift of legacy systems, accepting that I now own patching and availability. The decision hinges on control needed, traffic pattern (steady vs bursty), and how much operational burden the team should carry - I move up the managed stack whenever requirements allow.
What is a cold start and how do you mitigate it for serverless workloads?
A cold start is the added latency when a serverless platform must allocate and initialize a new instance (load the runtime, JIT, run startup) because none was warm - common after idle periods or during scale-out. Mitigations include using a Premium/Elastic plan that keeps pre-warmed instances ready, enabling always-ready/minimum instances, reducing startup cost with ReadyToRun or Native AOT and lean dependency graphs, and keeping functions small. For latency-critical user-facing paths I might avoid Consumption-plan serverless altogether and use App Service or Container Apps with a minimum instance count. The trade-off is that eliminating cold starts costs the idle capacity that scale-to-zero was saving.
What are deployment slots and how do they enable zero-downtime releases?
Deployment slots are live instances of an App Service app (for example a “staging” slot alongside “production”) that share the app’s plan. You deploy the new version to staging, warm it up and run smoke tests against it while it takes no production traffic, then perform a swap - which is a routing change that promotes staging to production instantly. Because the new version is already warm when it goes live, there is no cold-start hit and the swap is near- instantaneous, and if something is wrong you swap back immediately for a fast rollback. Slots effectively give you blue-green deployment as a built-in platform feature.
How do you design a compute strategy for a large enterprise with many diverse workloads?
I avoid a one-size-fits-all mandate and instead define a small set of sanctioned compute patterns mapped to workload archetypes, so teams choose from guardrails rather than the entire menu. Standard web APIs default to App Service or Container Apps; event-driven and background work to Functions; complex microservice systems needing orchestration and portability to a shared AKS platform; and VMs only for justified legacy or specialized cases, by exception. I back this with a platform-engineering approach - golden templates (IaC modules), shared CI/CD, and built-in observability - so the right choice is also the easy choice. On cost, I standardize autoscaling, right-sizing from metrics, and reservations for steady baselines. The goal is consistency and operational leverage across many teams without forcing unsuitable workloads onto a single technology.
When would you deliberately NOT use Kubernetes/AKS even though the team wants it?
When the operational complexity is not justified by the workload’s needs. Kubernetes brings enormous power - fine-grained orchestration, portability, a rich ecosystem - but also a steep operational surface: cluster upgrades, networking, security policy, capacity, and the expertise to run it safely. For a handful of stateless services with straightforward scaling, Azure Container Apps or App Service deliver most of the benefit (autoscaling, ingress, revisions, scale-to- zero) with a fraction of the operational burden. I’d choose AKS when there is genuine need - complex multi-service orchestration, specific Kubernetes features, multi-cloud portability, or an existing K8s investment and skill set - and steer smaller footprints to simpler PaaS. Adopting Kubernetes for résumé reasons rather than requirements is a common and expensive mistake, so I require the complexity to be earned.
2.10 Banking Enterprise Scenario
A bank runs a heterogeneous compute estate matched to each workload. Customer- facing APIs run on App Service with deployment slots for zero-downtime releases and zone redundancy for availability. Event-driven settlement and notification jobs run as Azure Functions that scale to zero between bursts. The core microservice platform runs on a shared AKS cluster managed by a platform team, while a legacy risk-calculation engine that needs a specific OS configuration remains on VM Scale Sets during modernization. Every workload is provisioned from golden IaC templates, autoscaled on real signals, and covered by reservations for its steady baseline - balancing agility, reliability, and cost across the portfolio.
Chapter Revision Notes
- Compute is a control-vs-managed spectrum from VMs to Functions.
- Default to App Service/Container Apps for web workloads; Functions for event-driven.
- Use AKS only when its orchestration power is genuinely needed.
- Deployment slots give built-in blue-green, zero-downtime releases.
- Prefer horizontal autoscaling, zone distribution, and stateless design.
- Optimize cost with right-sizing, autoscaling, scale-to-zero, and reservations.