本文由 AI 分析生成
建立時間: 2026-03-28 來源: https://learn.microsoft.com/en-us/azure/architecture/patterns/async-request-reply
Summary
Microsoft’s Azure Architecture Center documentation for the Asynchronous Request-Reply pattern — a technique to decouple long-running backend processing from frontend callers using HTTP polling. The pattern returns HTTP 202 Accepted immediately with a Location header pointing to a status endpoint, then redirects to the completed resource once processing finishes.
Microsoft Azure 架構中心對非同步請求-回覆模式的文件說明:透過 HTTP 輪詢解耦長時間執行的後端處理與前端呼叫端。模式立即回傳 HTTP 202 加 Location 標頭,完成後重定向到結果資源。
Key Points
- Problem: some backend operations take seconds to minutes; synchronous HTTP can’t wait that long and connections time out
- Solution: accept immediately with 202 +
Locationheader → client polls status endpoint → endpoint returns 200 (pending) or 302 redirect (complete) to result resource - Key HTTP headers:
Location(status endpoint URL, can be SAS token for access control),Retry-After(polling interval hint to avoid hammering backend) - Pattern flow: POST → 202 → poll GET /status/{id} → 200 “in progress” → … → 302 to result resource → GET result → 200 with data
- When NOT to use: when WebSockets/SignalR are available (prefer push over poll), when using event-driven services (Azure Event Grid), when streaming results are needed
Insights
The key tension this pattern resolves is between REST’s stateless request-response model and the real-world existence of long-running operations. HTTP was designed around sub-second responses; the 202 Accepted pattern is the canonical REST-compatible workaround.
The Retry-After header is critical for production correctness — without it, clients either poll too aggressively (hammers the backend) or use arbitrary fixed delays (slow for fast jobs). The server knows best how long the operation will take.
HTTP 302 redirect at completion is elegant: it means the status endpoint URL doesn’t need to serve the result data itself — it just redirects to wherever the result was stored (blob storage, new resource URL). This keeps the status polling layer thin.
Connections
Raw Excerpt
The API responds synchronously as quickly as possible. It returns an HTTP 202 (Accepted) status code to acknowledge that it received the request for processing. The response includes a location reference that points to an endpoint that the client can poll to check the result of the long-running operation.