1325 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.
Repository, Unit of Work, Service Layer, Domain and Application Services, DTO, Mapper, CQRS, Outbox, Inbox, Saga, Circuit Breaker, Retry and Bulkhead in .NET 10 services.
Repository pattern in .NET: intent (a collection-like abstraction over persistence for an aggregate root), repository vs DAO/table gateway, why a generic IRepository<T> over EF Core leaks IQueryable, breaks the unit of work with per-repository Save, encourages Update() on detached graphs and repositories for child entities, and what a narrow, aggregate-specific repository interface looks like with DI registration.
Architecture decision on wrapping EF Core in repositories: testing with mocks vs EF in-memory/SQLite vs Testcontainers SQL Server, aggregate repositories for the write side vs direct DbContext projections for reads, leaky IQueryable, EF Core 10 ExecuteUpdate/ExecuteDelete (non-expression setter lambda) bypassing the change tracker, multiple persistence stores, team skill and when the decision flips, recorded as an ADR.
Unit of Work in .NET: tracking changes and committing them as one transaction, EF Core's change tracker and SaveChangesAsync as the built-in UoW (implicit transaction, identity map), explicit transactions with BeginTransactionAsync for multiple SaveChanges or ExecuteUpdate/ExecuteDelete/raw SQL, wrapping them in CreateExecutionStrategy().ExecuteAsync when EnableRetryOnFailure is on, TransactionScope caveats, and sharing one scoped DbContext across repositories.
Service layer (Fowler) vs application service vs domain service (Evans/DDD): responsibilities (orchestration, transactions, authorisation and mapping vs stateless domain logic spanning aggregates), what belongs in entities, how 'god' service layers create an anaemic domain model, thin controllers/minimal API endpoints, and a funds-transfer example in .NET 10.
DTO pattern: Fowler's origin (batching data across a process boundary), a data-only contract with no behaviour, why exposing EF Core entities in APIs is risky (over-posting/mass assignment, leaking sensitive fields under the Privacy Act, schema changes breaking clients, JSON object cycles), separate request and response DTOs, records as immutable DTOs, and when not to add DTOs (inside one layer).
Mapper pattern in .NET 10: hand-written mapping (extension methods, constructors), AutoMapper (reflection/expression-compiled, ProjectTo, AssertConfigurationIsValid; dual RPL-1.5/commercial from v15, July 2025; free Community edition under US$5M revenue; 14.x last MIT with an unpatched advisory), Mapperly (Apache 2.0 source generator, build-time diagnostics, IQueryable projections), mapping after loading vs Select projection in EF Core (over-fetching, tracking, lazy-loading N+1), and testing mappings.
CQRS (Command Query Responsibility Segregation): CQS (Meyer) vs CQRS (Young), separate write model (aggregates, invariants) and read model (projections/DTOs), levels from handlers on one database to a synchronous denormalised table to a separate read store fed by events, eventual consistency and read-your-writes in the UI, relationship to MediatR and event sourcing, and when CQRS is overkill.
Transactional outbox: the dual-write problem (DB commit and broker publish can't be atomic; distributed transactions aren't an option with Azure SQL and Service Bus), writing an OutboxMessages row in the same EF Core SaveChanges/transaction, a relay BackgroundService polling with UPDLOCK/READPAST, publishing with MessageId = outbox id, marking ProcessedAt, at-least-once delivery and consumer idempotency, ordering, CDC as an alternative, library options (MassTransit v9 commercial, NServiceBus, Wolverine, CAP), and operational costs.
Inbox / idempotent consumer in .NET 10: why at-least-once delivery (outbox resends, peek-lock redelivery, lock expiry) causes duplicates, an InboxMessages table with a composite primary key (MessageId, Consumer), inserting the inbox row first and applying the business change in the same EF Core transaction inside an execution strategy, treating SQL errors 2627/2601 as 'already processed', how the key lock serialises concurrent duplicates, completing vs abandoning Service Bus messages, retention-based cleanup with ExecuteDeleteAsync, natural idempotency as an alternative, and tests.
Saga pattern for a distributed order-payment flow: why there's no distributed transaction, orchestration (central state machine) vs choreography (services react to events), compensating actions as semantic undo (release stock, refund) rather than rollback, pivot transactions, MassTransit state machine with EF Core saga repository and optimistic concurrency (v9 commercial, v8 Apache 2.0), scheduled timeouts, idempotent steps, late replies after cancellation, observability, and alternatives (NServiceBus, Wolverine, Durable Functions).
Retry pattern: transient vs permanent faults (5xx, 408, 429 with Retry-After, timeouts vs 400/401/404/409), exponential backoff with jitter (Polly's decorrelated jitter), retrying only idempotent operations (DisableForUnsafeHttpMethods, idempotency keys), retry storms and multiplicative amplification across layers, retry budgets, Polly v8 ResiliencePipeline and RetryStrategyOptions, HttpRetryStrategyOptions defaults in AddStandardResilienceHandler, EF Core EnableRetryOnFailure, and telemetry.
Circuit breaker pattern: closed/open/half-open state machine, Polly v8 CircuitBreakerStrategyOptions (FailureRatio 0.1, MinimumThroughput 100, SamplingDuration 30 s, BreakDuration 5 s, ShouldHandle, OnOpened/OnHalfOpened), BrokenCircuitException, ordering in AddStandardResilienceHandler (rate limiter, total timeout, retry, breaker, attempt timeout) and its validation rules, per-instance vs per-authority breakers (SelectPipelineByAuthority), low-traffic pitfalls, fallbacks and monitoring.
Bulkhead pattern: isolating failures so one slow dependency can't consume shared resources (threads, sockets, DB connections, memory), outbound bulkheads with Polly v8 concurrency limiters (Polly.RateLimiting, RateLimiterRejectedException) and the standard resilience handler's limiter (1,000 permits, queue 0), separate named HttpClients and MaxConnectionsPerServer, inbound bulkheads with ASP.NET Core AddRateLimiter concurrency policies, separate queues/consumers and MaxConcurrentCalls, bulkhead vs rate limiting, sizing with Little's Law, and rejection handling.
Real-world cascading failure: diagnosing with Application Insights dependency telemetry, dotnet-counters (thread pool, SqlClient pool, HTTP connections) and dotnet-dump; root causes (HttpClient 100 s default timeout, retries multiplying load, DB connections held across the external call, health checks including the dependency); mitigation with a feature flag; the real fix with attempt and total timeouts, a single jittered retry, a tuned circuit breaker, a concurrency-limit bulkhead, a flat-rate fallback, moving the call out of the transaction, and chaos testing.
Real-world messaging incident: finding lost events (publish after SaveChanges, fire-and-forget Task.Run, swallowed ServiceBusException) and duplicates (publisher retries with a new MessageId each time, peek-lock redelivery after lock expiry) with reconciliation queries, Application Insights correlation and Service Bus metrics; fixing with domain events written to an OutboxMessages table by a SaveChanges interceptor, a relay with UPDLOCK/READPAST and stable MessageId, duplicate detection, an InboxMessages table keyed on (MessageId, Consumer); rollout order (inbox first), backfill and refunds, and ongoing reconciliation.
Staff-level pattern selection: starting from forces (domain complexity, invariants, consistency, integration, scale, team) rather than a template, a minimal baseline every service gets (DbContext, DTOs, validation, HttpClient resilience, observability), a CRUD admin service (vertical slices, DbContext in handlers, no repositories/CQRS/mediator) vs an insurance-claims domain (aggregates, repositories, domain services, light CQRS, outbox/inbox, saga for long-running claims), triggers for adding patterns, cost of each pattern, ADRs with reversal conditions, architecture fitness functions (NetArchTest), and periodic review.