.NET Core Senior Interview Q&A

 

🔹 1. .NET Core Fundamentals

Q1. What is the difference between .NET Framework, .NET Core, and .NET 5/6/7?
Answer:

  • .NET Framework → Windows-only, monolithic.

  • .NET Core → Cross-platform, modular, open-source.

  • .NET 5/6/7/8 → Unified platform (.NET Core + Mono).

  • Example: In my current project, we migrated from .NET Framework 4.7.2 to .NET 6 for cross-platform support and performance gains (reduced API response time by ~30%).



           

Windows-only

  • Means the .NET Framework can run only on Windows OS.

  • You cannot directly run .NET Framework apps on Linux or macOS.


Monolithic

  • Monolithic application = a single, large, tightly-coupled unit.

  • All layers (UI, business logic, data access) are bundled together and deployed as one package.

  • Even a small change (e.g., fixing a bug in UI) requires rebuilding and redeploying the entire application.

  • Scaling is harder → you must scale the whole app, not just the part that needs more resources.


Example:
Suppose you build a Banking Application in .NET Framework:

  • The UI (ASP.NET WebForms), business logic, and database access are all in one big project.

  • If you need to change the “Loan Calculator” feature, you must redeploy the entire app, even though other modules (like Account or Payment) haven’t changed.


👉 By contrast, .NET Core / .NET 6+ allows:

  • Cross-platform (Windows, Linux, macOS).

  • Modular, microservices-friendly apps → each service can be built, deployed, and scaled independently.



        🔹 Real Scenario Examples of Modular

1. Using Only Needed Packages in .NET Core

  • In .NET Framework, you always got the whole framework (big and heavy, ~200MB runtime).

  • In .NET Core, you pull in only what you need via NuGet packages.

👉 Example:
If you’re building a REST API:

  • You might use only Microsoft.AspNetCore.Mvc (controllers, routing) and Microsoft.Extensions.Logging.

  • You don’t load unnecessary UI libraries like Razor Pages or Blazor.

✅ Benefit → Your app is lighter, faster, and deploys quicker.


2. Microservices (Independent Modules)

  • A Banking System might have services:

    • CustomerService (manages users)

    • AccountService (manages accounts)

    • TransactionService (handles transfers)

Each service is a modular .NET Core app, deployed separately.
If you need to update TransactionService, you don’t touch other modules.

✅ Benefit → Faster deployments, independent scaling (e.g., scale only transactions during peak).


3. Middleware in ASP.NET Core

  • Middleware components are modular building blocks in the request pipeline.

  • Example: You can plug in or remove components like Authentication, Exception Handling, CORS, Response Compression.

👉 In one project, we added a custom request logging middleware only for APIs exposed to partners, not for internal APIs.

✅ Benefit → Flexibility to compose the pipeline only with what you need.


4. Modular Monolith (Before going Microservices)

  • In some projects, instead of one big project, you can split into modules inside the same app:

    • Orders module

    • Inventory module

    • Payments module

Each module has its own controllers, services, and repositories.
They communicate internally but are loosely coupled.

✅ Benefit → Easier to maintain, and later you can extract modules into separate microservices if needed.


5. Third-party Integrations

  • Example: In an E-commerce app, you might need Payment Gateway integration (Stripe/PayPal).

  • You add that as a separate module/library.

  • If the business switches from PayPal to Razorpay, you just swap out the payment module, without affecting cart or order modules.

✅ Benefit → Pluggable design, easy replacement.


👉 Simple Interview Answer
"Modular means I can pick and use only what I need. For example, in one .NET Core API project, we used only MVC controllers and logging libraries without Razor Pages or SignalR, making the app lightweight. In another project, we designed modules like Payments, Orders, and Inventory separately so each could be updated without touching the others."


Q2. How does Dependency Injection (DI) work in .NET Core?
Answer:

  • Built-in DI container.

  • Register services in Program.cs (AddScoped, AddSingleton, AddTransient).

  • Constructor Injection is commonly used.

  • Example: I used DI to inject a ILoggingService across multiple microservices, improving testability.


Q3. Explain the difference between Task, Thread, and ValueTask.
Answer:

  • Thread → OS-level execution unit.

  • Task → Abstraction for async work (thread pool).

  • ValueTask → Optimized for high-frequency async calls to reduce memory allocations.

  • Example: Used ValueTask in an API that fetches data from cache 90% of the time, avoiding unnecessary heap allocations.


🔹 2. ASP.NET Core

Q4. Describe the Middleware pipeline in ASP.NET Core.
Answer:

  • Request → Middleware (Authentication → Routing → Controller) → Response.

  • Each middleware can pass or short-circuit the pipeline.

  • Example: I created a custom middleware for request logging and correlation IDs to trace distributed requests across microservices.


Q5. How do you implement Authentication and Authorization in ASP.NET Core?
Answer:

  • Authentication: JWT, OAuth2, IdentityServer.

  • Authorization: Role-based, Policy-based, Claims-based.

  • Example: In one project, we used Azure AD for authentication and role-based policies to secure APIs per department.


Q6. What is the difference between Filters and Middleware?
Answer:

  • Middleware → Runs before MVC pipeline (cross-cutting concerns: logging, authentication).

  • Filters → MVC-specific (Action, Result, Exception handling).

  • Example: I used an Exception Filter to standardize API error responses across services.


🔹 3. REST API & Microservices

Q7. How do you design a REST API for high scalability?
Answer:

  • Use Stateless APIs, proper versioning, caching (Redis/MemoryCache), pagination, async I/O, load balancing.

  • Example: Designed an order API handling 1M+ daily requests using Redis cache + async DB calls, reducing DB load by 40%.


