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.
The GoF creational, structural and behavioural patterns and the enterprise patterns used in modern .NET 10 services, with the judgement to know when a pattern helps and when it is ceremony.
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.