📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š Interview question

What is software architecture? Explain the difference between N-tier (physical) and layered (logical) architecture, and walk me through the classic three-layer .NET application.

Defines software architecture, separates physical tiers from logical layers, and explains the presentation, business logic and data access layers of a classic three-layer .NET application.

Beginner Theory Beginner architecture aspnet-core fundamentals layered-architecture n-tier three-layer

🎯 Key points

  • Architecture = the significant decisions that are expensive to change (structure, boundaries, dependencies, quality attributes)
  • Layer = logical grouping by concern for modularity, testability and easier maintenance; tier = physical process or machine boundary
  • Three layers: presentation, business logic (domain/services), data access
  • Several layers can run in one tier (one ASP.NET Core process); three-tier = browser, web server, SQL Server
  • Every tier boundary adds latency, serialisation, operating cost and new failure modes — split only on a measured need
  • Tiers are also security boundaries: database in a private subnet, least-privilege identities between tiers
  • Dependencies point downwards: presentation → business → data
  • Architecture is driven by quality attributes such as modifiability, security, scalability and cost, not by fashion

⏱ 30-second answer

Software architecture is the set of significant decisions about a system's structure β€” its parts, their responsibilities, how they depend on each other β€” that are expensive to change later.

  • A layer is a logical grouping of code (presentation, business logic, data access), usually a folder or project.
  • A tier is a physical deployment boundary: a separate process or machine, such as the browser, the ASP.NET Core server and SQL Server.
  • The classic three-layer app has presentation (controllers, Razor pages) calling business logic (services) calling data access (EF Core), all usually deployed as one tier talking to a database tier.

The trade-off: more tiers give independent scaling and isolation, but every tier boundary costs a network hop, serialisation and a new way to fail.

πŸ—£ Full answer (senior)

How I would answer this in an interview

"Software architecture is the set of decisions about a system that are hard to reverse: how it is split into parts, which part is responsible for what, which way the dependencies point, and which quality attributes β€” modifiability, performance, availability, cost β€” the structure is optimised for. Code inside a method can be rewritten in an afternoon; the shape of the system can't, so that's what we call architecture.

Two words get mixed up constantly: layers and tiers. A layer is logical β€” it's how I organise code, for example a Web project, a Business project and a Data project. A tier is physical β€” it's where code runs: the browser, the ASP.NET Core process in an Azure App Service, and Azure SQL. A classic .NET app has three layers deployed in one web tier plus a database tier. Its presentation layer β€” controllers or Razor Pages β€” handles HTTP and calls the business layer; the business layer holds the rules and calls the data access layer; the data access layer uses EF Core or Dapper to talk to SQL Server. Dependencies only point downwards.

The mistake I see is treating layers as tiers: putting the business layer behind its own internal HTTP API 'for scalability', which doubles latency and adds a failure mode without a real scaling need. I keep layers in one process until a measured requirement forces a physical split. Layers are about organising change; tiers are about deployment, scale and security β€” choose each for its own reason."


Layers vs tiers

Layer (logical) Tier (physical)
What it is A group of code with one responsibility A process, container or machine
In .NET A folder or project (Shop.Web, Shop.Business, Shop.Data) An App Service, a container, Azure SQL
Crossing it costs A method call (nanoseconds) A network call (β‰ˆ0.5–5 ms in one Azure region), serialisation, retries
Main reason to add one Separate concerns, make change easier Scale, isolate, secure or deploy independently

The classic three-layer application

Layer Responsibility Typical .NET pieces
Presentation HTTP, input validation, view models, status codes Controllers, Minimal API endpoints, Razor Pages
Business logic Rules, calculations, workflows Service classes, domain classes
Data access Queries and persistence DbContext, repositories, Dapper queries

Common tier layouts

Layout Example When it fits
2-tier Desktop WinForms app talking straight to SQL Server Internal tools, legacy
3-tier Browser β†’ ASP.NET Core β†’ Azure SQL Most web apps
N-tier Browser β†’ API gateway β†’ several services β†’ databases and caches Large scale or strict isolation needs

When to use / when not

Use more layers when… Avoid extra tiers when…
Rules are shared by several entry points (API, background job) There's no measured scaling or security need
Several people work on different concerns One team deploys everything together
You want to test business rules without HTTP or SQL Latency budgets are tight (every hop adds milliseconds)

Production example

An internal claims portal had its business layer deployed as a separate internal Web API "so it could scale". Each page made 6–10 calls across that boundary, adding about 40 ms per page. Folding the two tiers back into one App Service (keeping the three logical layers) cut p95 page time from 310 ms to 190 ms and removed a whole class of timeout errors.

πŸ” What the interviewer is checking

Checks that the candidate can define architecture in terms of hard-to-change decisions and precisely distinguish logical layers from physical tiers.

Green flags

  • Defines architecture through cost of change and quality attributes
  • Separates layer (code) from tier (deployment) without prompting
  • Names the three layers and what lives in each, with .NET examples
  • Mentions the network cost of extra tiers

