Advertisement
Advanced .NET, CORS & Cross-Origin Resource Sharing

How does CORS interact with a reverse proxy or API gateway sitting in front of multiple backend microservices?

Short answer

When a browser calls through an API gateway acting as a single origin (e.g., https://api.mycompany.com routing to multiple backend services), CORS only needs to be configured once at the gateway layer since that's the origin the browser actually communicates with -- the backend…

Save .NET mock interview
Advertisement
AModel answer
When a browser calls through an API gateway acting as a single origin (e.g., https://api.mycompany.com routing to multiple backend services), CORS only needs to be configured once at the gateway layer since that's the origin the browser actually communicates with -- the backend microservices behind the gateway typically don't need their own CORS configuration since they're never called directly cross-origin by the browser, simplifying CORS management significantly in a microservices architecture.
// Browser only ever talks to the gateway origin:
// fetch('https://api.mycompany.com/orders')  -- gateway handles CORS
// Gateway internally routes to http://orders-service:8080 (no CORS needed here,
// since this is server-to-server, not browser-to-server)
Real-world example
A microservices platform configures CORS exactly once at their YARP-based API gateway, eliminating the need to duplicate and maintain consistent CORS policies across dozens of individual backend services that the browser never contacts directly.
Likely follow-ups
  • What CORS considerations remain if a gateway does server-side aggregation calling multiple backends?
  • How does this simplification break down if some services are exposed directly, bypassing the gateway?
Related topics