1. APIM Role in Architecture
APIM implements the facade pattern — a single, consistent entry point that hides the complexity of multiple backend services. This decouples frontend consumers from backend implementation details and centralises cross-cutting concerns.
Cross-Cutting Concerns Handled by APIM
- Authentication & authorization — validate tokens before traffic reaches backends
- Rate limiting & throttling — protect backends from burst traffic
- Caching — reduce backend load for read-heavy APIs
- Request/response transformation — reshape payloads without changing backends
- Logging & analytics — unified telemetry across all APIs
- Versioning & deprecation — expose stable contracts while evolving backends
2. APIM Tiers — Decision Matrix
Choosing the right tier is a cost-vs-capability trade-off that appears frequently on AZ-305.
| Tier | SLA | VNet | Multi-Region | Dev Portal | Scale Units | Best For |
|---|---|---|---|---|---|---|
| Consumption | 99.95% | ❌ | ❌ | ✅ | Auto | Serverless, low-traffic, pay-per-call |
| Developer | No SLA | ❌ | ❌ | ✅ | 1 (no scale) | Dev/test, prototyping |
| Basic | 99.95% | ❌ | ❌ | ❌ | Up to 2 | Small production, no portal needed |
| Standard | 99.95% | ❌ | ❌ | ✅ | Up to 4 | Medium production workloads |
| Premium | 99.99% | ✅ | ✅ | ✅ | Up to 12+ | Enterprise, VNet, multi-region, compliance |
3. APIM Architecture
Every APIM instance comprises three logical components:
- Gateway (data plane) — proxies API calls, enforces policies, routes to backends. This is the performance-critical path.
- Management plane — Azure Resource Manager APIs + Azure portal experience for configuring APIs, products, policies, users.
- Developer portal — auto-generated, customisable documentation site where API consumers discover, test, and subscribe to APIs.
Policy Pipeline
Policies execute at four stages of a request lifecycle:
- Inbound — runs before the request reaches the backend (auth, rate-limit, transform)
- Backend — runs just before forwarding (set backend URL, client cert)
- Outbound — runs after backend response (transform, cache-store, headers)
- On-error — runs if any stage throws an exception
<policies>
<inbound>
<rate-limit calls="100" renewal-period="60" />
<validate-jwt header-name="Authorization" ...>
</inbound>
<backend>
<forward-request />
</backend>
<outbound>
<cache-store duration="300" />
</outbound>
<on-error>
<set-body>@("Error: " + context.LastError.Message)</set-body>
</on-error>
</policies>
4. Key Policies
| Policy | Stage | Purpose | Example |
|---|---|---|---|
rate-limit | Inbound | Throttle per subscription key | 100 calls/min |
rate-limit-by-key | Inbound | Throttle by custom expression (IP, user) | By caller IP |
quota | Inbound | Hard cap over longer period | 10,000 calls/month |
cache-lookup / cache-store | Inbound / Outbound | Built-in response caching | Cache GET for 5 min |
validate-jwt | Inbound | Validate OAuth 2.0 / OIDC tokens | Check issuer, audience, claims |
set-header | Any | Add/remove/replace headers | Strip internal headers outbound |
set-body | Any | Transform request/response body | XML → JSON conversion |
rewrite-uri | Inbound | Change URL path before forwarding | /v2/orders → /api/orders |
mock-response | Inbound | Return static response without calling backend | Prototyping, testing |
retry | Backend | Retry failed backend calls | 3 retries, exponential back-off |
send-request | Any | Call an external service (e.g., lookup cache, enrich) | Fetch user profile, attach to request |
<base /> to control ordering.
5. Backend Abstraction: Versioning & Revisions
Versioning Strategies
| Scheme | Example | Pros | Cons |
|---|---|---|---|
| URL path | /v1/orders | Explicit, easy to cache/route | URL changes per version |
| Query string | /orders?api-version=2024-01-01 | URL stays same; Azure's own pattern | Harder to discover |
| Header | Api-Version: 2 | Clean URLs | Not visible in browser, harder to test |
Revisions vs Versions
- Revision — non-breaking changes (bug fix, add optional field). Consumers don't notice. You can test a revision before making it current. Think: git branch before merge.
- Version — breaking changes (removed field, new auth model). Consumers choose which version to call. Think: v1 vs v2 coexisting.
6. Security Patterns
OAuth 2.0 Flow Through APIM
Security Layers
| Mechanism | Where | Use Case |
|---|---|---|
| Subscription keys | APIM inbound | Identify callers, basic access control per product |
| OAuth 2.0 / JWT validation | APIM inbound (validate-jwt) | Delegated auth, fine-grained claims-based access |
| Client certificates (mTLS) | APIM inbound | Partner-to-APIM mutual authentication |
| Managed Identity | APIM → Backend | APIM authenticates to backend without secrets (e.g., to Azure Functions, App Service) |
| IP filtering | APIM inbound policy | Restrict to known CIDR ranges |
7. Networking: VNet Modes & Self-Hosted Gateway
VNet Integration Modes (Premium Only)
| Mode | Gateway Accessible From | Backend Accessible From | Use Case |
|---|---|---|---|
| External | Internet (public IP) | VNet + Internet | Public-facing API with private backends |
| Internal | VNet only (private IP) | VNet only | Fully private API platform; expose via App Gateway / Front Door |
Self-Hosted Gateway
A containerised gateway you deploy on-premises, in other clouds, or at the edge. It connects back to the APIM management plane for configuration sync.
- Runs as a Docker container or Kubernetes deployment
- Enables hybrid/multi-cloud API governance with a single control plane
- Policies and API definitions sync from the Azure-hosted management plane
- Available on Developer and Premium tiers
8. Multi-Region Deployment
Premium tier supports deploying additional gateway units to multiple Azure regions, providing:
- Lower latency — clients route to the nearest gateway via Traffic Manager / Front Door
- Higher availability — if one region fails, traffic shifts to healthy regions (99.99% SLA)
- Compliance — keep data processing in-region where required
How It Works
- Primary region hosts the management plane (one region always "primary")
- Additional regions host gateway units only
- Configuration syncs automatically from primary to all regions
- Each region can have its own backend pool (use
set-backend-servicepolicy with expressions to route by region)
9. Real-World: Banking API Platform
🏦 Scenario: Open Banking Partner API
A bank exposes internal services (accounts, payments, standing orders) to fintech partners via APIM.
Architecture Decisions
- Tier: Premium — requires VNet integration (backends in private VNet) and multi-region for DR
- Networking: External VNet mode — partners call from internet, backends are VNet-private
- Security stack:
- Partners authenticate via OAuth 2.0 (client credentials flow) → APIM validates JWT with
validate-jwt - Client certificates required for high-value payment APIs (mTLS)
- Subscription keys per partner for identification & analytics
- APIM uses managed identity to call backend Azure Functions
- Partners authenticate via OAuth 2.0 (client credentials flow) → APIM validates JWT with
- Rate limiting: Per-partner quotas (10,000 calls/day basic tier, 100,000 premium tier) via Products
- Audit: All requests logged to Event Hub → Splunk for regulatory compliance
- Versioning: URL path scheme (
/v1/accounts,/v2/accounts) — partners migrate at their own pace
Result
50+ fintech partners onboarded via the developer portal. Zero backend exposure. Rate limiting prevented a partner's runaway script from impacting other consumers. Audit trail satisfies PSD2 regulatory requirements.
10. Knowledge Check
Q1: Which APIM tier is required to deploy the gateway inside a Virtual Network?
Q2: In the APIM policy pipeline, at which stage does cache-store execute?
Q3: What is the difference between a revision and a version in APIM?
Q4: How should APIM authenticate to a backend Azure Function without storing secrets?