.NET Scenario-Based Interview Questions and Answers
Open-ended, real-world .NET interview scenarios — an endpoint slow under load, an intermittent production NullReferenceException, stale data after a save — with a structured way to answer each.
Scenario questions test how you think, not what you have memorised. Each of these has no single right answer — the interviewer wants a structured approach, the common causes, and how you would confirm which one it is. Answer out loud, working from data.
Performance & load
3 questionsReproduce with realistic concurrency, then use data — server metrics (CPU, memory, GC, thread-pool queue), request tracing/APM, and the database's own view (slow query log, wait stats). The usual causes:…
Read detailed answerMeasure first: capture the actual execution plan and STATISTICS IO/TIME. Then look for the usual culprits — a scan where a seek should happen (missing or unusable index), non-sargable predicates (functions on…
Read detailed answerEager loading pulls related data in the same query using Include(). Lazy loading fetches a navigation property automatically the first time you access it — convenient but the classic cause of the N+1 query…
Read detailed answerDebugging production
3 questionsGet the exact stack trace and a correlation ID from structured logging, and identify the line and the reference that's null. “Intermittent” and “only in production” usually points to concurrency (a…
Read detailed answerA captive dependency is when a longer-lived service holds a reference to a shorter-lived one, “capturing” it and keeping it alive far longer than intended. The classic case is a Singleton that injects a…
Read detailed answerDbContext is registered as Scoped because it is a lightweight, stateful, not thread-safe unit-of-work. One instance per request lets every repository and service in that request share the same change tracker…
Read detailed answerCaching & consistency
3 questionsSomething between the write and that user's read is serving an older version: an application or output cache that wasn't invalidated, a long-lived DbContext returning tracked (pre-update) entities, HTTP/CDN…
Read detailed answerChange tracking is how EF Core knows what to save. When you query with tracking (the default), the context keeps a snapshot of each entity and assigns it a state — Unchanged, Added, Modified, Deleted. On…
Read detailed answerA transaction is a unit of work that either fully completes or has no effect. ACID is the set of guarantees: Atomicity (all-or-nothing), Consistency (constraints hold before and after), Isolation (concurrent…
Read detailed answer