Q8. How do you handle API versioning in .NET Core?
Answer:

  • Options: URL-based (/api/v1/), Header-based, Query string.

  • In .NET Core → Microsoft.AspNetCore.Mvc.Versioning package.

  • Example: Implemented versioning for Payment API to maintain backward compatibility while adding new tax rules.


Q9. What are Circuit Breakers in Microservices?
Answer:

  • Prevents cascading failures by stopping calls to failing services temporarily.

  • Implemented using Polly in .NET Core.

  • Example: Used Circuit Breaker for payment service integration; avoided timeouts when third-party API was down.


🔹 4. Entity Framework Core

Q10. How do you improve performance in EF Core?
Answer:

  • Use AsNoTracking for read-only queries.

  • Compiled Queries.

  • Batch operations.

  • Proper indexing.

  • Example: We reduced API response from 3s to 800ms by applying AsNoTracking and adding a covering index.


Q11. How do you handle concurrency in EF Core?
Answer:

  • Optimistic concurrency[Timestamp] or RowVersion.

  • Pessimistic concurrencyTransaction with locks.

  • Example: Used Optimistic concurrency in a ticket booking app to prevent double-booking.


Q12. Explain Repository & Unit of Work with EF Core.
Answer:

  • Repository → Encapsulates data access logic.

  • Unit of Work → Manages transactions across multiple repositories.

  • Example: Implemented this pattern in a banking app to maintain consistency across multiple accounts during transfers.


🔹 5. SQL Server

Q13. How do you optimize slow SQL queries?
Answer:

  • Check Execution Plan.

  • Add appropriate Indexes.

  • Use CTEs/Window functions.

  • Avoid SELECT *.

  • Example: Optimized a query by converting cursor-based logic to set-based query, reducing execution from 2 minutes to 4 seconds.


Q14. Explain Deadlocks and how to prevent them.
Answer:

  • Deadlocks happen when 2 transactions wait on each other.

  • Prevent by keeping transaction short, accessing resources in the same order, using Read Committed Snapshot Isolation (RCSI).

  • Example: Solved a production deadlock by reordering update statements and enabling RCSI.


🔹 6. Design & Architecture

Q15. Difference between Monolith, Microservices, and Serverless.
Answer:

  • Monolith → Single deployable unit.

  • Microservices → Independent services communicating via APIs.

  • Serverless → Event-driven (Azure Functions).

  • Example: Migrated a legacy monolith HR system into microservices (Employee, Payroll, Leave) deployed in Azure.


Q16. Explain SOLID principles in real projects.
Answer:

  • Single Responsibility → Each class should do one thing.

  • Open/Closed → Extend without modifying.

  • Example: Refactored an Invoice Service by applying SRP → separated tax calculation, discount, and invoice generation into separate classes.


Q17. What is Clean Architecture in .NET Core?
Answer:

  • Layers: Domain → Application → Infrastructure → UI.

  • Decouples business logic from frameworks.

  • Example: Implemented Clean Architecture in an Insurance API → easy to swap SQL with Cosmos DB without changing business logic.


🔹 7. Azure & Cloud

Q18. How do you deploy a .NET Core app to Azure?
Answer:

  • Azure App Service, Containers, AKS.

  • Use CI/CD via Azure DevOps or GitHub Actions.

  • Example: Deployed an e-commerce API to Azure App Service with auto-scaling (scale out at CPU > 70%).


Q19. Explain Azure Service Bus vs Event Grid vs Event Hub.
Answer:

  • Service Bus → Enterprise messaging, queue-based.

  • Event Grid → Pub-Sub for reactive events.

  • Event Hub → Streaming (big data, telemetry).

  • Example: Used Service Bus for order processing (guaranteed delivery), Event Grid for sending email notifications.


Q20. How do you secure secrets in Azure?
Answer:

  • Azure Key Vault.

  • Managed Identity.

  • Example: Stored DB connection strings in Key Vault, avoiding plain-text configs.


🔹 8. Advanced Topics

Q21. How do you implement caching in .NET Core?
Answer:

  • In-Memory Cache.

  • Distributed Cache (Redis, SQL Server).

  • Response Caching.

  • Example: Used Redis cache for product catalog API, reducing DB hits by 60%.


Q22. How do you handle Logging & Monitoring in .NET Core?
Answer:

  • Built-in logging (Serilog, NLog, Application Insights).

  • Centralized monitoring with ELK or Azure App Insights.

  • Example: Implemented structured logging with Serilog + Application Insights for distributed tracing.


Q23. Explain CQRS with an example.
Answer:

  • Command Query Responsibility Segregation → Separate read & write models.

  • Example: In an e-commerce app, we used CQRS → Commands for order placement, Queries for order history (optimized DB reads using Dapper).


🔹 9. Agile/Scrum

Q24. How do you work in Agile/Scrum?
Answer:

  • 2-week sprints, backlog grooming, daily standups, sprint reviews, retrospectives.

  • Example: Implemented a Payment API feature in 2 sprints, demoed to stakeholders, and refined based on feedback.


Q25. How do you handle changing requirements in Agile?
Answer:

  • Re-prioritize backlog with Product Owner.

  • Deliver in small increments.

  • Example: When tax rules changed mid-sprint, we delivered base API first, then enhancements in next sprint.

 What are Hosting Models in .NET Core?
Answer:

  • In-Process hosting – App runs inside IIS worker process (w3wp.exe), better performance.

  • Out-of-Process hosting – App runs as a separate process (dotnet.exe) with IIS as a reverse proxy.

  • Self-hosted (Kestrel only) – Runs without IIS, often used in Docker or Linux environments.

Comments

Popular posts from this blog

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

What are SOLID Principles?