ASP.NET Core Web API Interview Question #188
How would you design an API that calls several external services?
Senior API Design, Architecture, Scalability & Production Scenarios Senior Advanced
Quick Interview Answer
Place each external integration behind a focused client abstraction and configure it through IHttpClientFactory. Apply explicit timeouts, cancellation, resilience policies, and observability per dependency.
Detailed Explanation
Place each external integration behind a focused client abstraction and configure it through IHttpClientFactory. Apply explicit timeouts, cancellation, resilience policies, and observability per dependency.
Avoid holding a database transaction open across slow network calls. Decide whether the workflow needs synchronous coordination, asynchronous messaging, compensation, or eventual consistency based on business guarantees.
Code Example
builder.Services.AddHttpClient<IPaymentClient, PaymentClient>();
builder.Services.AddHttpClient<IShippingClient, ShippingClient>();
// Application service coordinates the workflow;
// controllers do not contain integration details.