Red flags

  • "Architecture is the folder structure" or "it's what the architect draws"
  • Uses layer and tier interchangeably
  • Believes more tiers automatically means more scalable

πŸ“š Learn in depth

1. What makes a decision "architectural"

A useful test: how expensive is it to change? Renaming a variable is cheap. Moving from one database to two, or from one deployable to ten, touches every team and every pipeline. Architecture covers:

  • Structure: the parts (modules, layers, services) and their responsibilities.
  • Dependencies: which part may know about which.
  • Quality attributes: the "-ilities" the structure is optimised for β€” modifiability, performance, availability, security, cost.
  • Constraints: team size, budget, regulations (for example the Privacy Act 1988 and data residency in Azure Australia East).

2. Layers: organising code

+---------------------------+
|  Presentation             |  controllers, endpoints, views
+---------------------------+
             |
             v
+---------------------------+
|  Business logic           |  services, domain rules
+---------------------------+
             |
             v
+---------------------------+
|  Data access              |  DbContext, queries
+---------------------------+
             |
             v
        [ SQL Server ]

Each layer only calls the layer below. In .NET you usually enforce this with project references: Shop.Web references Shop.Business, which references Shop.Data. The compiler then refuses an upward reference, because it would create a circular project reference.

3. Tiers: deploying code

[ Browser ] --HTTPS--> [ App Service: Web + Business + Data layers ] --TDS--> [ Azure SQL ]
   tier 1                         tier 2                                       tier 3

All three layers live in tier 2 here. Crossing a tier means:

  1. Serialising the data (JSON over HTTP, or TDS for SQL Server).
  2. A network round trip β€” roughly 0.5–2 ms inside one Azure region, far more across regions.
  3. A new failure mode: timeouts, DNS, TLS, partial outages.

That is why tier boundaries are chosen for scale, isolation or security (for example, keeping the database in a private subnet), not for code organisation.

4. How a request flows

For GET /orders/42 in a three-layer ASP.NET Core app:

  1. Kestrel accepts the request; routing picks OrdersController.Get.
  2. The controller calls IOrderService.GetAsync(42).
  3. The service applies rules (may this user see this order?) and calls the data layer.
  4. The data layer runs an EF Core query against SQL Server.
  5. The result is mapped to a DTO and serialised to JSON.

Steps 2–4 are in-process method calls; only step 4's database call crosses a tier.

5. Where the classic model runs out

The three-layer model puts the database at the bottom, so business logic depends on data access. That works for CRUD apps but makes rules hard to test without a database, and tends to produce "database-centric" designs. Clean, Onion and Hexagonal architectures invert that dependency β€” the next questions in this topic.

Try it yourself

  1. Create three projects (dotnet new webapi, two classlibs), add references Web β†’ Business β†’ Data, then try adding a Data β†’ Web reference and read the error.
  2. Move the business layer behind its own Minimal API and measure the extra latency per call with Stopwatch or Application Insights dependency tracking.
  3. Draw your current work project as layers and as tiers on one page; note where the two pictures differ.
  4. List three decisions in a project you know that would be expensive to change; those are its architecture.

πŸ’» Code

A minimal three-layer slice: each layer is a separate project, and dependencies only point downwards.

// Shop.Data/OrderRepository.cs β€” data access layer
namespace Shop.Data;

public sealed record OrderRow(int Id, string CustomerEmail, decimal Total);

public interface IOrderRepository
{
    Task<OrderRow?> FindAsync(int id, CancellationToken ct);
}

public sealed class OrderRepository(ShopDbContext db) : IOrderRepository
{
    public Task<OrderRow?> FindAsync(int id, CancellationToken ct) =>
        db.Orders
          .Where(o => o.Id == id)
          .Select(o => new OrderRow(o.Id, o.CustomerEmail, o.Total))
          .SingleOrDefaultAsync(ct);
}
// Shop.Business/OrderService.cs β€” business logic layer (references Shop.Data)
namespace Shop.Business;

using Shop.Data;

public sealed record OrderSummary(int Id, decimal Total, bool QualifiesForFreeShipping);

public sealed class OrderService(IOrderRepository orders)
{
    private const decimal FreeShippingThreshold = 100m; // a business rule lives here, not in the controller

    public async Task<OrderSummary?> GetAsync(int id, CancellationToken ct)
    {
        var row = await orders.FindAsync(id, ct);
        return row is null
            ? null
            : new OrderSummary(row.Id, row.Total, row.Total >= FreeShippingThreshold);
    }
}
// Shop.Web/Program.cs β€” presentation layer (references Shop.Business and, for registration only, Shop.Data)
using Microsoft.EntityFrameworkCore;
using Shop.Business;
using Shop.Data;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<ShopDbContext>(o =>
    o.UseSqlServer(builder.Configuration.GetConnectionString("Shop")));
builder.Services.AddScoped<IOrderRepository, OrderRepository>();
builder.Services.AddScoped<OrderService>();

var app = builder.Build();

