Dot NET Architecture Interview Q&A

 

🔹 Basic Architecture

Q1: What is N-tier architecture?
👉 Separation of application into Presentation, Business Logic, and Data layers. Improves maintainability and scalability.

Q2: Difference between Layered and Onion Architecture?
👉 Layered allows top-to-bottom dependency. Onion forces inner layers (business/domain) to never depend on outer ones (DB/UI).

Q3: What is the Repository Pattern?
👉 Abstracts database calls so business logic doesn’t depend on EF Core/SQL directly. Example: IBookRepository.

Q4: What is Dependency Injection (DI)?
👉 A design pattern where dependencies are provided rather than created inside classes. Improves testability and flexibility.

Q5: What are SOLID Principles?
👉

  • S – Single Responsibility

  • O – Open/Closed

  • L – Liskov Substitution

  • I – Interface Segregation

  • D – Dependency Inversion


🔹 Onion / Clean Architecture

Q6: What is Onion Architecture?
👉 An architecture where business rules (Domain) are at the center, surrounded by Application, then Infrastructure/UI. Dependencies always point inward.

Q7: Why is Onion better than Layered?
👉 Business logic doesn’t depend on infrastructure. Easy to swap DB, UI, or external tools.

Q8: Example of Onion in .NET?
👉

  • Core: Entities (Customer, Order)

  • Application: Services (OrderService)

  • Infrastructure: EF Core, SQL, Logging

  • UI/API: ASP.NET Core Web API

Q9: What is Dependency Inversion in Onion?
👉 Outer layers depend on abstractions (interfaces) in inner layers, not on concrete implementations.


🔹 Microservices & Distributed

Q10: What are Microservices?
👉 Small, independently deployable services that communicate via APIs/events.

Q11: How do Microservices communicate?
👉 REST API, gRPC, Messaging (RabbitMQ, Kafka).

Q12: What is API Gateway?
👉 A single entry point for all microservices. Handles routing, auth, logging.

Q13: What is CQRS?
👉 Separating commands (write) from queries (read). Example: CreateOrderCommand vs GetOrderQuery.

Q14: How do you handle Authentication in Microservices?
👉 Using JWT, OAuth2, or Identity Server.


🔹 Cloud & Scalability

Q15: How do you scale a .NET app?
👉 Vertical (increase resources) or Horizontal (multiple servers with load balancer).

Q16: What is Caching?
👉 Store frequent data in memory (In-Memory Cache, Redis) to reduce DB calls.

Q17: Difference between Containers and VMs?
👉 Containers are lightweight and share OS kernel; VMs are heavier and have full OS.

Q18: What is Serverless in .NET?
👉 Running code without managing servers, e.g., Azure Functions, AWS Lambda.


🔹 Practical / Scenario

Q19: If the DB changes from SQL to MongoDB in Onion Architecture, what changes?
👉 Only Infrastructure Layer; Core/Application remain unchanged.

Q20: How would you secure an ASP.NET Core Web API?
👉 Using JWT tokens, Role-based access, HTTPS, API Gateway.

Q21: How to implement Logging across .NET project?
👉 Use middleware or logging frameworks (Serilog, NLog). Configure centralized logging.

Q22: If app is slow, how do you troubleshoot?
👉 Check DB performance, API response, caching, async calls, profiling tools.

Q23: How to handle cross-cutting concerns (logging, caching, security)?
👉 Use Middleware, Dependency Injection, or AOP (Aspect-Oriented Programming).


Pro Tip for Interviews:
Always link answers with real projects (like your Honda Motors contract project).
Example:
"We used Onion Architecture in my Honda  Motors project. The core layer had contracts and dealers. The infrastructure handled SQL. Later, we switched to Redis caching without changing business logic."



🔹 What is Onion Architecture?

Onion Architecture is a way of designing software so that:

  • Code is organized in layers (like an onion has rings).

  • Core logic (business rules) is kept safe in the center.

  • Outer layers depend on inner layers, but inner layers never depend on outer ones.

  • This makes the project flexible, testable, and easy to maintain.


🔹 Layers of Onion Architecture

Think of an onion cut in half 🧅 – it has circles inside circles:

  1. Core (Center Layer – Domain Model)

    • Business rules, entities, core logic.

    • Example: In a Bank App, classes like Customer, Account, Transaction.

  2. Domain Services

    • Business logic that uses core entities.

    • Example: Transfer money between accounts.

  3. Application Services (Use Cases)

    • Defines how the system is used.

    • Example: "Create New Account", "Deposit Money".

  4. Infrastructure Layer (Outer Layer)

    • Databases, APIs, UI, logging, email, etc.

    • Example: SQL Server, EF Core, REST API.


🔹 Rule of Onion Architecture

👉 Inner layers do not depend on outer layers.
Only outer layers depend on inner layers.

This protects your business logic from being affected by changes in UI, database, or third-party tools.


🔹 Simple Example

Suppose we are making a Library Management System 📚

  • Core (Entities): Book, Member

  • Domain Service: BorrowBookService (rules like "A member can borrow only 5 books")

  • Application Service: LibraryApp (operations like Add Member, Issue Book)

  • Infrastructure: SQL Database, ASP.NET MVC frontend, Email service

Now if tomorrow the client says “Instead of SQL, use MongoDB”,
👉 You don’t touch your core logic — only change the infrastructure layer.

Comments

Popular posts from this blog

.NET Core Interview Questions and Answers for 10+ Years Experienced Professionals

What are SOLID Principles?

.NET Core Senior Interview Q&A