Volume 12 · Chapter 8 — Principal Software Architect Interview Mastery & Enterprise System Design Handbook

.NET Enterprise Design Questions

Goutham Mayaluri 7 min read .NETC#

8.1 Introduction

For a .NET principal architect, interviews combine system design with .NET-specific depth: Clean Architecture, DDD, CQRS, microservices, API design, performance, and dependency injection - the material of Volumes 6, 7, 9, and 10, now framed as interview questions. The interviewer wants to see that you can apply these patterns judiciously, knowing when each earns its cost, rather than reciting them. This chapter distills the most-asked .NET design questions.

8.2 Clean Architecture and DDD

Clean Architecture keeps business logic independent of frameworks via the Dependency Rule (dependencies point inward), making the core testable and the technology replaceable. DDD models the business - bounded contexts define boundaries, aggregates define consistency boundaries, and domain events decouple reactions. The interview signal is knowing these earn their cost in complex domains and are overkill for simple CRUD.


// The Dependency Rule in project references: Domain depends on nothing.
// Bank.Domain            -> (no references)
// Bank.Application        -> Bank.Domain
// Bank.Infrastructure     -> Bank.Application, Bank.Domain   (implements ports)
// Bank.Api                -> Bank.Application, Bank.Infrastructure (composition root)

8.3 CQRS, Microservices, and APIs

CQRS separates command and query models where they diverge (not always two databases). Microservices buy team and scaling independence at the cost of distribution - cut boundaries by business capability, own data per service, and avoid the distributed monolith. API design centers on clear contracts, versioning, security, and resilience. Each is applied on evidence of need, and a strong candidate says so.

8.4 Performance and Dependency Injection

Performance questions reward the measure-first mindset (Volume 7): profile, find the real bottleneck (usually the database), reduce allocations on hot paths, and validate with benchmarks. DI questions test lifetimes (singleton/scoped/transient), the captive-dependency trap (scoped-in-singleton), and why constructor injection beats the service-locator anti-pattern.

Principal .NET Architect Interview Question

How do you design a large enterprise .NET application?

I structure it with Clean Architecture so the business logic is independent of frameworks and infrastructure - the Domain project references nothing, Application depends on Domain, and Infrastructure and the API depend inward and implement the ports the inner layers define, enforced by project references and architecture tests. This keeps the valuable business rules testable with plain objects and lets the technology (EF Core, ASP.NET, the messaging stack) be replaced over the app’s long life without touching the core. I use DDD where the domain is genuinely complex: bounded contexts drawn from business capabilities define the boundaries (and later the module or service split), aggregates enforce invariants atomically within consistency boundaries, and domain events decouple reactions - while keeping generic or simple subdomains as plain CRUD, because full DDD is overkill there. I apply CQRS where reads and writes diverge, and I decide the service topology on evidence: I often start as a modular monolith with clean internal boundaries and database schemas per module, and extract microservices only when a concrete pressure (independent scaling or release cadence) justifies the distribution cost, cutting boundaries by business capability with data owned per service to avoid a distributed monolith. Cross-cutting concerns go through DI (constructor injection, correct lifetimes, avoiding captive dependencies) and pipeline behaviors/middleware rather than scattered code, and APIs are designed with clear contracts, versioning, security, and resilience. I build in performance awareness (measure-first, low-allocation hot paths), comprehensive automated testing, observability, and CI/CD from the start. The judgment I’d stress in an interview is applying each pattern where it earns its cost and keeping things as simple as the domain allows - Clean Architecture and DDD for the complex core, simpler approaches elsewhere - because over-engineering a straightforward system with heavy patterns is as much an architectural failure as under-structuring a complex one.

Principal .NET Architect Interview Question

Do you always need the Repository pattern and CQRS in a .NET app? How do you decide?

No - and knowing when to skip them is part of the judgment being tested. On the Repository pattern: EF Core’sDbSetalready behaves like a repository andDbContextis already a unit of work, so a pass-through repository that only wraps them adds indirection without value and even hides useful EF features. I add a repository when I want to keep EF types out of the domain, centralize complex or reused query logic behind domain-meaningful methods, or make the write model easily testable and swappable - otherwise using EF directly in the application layer is a legitimate, simpler choice. On CQRS: it is worth it when reads and writes genuinely diverge - very different scaling needs, or read shapes so different from the write model that one model serves neither well, or a domain complex enough that separating command and query responsibilities clarifies the design - and it does not require two databases; many systems run “CQRS-lite” with split code paths over a single database, adding a separate read store only when read scaling demands it. For simple CRUD, a single model and straightforward data access are simpler and better, and imposing CQRS or a repository-per-entity there is ceremony that slows delivery without buying anything. So my decision rule for both is the same: apply the pattern only when a concrete force (testability, keeping EF out of the domain, divergent read/write needs, scaling) justifies its cost, and prefer the simplest approach that meets the requirement. In an interview, demonstrating that I’ll deliberately not use a fashionable pattern when it does not earn its place is a stronger signal of seniority than reflexively applying every pattern.

Principal .NET Architect Interview Question

Explain DI service lifetimes and the most common mistake with them.

The three lifetimes control how instances are created and shared. A Singleton is created once and shared for the application’s lifetime, so it must be thread-safe and is suited to stateless services, caches, and configuration. A Scoped instance lives for the duration of a scope - one per HTTP request in ASP.NET Core - which is whyDbContextis scoped, since it is not thread-safe and represents a unit of work per request. A Transient instance is created every time it is requested, suited to lightweight, stateless helpers. The most common and dangerous mistake is the captive dependency: injecting a shorter-lived service (typically Scoped) into a longer-lived one (a Singleton). The singleton captures that scoped instance and holds it for the whole application lifetime, so, for example, a per-requestDbContextbecomes effectively a shared singleton across all requests - causing threading errors, stale data, and hard-to-diagnose bugs becauseDbContextis not thread-safe and was never meant to outlive its request. The fix is not to capture the scoped service directly but to inject anIServiceScopeFactoryinto the singleton (or background service) and create a fresh scope per unit of work, resolving the scoped dependency from that scope. I also enable scope validation (ValidateScopes/ValidateOnBuild) so the container catches captive dependencies at startup rather than in production. In an interview I’d note that this trap is so common precisely because the code compiles and often works under light load, only failing under concurrency - which is why understanding lifetimes and validating them is important.

8.5 Banking Enterprise .NET Scenario

A bank’s .NET platform uses Clean Architecture to keep account and payment rules independent of EF Core and ASP.NET, DDD aggregates to enforce funds invariants, and CQRS to separate transaction processing from statement reads. Services are cut by business capability, own their data, and integrate via events; APIs are versioned, secured, and resilient; DI uses correct lifetimes with scope validation to prevent captive-dependency bugs; and performance is engineered with the measure-first mindset. Each pattern is present because the complexity of a banking domain justifies it - and simpler internal tools use simpler approaches.

Chapter Revision Notes

  • Clean Architecture (Dependency Rule) keeps business logic independent and testable.
  • DDD, CQRS, and microservices earn their cost in complex domains - apply them on evidence.
  • Skip the Repository pattern and CQRS where EF/CRUD suffices - knowing when not to is seniority.
  • Performance = measure first, reduce allocations, validate with benchmarks.
  • Master DI lifetimes and avoid the captive-dependency (scoped-in-singleton) trap.