Azure for .NET
Azure gives .NET workloads managed compute, data, messaging, identity, secrets, networking, delivery, and observability building blocks. A production design maps workload requirements to those capabilities, keeps authentication secret-free with managed identity, treats service limits and transient failure as architecture inputs, and proves security, reliability, performance, recovery, and cost through automation and telemetry.
Overview
A sound Azure design begins with workload requirements rather than a service catalog. Record critical flows, data classification, latency and availability objectives, recovery targets, scale shape, residency, integrations, and team responsibilities before selecting services. Choose compute by execution and control needs; choose data by access, consistency, partition, backup, and recovery needs; add messaging when buffering or temporal decoupling is valuable. In .NET, reuse Azure SDK clients and credential instances, use a convenient developer credential chain locally, and select ManagedIdentityCredential deterministically in hosted production. Assign only required data-plane roles. Bound timeouts and retries, make replayed effects idempotent, control concurrency before dependencies saturate, and carry cancellation and trace context throughout the call path. Infrastructure, private networking and DNS, immutable delivery, observability, quotas, budgets, backup, restore, regional recovery, and incident ownership are parts of the application architecture rather than work postponed until release.
What you will learn
- Select Azure compute, data, messaging, identity, networking, and observability services from workload requirements.
- Configure Azure SDK clients and deterministic authentication correctly in .NET.
- Design least-privilege managed identity and secret-free service access.
- Handle transient failure, throttling, duplicate delivery, concurrency, and dependency pressure safely.
- Build an immutable delivery path with infrastructure as code and production validation.
- Operate Azure workloads against measurable reliability, security, performance, and cost objectives.
Prerequisites
- ASP.NET Core dependency injection, configuration, logging, and asynchronous programming.
- Cloud identity, RBAC, networking, DNS, and distributed-system basics.
- An Azure subscription is optional for reading and local tests but required for deployment exercises.
When to use Azure for .NET
Good fit
- A .NET workload benefits from managed compute, identity, data, messaging, scaling, and Azure-native operations.
- The team can automate infrastructure, monitor service behavior, and own cost and recovery outcomes.
- Service capabilities and regional availability meet the workload requirements.
Choose another approach when
- A portable on-premises runtime or another cloud is a hard business constraint.
- A managed service cannot meet required protocols, residency, latency, or control boundaries.
- The organization cannot yet operate identity, networking, delivery, telemetry, backup, and cost safely.
Key concepts
Map latency, execution model, scale, network, recovery, compliance, and team-operating needs to services; do not begin from a favorite product.
Register thread-safe Azure SDK clients once, reuse credential and transport state, configure bounded retries, and pass cancellation to every asynchronous operation.
Use developer credentials locally, a deterministic managed identity in Azure, and least-privilege data-plane RBAC at the narrowest practical scope.
Keep endpoints and non-secret settings in typed configuration; reference secrets from Key Vault and rotate rather than embedding keys or connection strings.
App Service, Container Apps, Functions, and AKS trade platform control for operational responsibility, scale behavior, networking capabilities, and cost shape.
Choose data stores from access and consistency requirements, and use Service Bus or Event Hubs when buffering, temporal decoupling, or stream ingestion is required.
Bound attempts with timeouts, retry only transient and safe operations, control concurrency, and make side effects idempotent before replay.
Correlate traces, metrics, logs, deployments, cost, security posture, quotas, backup, and recovery evidence around workload service-level objectives.
Architecture
A managed entry point routes traffic to .NET compute, which uses identity-based access to data and messaging while emitting correlated telemetry.
Conceptual architecture · Adapt to your system context
Implementation walkthrough
The Azure .NET service baseline validates a storage endpoint, selects developer credentials locally and deterministic managed identity when hosted, reuses an Azure Blob client, exposes health, and tests identity selection without contacting Azure.
- 01Define the workload
Document users, critical flows, data classifications, SLOs, RTO, RPO, throughput, latency, residency, integration, and cost constraints.
- 02Choose service boundaries
Compare compute and managed dependencies by responsibility, limits, regions, networking, recovery, and operating burden.
- 03Design identity first
Create application and delivery identities, assign minimal RBAC, and decide system versus user-assigned lifecycle.
- 04Register SDK clients
Validate typed endpoints, reuse credentials and clients, set operation-aware timeouts and retries, and propagate cancellation.
- 05Build reliability controls
Add idempotency, admission control, backpressure, health semantics, dependency isolation, and degraded behavior.
- 06Instrument the workload
Emit correlated traces, metrics, structured logs, business outcomes, dependency signals, and deployment annotations.
- 07Automate delivery
Provision with reviewed infrastructure as code, publish immutable artifacts, scan dependencies, and use short-lived deployment identity.
- 08Prove operations
Load test, fail dependencies, verify backup and restore, exercise regional recovery, validate alerts, and compare actual cost to budget.
Code example
DefaultAzureCredential supports local developer identity and managed identity in Azure without changing application code.
using Azure.Identity;
using Azure.Storage.Blobs;
var accountUri = new Uri(builder.Configuration["Storage:AccountUri"]!);
var credential = new DefaultAzureCredential();
builder.Services.AddSingleton(new BlobServiceClient(
accountUri,
credential));
// Local: developer credential chain
// Azure: managed identity when configuredTesting strategy
Evidence must cover code behavior, Azure integration contracts, deployment, failure, and recovery.
- Unit test configuration, identity selection, idempotency, mapping, and retry classification.
- Run integration tests against emulators only where semantics are representative; use isolated Azure resources for authoritative tests.
- Test RBAC success and forbidden paths with the deployed workload identity.
- Load test dependency throttling, connection reuse, timeouts, backpressure, and scale behavior.
- Inject dependency, DNS, identity, and region failures and verify alerts and degraded behavior.
- Restore backups and execute the recovery runbook against defined RTO and RPO.
Security considerations
Azure security combines Entra identity, authorization, network boundaries, data protection, supply-chain controls, and continuous evidence.
- Use ManagedIdentityCredential and least-privilege RBAC instead of account keys.
- Separate control-plane deployment rights from application data-plane access.
- Use Key Vault references for unavoidable secrets and rotate with overlap.
- Encrypt in transit and at rest, restrict public exposure, and verify private DNS paths.
- Scan source, packages, images, templates, and deployed configuration.
- Log privileged changes and authentication failures without recording tokens or sensitive payloads.
Performance and scalability
Measure the whole request path and tune around downstream capacity, not only compute utilization.
- Reuse SDK clients, credentials, HttpClient transports, and database pools.
- Set bounded concurrency and queue prefetch from dependency throughput.
- Cache only with ownership, invalidation, staleness, and failure semantics.
- Load test warm, cold, burst, and sustained traffic with production-shaped data.
- Track percentile latency, throttling, saturation, connection counts, and cost per business operation.
- Scale out only after removing serialization, hot partitions, and downstream bottlenecks.
Deployment and operations
Promote the same immutable application and infrastructure definitions with environment-specific parameters.
- Build, test, audit, sign, and publish one immutable artifact.
- Preview infrastructure changes and gate identity, network, deletion, and cost risk.
- Use federated delivery identity with minimal environment scope.
- Deploy progressively with health, telemetry, and business-metric gates.
- Run identity, dependency, and critical-path smoke tests after deployment.
- Prefer forward repair while keeping tested rollback and data-recovery procedures.
Common problems and fixes
Works locally but receives 403 in Azure
Likely cause: The hosted identity is missing, the wrong identity is selected, or data-plane RBAC is absent or scoped incorrectly.
Fix: Log the credential mode without secrets, inspect the resource identity, role assignment scope, token audience, and allow propagation time.
Requests stall during an outage
Likely cause: Unbounded retries, long default timeouts, or connection exhaustion are consuming the latency budget.
Fix: Capture dependency timing, bound timeout and attempts, add jitter and admission control, and verify safe retry semantics.
Private endpoint name resolves publicly
Likely cause: The private DNS zone, virtual-network link, forwarding path, or record is missing.
Fix: Trace DNS from the workload subnet and correct zone links and resolvers before changing application code.
Scale-out increases failures
Likely cause: A downstream quota, connection pool, hot partition, or synchronized retry wave is saturated.
Fix: Limit concurrency, reuse connections, add jitter and buffering, repartition if needed, and raise quotas only with evidence.
Telemetry has disconnected traces
Likely cause: Propagation headers, Activity sources, exporters, or sampling configuration are inconsistent.
Fix: Verify W3C trace context across ingress, messaging, SDK calls, and workers; retain errors and representative traces.
Failover causes duplicate effects
Likely cause: In-flight work replayed or both regions processed the same operation.
Fix: Use globally meaningful idempotency keys, conditional writes, explicit ownership, and rehearsed traffic and consumer failover.
Best practices
- Choose Azure services from documented workload requirements and explicit responsibility boundaries.
- Use DefaultAzureCredential for local development and a specific ManagedIdentityCredential in hosted production.
- Reuse Azure SDK clients and credentials; do not create them for each request.
- Assign minimal data-plane RBAC and separate application, deployment, and human identities.
- Configure timeouts and bounded retry policies from operation semantics and downstream capacity.
- Use private networking only with a complete DNS, egress, observability, and operational design.
- Deploy immutable artifacts and infrastructure as code with staged validation and post-deployment smoke checks.
- Define SLOs, alerts, budgets, quotas, backup, restore, and regional recovery before production traffic.
Production checklist
- Workload requirements, SLO, RTO, RPO, residency, and ownership are approved.
- Compute and managed services are selected against limits and regional capabilities.
- Hosted code uses deterministic managed identity and minimal data-plane RBAC.
- SDK clients are reused with bounded timeouts, retries, cancellation, and concurrency.
- Network, DNS, egress, encryption, secret rotation, and audit paths are verified.
- Telemetry and alerts cover user outcomes, dependencies, deployments, saturation, and cost.
- Immutable delivery, infrastructure review, smoke tests, and recovery controls are automated.
- Load, failure, backup, restore, and regional recovery exercises meet acceptance targets.
Common interview questions
Why use deterministic credentials in production?
A fixed ManagedIdentityCredential prevents an unexpected credential in a chain from succeeding after configuration drift and makes the application identity auditable.
Why should Azure SDK clients be reused?
They are designed to be thread-safe and reuse transports and token caches; per-request construction adds connections, authentication calls, latency, and resource pressure.
When does messaging improve an Azure design?
When producers need buffering, independent scaling, retry isolation, fan-out, temporal decoupling, or durable acceptance before slower processing.
What does a private endpoint not solve?
It does not by itself solve DNS, outbound control, identity, authorization, data exfiltration, monitoring, high availability, or application-layer security.
How do you choose between system and user-assigned identity?
Use system-assigned for lifecycle-coupled simplicity; use user-assigned when identity must survive resource replacement or be shared deliberately across instances.
How should Azure service limits influence architecture?
Treat quotas, throttles, connection limits, scale units, and regional availability as design inputs, test near expected peaks, and automate quota monitoring.
What is the safe response to a regional dependency outage?
Follow a tested recovery design with idempotent failover, replicated or restorable data, controlled traffic movement, dependency validation, and clear consistency trade-offs.
Dedicated GitHub sample
Clone, run, test, and modify the focused implementation created for this guide.
Azure .NET Service Baseline
A .NET 10 API demonstrating validated Azure endpoints, reusable SDK clients, local developer credentials, deterministic production managed identity, health reporting, and identity-selection tests.
- Run
dotnet run --project src/AzureDotNetServiceBaseline- Test
dotnet test AzureDotNetServiceBaseline.slnx