Control API usage by limiting call frequency (e.g., 100 calls/min) versus total calls over a longer period (e.g., 10,000 calls/month).
→Use the `rate-limit` policy for call frequency. Use the `quota` policy for total call volume.
Why: `rate-limit` throttles short-term bursts and returns HTTP 429. `quota` enforces a usage cap over a longer term (e.g., a billing period) and returns HTTP 403 when exceeded.
Reference↗
Cache API responses in API Management to reduce backend load, with the cache key varying by a request header.
→Use a `<cache-lookup vary-by-header="..." />` policy in the inbound section and a `<cache-store duration="..." />` policy in the outbound section.
Why: This two-part policy combination enables response caching. `cache-lookup` checks for a cached item, and `cache-store` saves the response. The `vary-by` attributes ensure unique cache entries for different request variations.
Manage changes to an API. A breaking change is required vs. a non-breaking change needs to be tested.
→Use Versions for breaking changes (e.g., /v1, /v2). Use Revisions for non-breaking changes and safe, staged rollouts.
Why: Versioning allows multiple API versions to be live simultaneously. Revisions allow you to modify an API offline, test it, and then make it the "current" revision without downtime.
Notify multiple, independent downstream services when an event occurs in an Azure service (e.g., blob created, resource group created).
→Use Azure Event Grid. Create a system topic for the Azure resource and event subscriptions for each downstream handler.
Why: Event Grid is a fully managed, push-based pub/sub service that decouples event publishers from subscribers, enabling reactive, event-driven architectures.
Reference↗
Ingest a high-volume stream of telemetry or event data (millions of events per second) from many devices.
→Use Azure Event Hubs.
Why: Event Hubs is a massively scalable data streaming platform designed for high-throughput ingestion. It uses a partitioned consumer model for parallel processing.
Ensure events from the same source (e.g., a specific IoT device) are processed in order by the same consumer.
→Send events to Event Hubs with a partition key set to the source identifier (e.g., device ID).
Why: Event Hubs routes all messages with the same partition key to the same partition. Within a partition, message order is maintained.
Process a sequence of related messages in strict First-In, First-Out (FIFO) order.
→Use Azure Service Bus sessions. Send all related messages with the same `SessionId`.
Why: Sessions provide a concurrent, ordered stream of messages. A session-aware receiver locks the session, guaranteeing that messages are processed sequentially by a single consumer.
A single publisher sends messages to a topic, but multiple subscribers only want a subset of those messages based on message properties.
→Use a Service Bus topic with multiple subscriptions. Apply SQL filters or Correlation filters to each subscription.
Why: This is the canonical publish-subscribe pattern with content-based routing. Each subscription receives a copy of the message if it matches its filter rule.
A message cannot be processed successfully after multiple retries and must be set aside for later inspection.
→Let the message fail processing until its max delivery count is exceeded. It will automatically be moved to the Dead-Letter Queue (DLQ).
Why: The DLQ is a built-in sub-queue for poison messages. This prevents a failing message from blocking the main queue and allows for offline analysis and reprocessing.
Choose a messaging service for: enterprise commands, reactive events, or high-volume telemetry.
→Service Bus for commands (orders, transactions). Event Grid for reactive events (blob created, resource changed). Event Hubs for telemetry (IoT data, clickstreams).
Why: Service Bus offers rich features like ordering, transactions, and dead-lettering. Event Grid is for lightweight, push-based event routing. Event Hubs is for high-throughput data streaming.