ASP.NET Core Web API Interview

Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability

ASP.NET Core Web API interview questions covering error handling, logging, caching, rate limiting, CORS and reliability.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
126
SeniorAdvanced

What is centralized exception handling in ASP.NET Core Web API?

Centralized exception handling catches unhandled exceptions at a common point in the HTTP pipeline instead of repeating try/catch blocks in every controller action. It is typically implemented with ASP.NET Core exception-handling middleware.

127
SeniorAdvanced

Why should controllers avoid repetitive try/catch blocks?

Repeated try/catch logic makes controllers noisy and often produces inconsistent logging and response formats. Expected business outcomes should normally be represented explicitly, while unexpected exceptions can be handled centrally.

128
SeniorAdvanced

What is ProblemDetails and why is it useful for API errors?

ProblemDetails is a standardized structure for HTTP API errors. It commonly includes type, title, status, detail, and instance, and can be extended with additional safe metadata such as a trace identifier.

129
SeniorAdvanced

How should validation errors differ from unexpected server errors?

Validation errors are expected client-facing failures and should identify invalid input with an appropriate 4xx status and useful field-level details. Unexpected exceptions indicate an unplanned server failure and normally result in a safe 500 response.

130
SeniorAdvanced

What is structured logging in ASP.NET Core?

Structured logging records named properties separately from the human-readable message. This lets logging systems filter, aggregate, and search by fields such as OrderId, UserId, or elapsed time.

131
SeniorAdvanced

What are common logging levels in ASP.NET Core?

Common levels are Trace, Debug, Information, Warning, Error, and Critical. The level should reflect the operational significance of an event rather than simply how much text is being logged.

132
SeniorAdvanced

What information should not be written to API logs?

Avoid logging passwords, access tokens, refresh tokens, private keys, connection strings, payment secrets, and unnecessary personal or confidential information. Request and response bodies can also contain sensitive data and should not be logged indiscriminately.

133
SeniorAdvanced

What is a correlation ID or trace ID?

A correlation or trace identifier lets related log entries and distributed operations be connected to the same request or workflow. ASP.NET Core exposes request tracing information through HttpContext, and distributed tracing can propagate context across service boundaries.

134
SeniorAdvanced

What is response caching?

Response caching stores and reuses HTTP responses according to HTTP caching semantics and cache headers. It is most suitable for responses that can safely be reused for equivalent requests.

135
SeniorAdvanced

What is output caching in ASP.NET Core?

Output caching stores endpoint responses on the server and can reuse them according to configured policies. It provides application-controlled caching behavior and can reduce repeated work for suitable endpoints.

136
SeniorAdvanced

What is in-memory caching?

In-memory caching stores data in the memory of the current application process. It is fast and simple for data that is safe to recreate and where process-local cache behavior is acceptable.

137
SeniorAdvanced

What is distributed caching?

A distributed cache is shared by multiple application instances, commonly through a dedicated system such as Redis or another supported distributed-cache provider. It can support consistent cached data across a scaled-out API.

138
SeniorAdvanced

What is cache invalidation?

Cache invalidation removes or replaces cached data when it is no longer valid. Common strategies include time-based expiration, explicit removal after writes, versioned keys, and event-driven invalidation.

139
SeniorAdvanced

What is rate limiting in ASP.NET Core Web API?

Rate limiting restricts the number or rate of requests accepted for a client or partition. It can protect service capacity, reduce accidental overload, and enforce usage policies.

140
SeniorAdvanced

What is HTTP 429 Too Many Requests?

429 Too Many Requests indicates that a client has exceeded an applicable request limit. A rate-limited API may also provide retry information such as a Retry-After header when the policy can determine an appropriate delay.

141
SeniorAdvanced

What is CORS and why is it not an API security mechanism by itself?

CORS controls whether browser JavaScript from one origin is permitted to read responses from another origin. It is enforced by browsers and is important for frontend integration.

142
SeniorAdvanced

What is a CORS preflight request?

For certain cross-origin requests, a browser first sends an OPTIONS request to ask whether the actual method, headers, and origin are permitted. This is called a preflight request.

143
SeniorAdvanced

What is a timeout and why should external calls have one?

A timeout limits how long an operation is allowed to wait before it is treated as failed. Without suitable timeouts, slow downstream dependencies can consume request resources for excessive periods and contribute to cascading failures.

144
SeniorAdvanced

What is a retry policy?

A retry policy repeats an operation after a transient failure that may succeed on a later attempt, such as a brief network interruption. Retries should use bounded attempts and usually delay or backoff between attempts.

145
SeniorAdvanced

What is the circuit breaker pattern?

A circuit breaker temporarily stops calls to a dependency after repeated failures. This prevents every incoming request from continuing to wait on a dependency that is already known to be unhealthy.

146
SeniorAdvanced

What is idempotency and why is it important for reliable POST operations?

POST is not inherently idempotent, so retrying a request can create duplicate orders, payments, or other effects. For operations where clients may safely retry, the API can support an idempotency key and remember the result associated with that key.

147
SeniorAdvanced

What are health checks in ASP.NET Core?

Health checks expose application health information for infrastructure such as orchestrators, load balancers, and monitoring systems. Checks can report whether the process is running and whether critical dependencies are available.

148
SeniorAdvanced

What is the difference between liveness and readiness checks?

A liveness check answers whether the application process is alive enough to continue running. A readiness check answers whether the instance is currently ready to receive traffic.

149
SeniorAdvanced

How can an API improve resilience when a downstream service fails?

Use bounded timeouts, cancellation, carefully targeted retries, circuit breakers, fallback behavior where semantically safe, and clear failure responses. Monitor downstream latency and failure rates so reliability problems are visible.

150
SeniorAdvanced

What are best practices for error handling, logging, caching, rate limiting, CORS, and API reliability?

Handle unexpected exceptions centrally and return consistent, safe ProblemDetails responses. Use structured logs with correlation or trace identifiers while excluding secrets and unnecessary sensitive data. Distinguish expected client errors from unexpected server failures.