Volume 5 · Chapter 8 — Advanced .NET Cloud Native Architecture
Azure Architecture Patterns
8.1 Introduction
Cloud-native systems on Azure lean on a set of well-established architecture patterns that solve recurring problems: distributing load, integrating services asynchronously, securing traffic, isolating tenants, and degrading gracefully under failure. This chapter surveys the patterns most likely to appear in senior interviews and real designs - not as trivia, but as the vocabulary you use to reason about a system.
8.2 Messaging and Asynchronous Integration
Rather than services calling each other synchronously (which couples their availability and latency), Azure Service Bus and Event Grid let services communicate through queues and events. A queue absorbs bursts and lets a slow consumer work at its own pace (the competing-consumers pattern scales throughput by adding consumers); publish/subscribe lets one event fan out to many independent subscribers without the publisher knowing them. This asynchrony is what makes services independently deployable and resilient to each other’s outages.
flowchart LR Prod[Order Service] -->|publish OrderPlaced| Topic[(Service Bus Topic)] Topic --> S1[Inventory Subscriber] Topic --> S2[Billing Subscriber] Topic --> S3[Notification Subscriber] S1 -. independent, retryable .-> DB1[(Inventory DB)]
8.3 Gateway, BFF, and Traffic Patterns
An API Gateway (Azure API Management, or a gateway inside AKS) provides a single controlled entry point that handles cross-cutting concerns - authentication, rate limiting, routing, TLS termination - so individual services don’t each re-implement them. The Backend-for-Frontend (BFF) pattern gives each client type (web, mobile) its own tailored gateway that aggregates and shapes data for that client. Front Door and Traffic Manager distribute traffic globally for latency and failover.
// A minimal BFF endpoint aggregating two downstream services for a mobile screen.
app.MapGet("/mobile/dashboard", async (IOrderApi orders, IProfileApi profiles, HttpContext ctx) =>
{
var userId = ctx.User.FindFirst("sub")!.Value;
// Aggregate + shape for the mobile client so it makes one call, not three.
var (recent, profile) = (await orders.GetRecentAsync(userId), await profiles.GetAsync(userId));
return Results.Ok(new { profile.DisplayName, recentOrders = recent.Take(5) });
});
8.4 Resilience Patterns
Cloud systems must assume dependencies will fail. The circuit breaker stops calling a failing dependency to let it recover and to fail fast; retries with exponential backoff and jitter handle transient faults; timeouts bound how long you wait; bulkheads isolate resource pools so one struggling dependency can’t exhaust all threads. In .NET these are expressed with Polly /Microsoft.Extensions.Http.Resilience. (Covered in depth in the resilience volume.)
8.5 Multi-Tenancy and Data Patterns
SaaS on Azure chooses a tenancy model per the isolation/cost trade-off: database-per-tenant (strong isolation, higher cost), shared database with a tenant discriminator (cheaper, needs rigorous row-level filtering), or a hybrid. Data patterns like CQRS (separate read and write models) and materialized views serve read-heavy workloads, while the outbox pattern ensures a state change and its published event are atomic.
When would you integrate services asynchronously via messaging rather than synchronous calls, and what does it cost you?
I integrate asynchronously via messaging when I want services to be decoupled in availability and load - when the caller shouldn’t fail or block just because the downstream is slow or temporarily down, and when the work can happen slightly later rather than strictly within the request. Concretely: when a service triggers work in others that doesn’t need to complete before responding to the user (placing an order that then triggers inventory, billing, and notification), asynchronous events let the order service respond immediately and each consumer process independently, so a billing outage doesn’t fail order placement. When load is bursty, a queue absorbs the spike and lets consumers drain it at a sustainable rate rather than overwhelming a synchronous downstream - the competing-consumers pattern then scales throughput by adding consumers. When one event should notify many independent subscribers, pub/sub fans out without the publisher knowing or depending on them, so new consumers are added without touching the publisher. And messaging gives durability and retryability - messages persist and redeliver, so transient failures self-heal and nothing is lost. The result is services that are independently deployable, independently scalable, and resilient to each other’s failures, which is the core reason to reach for it. But it costs you real complexity, and I’m explicit about that. You give up strong consistency for eventual consistency: the caller returns before downstream work completes, so the system is temporarily inconsistent and the UI/design must handle “accepted, processing” states rather than immediate truth. Debugging and reasoning get harder because flows are now spread across queues and consumers rather than a single call stack, so you need correlation IDs and distributed tracing to follow a request end to end. You must handle delivery semantics: messaging is typically at-least-once, so consumers must be idempotent to tolerate duplicates, and you need dead-letter queues and poison-message handling for messages that keep failing. Ordering is not guaranteed by default and must be designed for if it matters. There’s operational overhead in running and monitoring the broker (Service Bus/Event Grid), queue depth, and consumer lag. And error handling is no longer a simple thrown exception the caller sees - failures surface asynchronously and need their own alerting and compensation. So the trade is clear: asynchronous messaging buys decoupling, resilience, burst absorption, and independent scaling, at the price of eventual consistency, idempotency requirements, harder debugging, and broker operations. I use it where those benefits matter - cross-service workflows, bursty or fan-out work, resilience-critical paths - and I keep synchronous calls for genuinely request-scoped reads and simple, low-latency queries where the added complexity isn’t justified. Choosing per-interaction rather than dogmatically is the senior judgment.
How do you choose a multi-tenancy model for a new SaaS platform on Azure?
I choose the tenancy model by trading isolation, cost, scale, and operational complexity against the specific requirements - regulatory, commercial, and scale - rather than defaulting to one model, and I’m comfortable mixing models by tier. The three baseline options are database-per-tenant, shared database with a tenant discriminator, and a hybrid pool. Database-per-tenant gives the strongest isolation: each tenant’s data is physically separated, which simplifies compliance and per-tenant encryption, backup/restore, and even moving a tenant, and eliminates the catastrophic risk of a query leaking one tenant’s data to another; it also lets a large tenant be scaled or located independently. Its costs are higher per-tenant expense and operational overhead - many databases to provision, migrate, monitor, and patch - so schema migrations must fan out across all tenant databases, which needs automation. Shared database with a discriminator column is the cheapest and most operationally simple - one schema, one migration, high density - which suits many small tenants and a cost-sensitive model, but isolation is only logical: every query must rigorously filter by tenant (ideally enforced by row-level security or a global query filter, not left to developers remembering), a single bug can cross tenants, the “noisy neighbor” problem is real, and per-tenant compliance or data residency is hard. The hybrid/pool model balances these: pool small tenants into shared databases for density while giving large or premium/regulated tenants their own database, often mapping to pricing tiers. So I decide based on: regulatory and data-residency requirements (strong isolation or specific regions push toward database-per-tenant or regional pools); the customer profile (many small tenants favor shared; a few large enterprise tenants favor dedicated); the commercial model (premium tiers can justify and fund isolation); the noisy-neighbor and blast-radius tolerance (can one tenant’s load or a bug be allowed to affect others?); and operational maturity (can you automate migrations and management across many databases?). Practically I often land on a hybrid: shared pools for the long tail of small tenants to keep costs viable, dedicated databases for large or regulated tenants, with the application designed tenancy-agnostic (a tenant-resolution layer maps a tenant to its data location) so tenants can be promoted from pool to dedicated without rewriting the app. And regardless of model, I enforce tenant isolation defensively in code - a mandatory tenant filter/RLS so isolation doesn’t depend on every developer remembering it - because a cross-tenant data leak is an existential failure for a SaaS. So the answer is: match the model to isolation, compliance, scale, cost, and operations; strong isolation for regulated/large tenants, shared density for the small-tenant long tail, hybrid to get both, and always enforce isolation by construction. That deliberate, requirements-driven, often-mixed choice is what I’d expect an architect to articulate.
8.6 Retail Enterprise Scenario
A retail platform uses API Management as its single secured entry point, with per-client BFFs shaping data for web and mobile. Order placement publishes anOrderPlacedevent to a Service Bus topic; inventory, billing, and notification subscribers each process independently and idempotently, so a billing slowdown never blocks checkout. Front Door distributes traffic globally with failover, Polly circuit breakers protect calls to a flaky pricing dependency, and the SaaS backend pools small merchants into shared databases while giving large enterprise merchants dedicated databases - all behind a tenant-agnostic resolution layer.
Chapter Revision Notes
- Async messaging (Service Bus/Event Grid) decouples availability and absorbs bursts - at the cost of eventual consistency and idempotency requirements.
- API Gateway centralizes cross-cutting concerns; BFF tailors a gateway per client type.
- Resilience patterns - circuit breaker, retry with backoff, timeout, bulkhead - assume dependencies fail.
- Multi-tenancy trades isolation vs cost: database-per-tenant, shared-with-discriminator, or hybrid pools.
- Enforce tenant isolation by construction (RLS/global filter), never by developer discipline alone.