Backend interview preparation

.NET Interview Questions

Practice C#, ASP.NET Core, Entity Framework Core and backend design with topic-wise questions and answer checkpoints.

8 topics · 40 interview questions

0%0 / 40 reviewed

Revision checklist saved in this browser. It is separate from your account’s solved-question count.

C# and the type system

0 / 5

Explain behavior with a small program, then discuss when each choice is useful.

Official topic reference ↗
  • How do value types and reference types differ?
    Answer checkpoints

    Compare copying a value with copying a reference. Explain that storage location depends on context; a value type is not always stored on the stack.

  • When would you use an interface, abstract class or composition?
    Answer checkpoints

    Discuss contracts, shared implementation and substitutability. Describe how composition can avoid a rigid inheritance hierarchy.

  • How do records, classes and structs express different models?
    Answer checkpoints

    Compare value equality, identity and copying. Explain why a record containing a mutable collection is not automatically deeply immutable.

  • What do nullable reference types actually guarantee?
    Answer checkpoints

    Explain compile-time flow analysis and annotations. Show why validation of external input is still required at runtime.

  • How do generics help with type safety and reuse?
    Answer checkpoints

    Compare a generic collection with an object-based collection, including constraints and boxing. Use variance only where the type relationship is valid.

Memory and resource ownership

0 / 5

Distinguish managed memory reclamation from deterministic release of external resources.

Official topic reference ↗
  • What does the garbage collector reclaim?
    Answer checkpoints

    Discuss reachability and generations. Explain that retaining references can keep unnecessary objects alive even in a managed runtime.

  • Why implement IDisposable and use using?
    Answer checkpoints

    Describe deterministic cleanup of owned resources, including exception paths. Do not rely on garbage collection to close a file or connection promptly.

  • What is boxing and when might it matter?
    Answer checkpoints

    Show a value converted to object or an interface and discuss allocation and copying. Measure before optimizing away clear code.

  • How can events or caches cause memory retention?
    Answer checkpoints

    Trace the reference chain from a long-lived publisher or cache to a subscriber. Explain unsubscribe, eviction and ownership policies.

  • How would you investigate a suspected memory leak?
    Answer checkpoints

    Compare allocations, live objects and working set over time. Use a reproducible workload and inspect heap roots before choosing a fix.

Collections and LINQ

0 / 5

Choose data structures by access pattern and explain when a query executes.

Official topic reference ↗
  • When should you choose List, Dictionary or HashSet?
    Answer checkpoints

    Compare ordered traversal, key lookup and membership tests. Include equality comparers and the memory cost of hashing.

  • What is deferred execution in LINQ?
    Answer checkpoints

    Show how enumeration can observe changed data or repeat expensive work. Explain when materializing with ToList is useful.

  • How do IEnumerable and IQueryable differ?
    Answer checkpoints

    Distinguish in-process enumeration from provider-translated expressions. Discuss where filtering occurs and how unsupported operations are handled.

  • How do you avoid multiple enumeration?
    Answer checkpoints

    Identify a query enumerated for Count and then for results. Choose streaming, materialization or a different query based on cost and memory.

  • What makes an equality comparer correct?
    Answer checkpoints

    Explain the equality contract and consistent hash codes. Discuss mutable keys and why a changed hash can break lookup expectations.

Async and concurrency

0 / 5

Separate waiting for I/O from executing CPU work in parallel.

Official topic reference ↗
  • What does async/await do during an I/O operation?
    Answer checkpoints

    Explain continuations and a task representing completion. An async method does not imply a new dedicated thread.

  • When would you use Task.Run?
    Answer checkpoints

    Discuss CPU-bound work and why wrapping naturally asynchronous I/O can waste thread-pool capacity on a server.

  • How should cancellation propagate?
    Answer checkpoints

    Pass CancellationToken through call boundaries. Explain cooperative cancellation, cleanup and how cancellation differs from a failure.

  • Why are Result and Wait risky in async code?
    Answer checkpoints

    Discuss blocking, thread starvation and synchronization-context deadlocks where applicable. Prefer awaiting through the call chain.

  • How do you bound concurrent work?
    Answer checkpoints

    Compare a semaphore, a bounded channel and a worker pool. Include backpressure, cancellation and error handling rather than launching unlimited tasks.

