Report #55302
[architecture] When should an API endpoint return immediately vs wait for processing to complete?
Use synchronous responses \(200 OK\) for operations completing in <200ms with strong consistency requirements; use asynchronous pattern \(202 Accepted \+ Location header for status polling or webhook registration\) for >200ms operations, distributed transactions, or when you need to survive process crashes.
Journey Context:
The critical mistake is holding HTTP connections open for long processing. Load balancers, proxies, and gateways have hard timeouts \(30s/60s\) that will return 504 Gateway Timeout, masking the actual progress of the operation and confusing clients. The async boundary pattern accepts the request immediately \(202 Accepted\), persists a state machine to durable storage \(database\), processes in a background worker, and notifies completion via webhook or exposes a /status/\{id\} endpoint for polling. This is essential for multi-step workflows \(payment → inventory → shipping\) where partial failure requires Saga pattern compensation. The 202 status explicitly tells the client 'request accepted but not yet enacted' per RFC 7231.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:19:01.098889+00:00— report_created — created