// The endpoint only translates HTTP to a service call and back.
app.MapGet("/orders/{id:int}", async (int id, OrderService service, CancellationToken ct) =>
    await service.GetAsync(id, ct) is { } order ? Results.Ok(order) : Results.NotFound());

app.Run();

⚠ Common mistakes

  • Mistake: Using "layer" and "tier" as synonyms. Why it is wrong: one is a code-organisation choice, the other a deployment choice with latency and failure costs. Instead: say "three layers in one tier" or "three tiers" precisely.
  • Mistake: Splitting layers into separate services "for scalability" with no measured need. Why it is wrong: every hop adds milliseconds, serialisation and timeouts. Instead: scale the single web tier horizontally first; split only when a part has a different scaling or security profile.
  • Mistake: Putting business rules in controllers or Razor pages. Why it is wrong: rules get duplicated across endpoints and background jobs and can't be tested without HTTP. Instead: keep controllers thin and put rules in the business layer.
  • Mistake: Letting the presentation layer query DbContext directly "just this once". Why it is wrong: it bypasses the rules and couples the UI to the schema. Instead: go through the business layer, or make the exception explicit and documented.
  • Mistake: Thinking architecture means drawing boxes once at the start. Why it is wrong: the significant decisions keep being made as the system grows. Instead: revisit them as requirements change and record them (for example in ADRs).
  • Mistake: Choosing an architecture because a big company uses it. Why it is wrong: their constraints (hundreds of teams, global scale) aren't yours. Instead: start from your quality attributes and team size.

πŸ› Senior insight: trade-offs

A senior answer separates logical from physical decisions and justifies each with a quality attribute. Logical layering is cheap and almost always worth it: it gives modularity, lets you test rules without HTTP or SQL, and keeps change local. Physical tiers are expensive and must be earned by a measured need β€” Application Insights showing one part needs different scaling, a security boundary, or a different release cadence β€” not by the assumption that "more tiers scale better". Most systems I see that are slow or fragile have too many tiers, not too few.

Every extra tier costs in three currencies: latency (0.5–2 ms per in-region hop, multiplied by chatty calls), money and operations (another App Service plan, pipeline, set of alerts and certificates), and complexity (timeouts, retries, partial failure, versioned contracts). The one place tiers clearly pay off early is security: keeping Azure SQL on a private endpoint reachable only from the web tier's managed identity, which also supports ACSC Essential Eight expectations around restricting access.

Option When it fits Cost When not to
Layers in one process Almost every web app and API Discipline to keep dependencies pointing one way Never really "not" β€” even a script benefits from separation
Extra physical tier Different scaling profile, security isolation, separate team Network latency, serialisation, distributed failures, more pipelines and hosting cost When one team deploys it all together and load fits one tier

Measure before splitting: dependency timings, CPU profiles and cost per environment tell you whether one part actually needs to stand alone.

πŸ”— Follow-ups the interviewer may ask

  1. When: Candidate says they would split the business layer into its own service for scalability. Why: Checks whether they can spot and reverse over-engineering rather than adding tiers by default.
    How to answer

    Over-engineering is complexity that today's requirements do not justify. I detect it through symptoms with numbers behind them: a one-field change touching many files, interfaces with one implementation, configuration options nobody sets, patterns like CQRS or event sourcing without the problems they solve, and microservices that always deploy together. I reverse it incrementally rather than with a rewrite: inline single-use abstractions, merge layers that only pass data through, consolidate services that share a release cycle, and delete unused options, each step behind tests. I also address why it happened, because otherwise it grows back.

  2. When: Candidate says architecture is decided up front and then fixed. Why: Checks whether they understand that architecture must evolve and how to make change safe.
    How to answer

    Evolutionary architecture (Ford, Parsons and Kua) is architecture designed to support guided, incremental change, rather than a fixed upfront design. The key tool is fitness functions: automated checks that protect the characteristics you care about, such as dependency rules (architecture tests), latency budgets, or startup time, run in CI or production. Around that, I keep boundaries modular (often a modular monolith first), make decisions reversible where possible and defer irreversible ones to the last responsible moment, record decisions in ADRs, and rely on continuous delivery, feature flags and observability so each change is small and safe.

  3. When: Candidate says dependencies point downwards from presentation to data. Why: Checks whether they know the layering rules and the problems layering causes as a system grows.
    How to answer

    The core rule: a layer may only depend on layers below it β€” presentation β†’ business β†’ data β€” never upwards and never in a cycle.

    • Strict layering allows calls only to the layer directly below; relaxed layering lets a layer skip down (for example a controller reading data directly for a simple query).
    • Database-centric design: because data access sits at the bottom, the schema is designed first and the business layer is shaped around tables, so rules leak into SQL and service classes.
    • Leaky layers: lower-layer types escape upwards β€” IQueryable, EF entities, SqlException in controllers.
    • Sinkhole layers: requests pass through layers that only map and forward.

    The trade-off: layering is simple and familiar, but every feature cuts across all layers and the domain ends up depending on the database.

More in Application Architectures

Last updated 23 Nov 2026.

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me