ASP.NET Core request handling

0 / 5

Walk through a request from middleware to endpoint and back.

Official topic reference ↗
  • Why does middleware order matter?
    Answer checkpoints

    Describe short-circuiting and the request/response sequence. Explain exception handling, authentication and authorization placement.

  • How do singleton, scoped and transient lifetimes differ?
    Answer checkpoints

    Explain ownership and scope boundaries. Discuss why a singleton must not capture a request-scoped dependency.

  • How do authentication and authorization differ?
    Answer checkpoints

    Separate establishing identity from permission checks. Cover policies and why hiding a UI control does not secure an endpoint.

  • How do you design validation and API error responses?
    Answer checkpoints

    Validate request boundaries, return appropriate status codes and avoid leaking internal exception details. Keep the response format consistent.

  • How should configuration and secrets be managed?
    Answer checkpoints

    Separate environment configuration from credentials. Describe typed options, startup validation and a secret store or managed identity.

Entity Framework Core and SQL

0 / 5

Inspect the SQL and access pattern before reaching for a framework-specific optimization.

Official topic reference ↗
  • What causes an N+1 query problem?
    Answer checkpoints

    Explain repeated related-data queries. Compare projections, eager loading and split queries with their transfer and consistency tradeoffs.

  • When is AsNoTracking useful?
    Answer checkpoints

    Use it for read-only entity queries when change tracking is unnecessary. Explain the implications for updates and identity resolution.

  • How would you handle concurrent updates?
    Answer checkpoints

    Describe an optimistic concurrency token, detecting a conflict and choosing a retry or user-resolution policy.

  • What belongs inside a transaction?
    Answer checkpoints

    Define the invariant across writes and explain isolation and locking. Do not assume a database transaction makes external network effects atomic.

  • How do you deploy schema changes safely?
    Answer checkpoints

    Prefer backward-compatible expansion, data migration and later cleanup. Consider old application instances, rollback limits and migration ownership.

Caching, APIs and security

0 / 5

Connect each mechanism to a concrete failure or threat model.

Official topic reference ↗
  • How do you choose between local and distributed caching?
    Answer checkpoints

    Compare latency, shared consistency, process lifetime and eviction. Avoid caching private responses under keys shared by different users.

  • How do you prevent a cache stampede?
    Answer checkpoints

    Discuss coalescing concurrent loads, bounded stale data and jittered expiry. Explain how refresh failures affect availability.

  • What makes a retry safe?
    Answer checkpoints

    Distinguish transient failure from permanent rejection. Combine bounded retries and backoff with idempotency for operations that may already have succeeded.

  • How do you protect cookie-authenticated write endpoints?
    Answer checkpoints

    Explain CSRF defenses, cookie attributes and authorization checks. Discuss CORS separately from authentication and CSRF protection.

  • How would you investigate a slow API endpoint?
    Answer checkpoints

    Measure request timings, database work, external calls and allocations. Use traces to find the bottleneck before increasing infrastructure.

Practical design exercises

0 / 5

Practice explaining constraints, tradeoffs and validation, not only writing a class.

Official topic reference ↗
  • Design a background job that can retry safely.
    Answer checkpoints

    Define durable state, deduplication and the boundary of each transaction. Explain cancellation, crash recovery and a dead-letter policy.

  • Design a paginated and searchable endpoint.
    Answer checkpoints

    Choose a stable sort, validate limits and compare offset with cursor pagination. Include indexes and access control.

  • Implement a service with a replaceable external dependency.
    Answer checkpoints

    Use a narrow interface, constructor injection and explicit failure handling. Describe meaningful tests at the boundary.

  • Explain how you would diagnose thread-pool starvation.
    Answer checkpoints

    Look for blocking calls, queue growth and latency under load. Distinguish starvation from CPU saturation or a slow database.

  • Plan a deployment with minimal user disruption.
    Answer checkpoints

    Cover readiness checks, compatible schema changes, staged traffic and rollback. Define the observations that would trigger a rollback.