<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4274440498886912486</id><updated>2026-10-15T12:58:16.672+05:30</updated><category term="Telangana"/><category term="Azure DevOps"/><category term=".net core"/><category term="angular"/><category term="Azure Kubernetes Service"/><category term="C#"/><category term="Docker"/><category term="Angular interview questions"/><category term="Azure Service Bus"/><category term="Circuit Breaker"/><category term="Design Patterns"/><category term="Micro Services"/><category term="Microservices"/><category term="PV sindhu"/><category term="Sql Server"/><category term="Top 100 Azure Cloud Service Interview Questions and Answers (2026)"/><category term="blogging"/><category term="yoga"/><category term=".Net Core Micro Services"/><category term=".Net Core WEB APi"/><category term="AI tools"/><category term="Angular Components"/><category term="Angular Standalone Components"/><category term="Angular architecture"/><category term="Angular modules"/><category term="Apache Kafka"/><category term="Azure Cloud"/><category term="Azure Kubernetes Service tutorial"/><category term="C# programming"/><category term="CQRS"/><category term="CQRS .NET Core"/><category term="ChatGPT"/><category term="DALL·E"/><category term="DB2"/><category term="DDD architecture"/><category term="Generative AI"/><category term="Hyderabad Telangana"/><category term="India"/><category term="Kubernetes"/><category term="Live TV"/><category term="Modern C# features"/><category term="NGINX"/><category term="OpenAI"/><category term="OpenAI API"/><category term="Parallel Programming"/><category term="PostgreSQL advantages"/><category term="PostgreSQL for .NET Core"/><category term="REST API"/><category term="RIO"/><category term="SQL"/><category term="SQL Query &amp; Stored Procedure Optimization: A Complete Guide for Developers"/><category term="SQL vs T-SQL vs PostgreSQL"/><category term="Structural Design Patterns"/><category term="Suicide"/><category term="all live tvs"/><category term="angular caching"/><category term="azure app service"/><category term="circuit breaker pattern"/><category term="future of AI"/><category term="health"/><category term="hyderabad"/><category term="images"/><category term="jathara"/><category term="photos"/><category term="retry pattern"/><category term="saralamma"/><category term="swamiye saranam ayyappa"/><category term="tools"/><category term="videos"/><category term="web API"/><category term=". NET Core Web API Notifications"/><category term=".NET AI development"/><category term=".NET Architect Interview Questions and Answers"/><category term=".NET Architecture Styles"/><category term=".NET Core Dependency Injection"/><category term=".NET Core Lifecycle"/><category term=".NET Core Singleton"/><category term=".NET Core Using Statement"/><category term=".NET Core Web API IoT"/><category term=".NET Core for cloud applications"/><category term=".NET Core interview questions&#xa;C# interview questions 2025."/><category term=".NET Core performance"/><category term=".NET Core vs .NET Framework"/><category term=".NET Framework monolithic application into microservices using AI tools. Includes step-by-step methodology"/><category term=".NET Framework vs .NET Core"/><category term=".NET Generics"/><category term=".NET WPF interview preparation"/><category term=".NET Web Services"/><category term=".NET environment variables"/><category term=".NET interview questions and answers"/><category term=".NET multithreading vs asynchronous programming"/><category term=".NET optimization"/><category term=".Net Framework"/><category term=".NetCore"/><category term=".net sql server optimization"/><category term="10 tv live"/><category term="10 tv news channel"/><category term="10 tv telugu news channel"/><category term="1000"/><category term="12-factor app"/><category term="2000"/><category term="4 to 6 experience dotnet developers interview questions"/><category term="500"/><category term="ACR and AKS"/><category term="ADF"/><category term="AE papers"/><category term="AE questions"/><category term="AE sample papers"/><category term="AI -2026"/><category term="AI Automation in DevOps"/><category term="AI Coding Tools"/><category term="AI art tool"/><category term="AI content creation"/><category term="AI design tool"/><category term="AI ethics"/><category term="AI for business"/><category term="AI for creativity"/><category term="AI image generator"/><category term="AI in .NET"/><category term="AI in .NET Core"/><category term="AI in .NET and Angular"/><category term="AI in cloud computing"/><category term="AI research"/><category term="AI safety"/><category term="AI with .NET Core Web API"/><category term="AI with .NET applications"/><category term="AI-powered Web API using .NET"/><category term="AKS autoscaler"/><category term="AKS best practices"/><category term="AKS configuration"/><category term="AKS networking"/><category term="AKS tutorial"/><category term="AKS workload identity"/><category term="API"/><category term="API Backward Compatibility"/><category term="API Gateway Example"/><category term="API Gateway in Microservices"/><category term="API comparison"/><category term="API for beginners"/><category term="API performance"/><category term="API performance optimization"/><category term="API traffic management"/><category term="API tutorial"/><category term="ASB notifications"/><category term="ASP.NET Core"/><category term="ASP.NET Core&#xa;Email and SMS notifications in .NET Core"/><category term="ASP.NET Core API Versioning"/><category term="ASP.NET Core REST API"/><category term="ASP.NET Core SignalR"/><category term="ATS tips"/><category term="AWS API Gateway"/><category term="AWS regions 2025"/><category term="AWS vs Azure vs Google Cloud"/><category term="Abstract Factory Design Pattern"/><category term="Adapter Design Pattern"/><category term="Adapter Pattern Real Time Example"/><category term="Adapter Pattern in C#"/><category term="Adapter pattern .NET"/><category term="Advanced Azure Architecture"/><category term="Advanced TypeScript concepts"/><category term="Advantages and Disadvantages"/><category term="Advantages of .NET Core"/><category term="Agentic AI"/><category term="Agentic AI interview questions"/><category term="Agentic AI tutorial"/><category term="All channels"/><category term="All countries codes"/><category term="Alternative of Message Broker"/><category term="Amazon SQS"/><category term="Andhra pradesh tv"/><category term="Angular .NET Core performance"/><category term="Angular 15"/><category term="Angular 15 Standalone Components"/><category term="Angular 15 new features"/><category term="Angular 15 tutorial"/><category term="Angular 16 best practices"/><category term="Angular 17"/><category term="Angular 17 questions"/><category term="Angular 18"/><category term="Angular Directives with example"/><category term="Angular Directives – Complete Guide with All Examples"/><category term="Angular Forms Best Practices"/><category term="Angular Forms Example&#xa;Template-Driven Forms in Angular"/><category term="Angular Forms Tutorial"/><category term="Angular Module vs Component"/><category term="Angular Modules in Angular&#xa;Angular Templates explained"/><category term="Angular Pipes in Angular"/><category term="Angular Reactive Forms vs Template-Driven Forms"/><category term="Angular SEO best practices"/><category term="Angular SSR tutorial"/><category term="Angular SSR vs CSR"/><category term="Angular Sample Project"/><category term="Angular TypeScript topics"/><category term="Angular Universal step by step"/><category term="Angular advanced interview"/><category term="Angular advantages"/><category term="Angular best practices"/><category term="Angular building blocks"/><category term="Angular code examples"/><category term="Angular code reusability"/><category term="Angular coding round"/><category term="Angular custom directive and pipe"/><category term="Angular developer interview"/><category term="Angular directives"/><category term="Angular disadvantages"/><category term="Angular dynamic Components"/><category term="Angular migration guide"/><category term="Angular optimization techniques"/><category term="Angular performance optimization"/><category term="Angular pipes"/><category term="Angular routing"/><category term="Angular routing standalone component"/><category term="Angular security"/><category term="Angular service state"/><category term="Angular services"/><category term="Angular state management"/><category term="Angular tutorial"/><category term="Angular version comparison"/><category term="Angular vs React performance"/><category term="Angular vs ReactJS"/><category term="Angular without NgModule"/><category term="Anna Hazare"/><category term="Apache Kafka Interview Questions &amp; Answers"/><category term="ApiGateway → Ocelot API Gateway"/><category term="App Services"/><category term="Architect"/><category term="Architect Interview"/><category term="Architectural Styles vs Architectural Patterns vs Design Patterns in .NET"/><category term="Ardha"/><category term="Artifact Feed"/><category term="Artificial Intelligence trends 2025"/><category term="Asian news live"/><category term="Assembly"/><category term="Asthma"/><category term="Async"/><category term="Async and Aswait"/><category term="Async notifications using ASB Bus"/><category term="Async/Await vs Multithreading vs Parallel Programming in .NET"/><category term="AuthService → issues JWT tokens"/><category term="AutoGPT"/><category term="Azure AD"/><category term="Azure AI Search"/><category term="Azure AI best practices"/><category term="Azure AKS monitoring"/><category term="Azure API Management"/><category term="Azure API Management (APIM)&#xa;Kong"/><category term="Azure App Service config"/><category term="Azure CI/CD"/><category term="Azure CNI vs kubenet"/><category term="Azure Cloud Services"/><category term="Azure Cognitive Services"/><category term="Azure Cognitive Services in .NET"/><category term="Azure Cognitive Services tutorial"/><category term="Azure Compute &amp; Storage"/><category term="Azure Container Registry"/><category term="Azure Container Registry push and pull"/><category term="Azure Cosmos DB interview questions"/><category term="Azure Data Factory"/><category term="Azure Data Factory Connectors"/><category term="Azure DevOps Artifacts"/><category term="Azure Functions"/><category term="Azure Functions interview questions"/><category term="Azure Functions tutorial"/><category term="Azure Key Vault"/><category term="Azure Monitor &amp; Application Insights"/><category term="Azure Networking &amp; Security"/><category term="Azure Pipeline Example"/><category term="Azure Pipelines"/><category term="Azure Red Hat OpenShift?"/><category term="Azure Service Bus tutorial"/><category term="Azure Speech SDK"/><category term="Azure Sql Database"/><category term="Azure Storage"/><category term="Azure database services"/><category term="Azure datacenters list"/><category term="Azure serverless example"/><category term="Background service"/><category term="Background services"/><category term="Balochista"/><category term="Basheer Abdul Kadhar"/><category term="BehaviorSubject Angular"/><category term="Behavioral Patterns&#xa;Dependency Injection"/><category term="Belgium"/><category term="Benefits of Generics"/><category term="Best Practices for .NET Developers"/><category term="Bhakti tv live"/><category term="Binary Serialization"/><category term="Birla mandir"/><category term="Brand ambassador"/><category term="Bridge Design Pattern"/><category term="Builder Design Pattern"/><category term="C# 11 features"/><category term="C# 12 features"/><category term="C# Design Patterns Tutorial Real-time example of Factory Pattern"/><category term="C# Generics Example"/><category term="C# IDisposable"/><category term="C# Resource Management"/><category term="C# Task example"/><category term="C# Thread example"/><category term="C# Thread-Safe Singleton Example"/><category term="C# access modifiers"/><category term="C# class accessibility"/><category term="C# code refactoring"/><category term="C# collection expressions"/><category term="C# encapsulation examples"/><category term="C# latest version"/><category term="C# memory optimization"/><category term="C# new features"/><category term="C# performance optimization"/><category term="C# primary constructors"/><category term="C# required members"/><category term="C# updates 2025"/><category term="C# visibility keywords"/><category term="CEILING vs FLOOR SQL"/><category term="CI/CD"/><category term="CI/CD pipeline"/><category term="CQRS (Command Query Responsibility Segregation) in .NET: A Complete Guide with Real-World Banking Example"/><category term="CQRS Design Patterns"/><category term="CQRS and Event Sourcing"/><category term="CQRS example"/><category term="CQRS pattern .NET"/><category term="CQRS tutorial"/><category term="CQRS with MediatR"/><category term="CREATE ALTER DROP TRUNCATE"/><category term="CRPF"/><category term="CRUD using ReactJS"/><category term="Canary"/><category term="Chain of Responsibility Design Pattern"/><category term="ChatGPT for Developers"/><category term="ChinapaDham"/><category term="Clean Code"/><category term="Cloud AI development tools"/><category term="Cloud Codex"/><category term="Cloud DevOps automation"/><category term="Cloud Hosting"/><category term="Cloud load balancer"/><category term="Codex"/><category term="Command Design Pattern"/><category term="Command Query Responsibility Segregation"/><category term="Compare Python and C# across syntax"/><category term="Complete Guide to DevOps"/><category term="Complete Guide to Docker with Real Time Example"/><category term="Complete Guide to ReactJS with .net Core"/><category term="Composite Design Pattern"/><category term="ConfigMap"/><category term="Configure Resilience Policies in Program.cs"/><category term="Congress"/><category term="Container orchestration in Go"/><category term="Cosmos DB Entity Framework integration"/><category term="Cosmos DB in microservices"/><category term="Cosmos DB use cases"/><category term="Cosmos DB vs SQL Server"/><category term="Cosmos DB with .NET Core"/><category term="Country"/><category term="Creating a Custom Component in Angular with a Real-Time Example"/><category term="Creational Design Pattern"/><category term="Creational Design Patterns in C#"/><category term="Creational Design Patterns – Singleton Pattern"/><category term="Cricket"/><category term="Cricket to badminton"/><category term="Cross-platform .NET development"/><category term="Custom Components"/><category term="Custom ML Models"/><category term="Custom Middleware in .NET Core ASP.NET Core request ipeline"/><category term="DALL·E examples"/><category term="DB2 Interview Questions and Answers"/><category term="DD news live"/><category term="DDD"/><category term="DDL DML DCL TCL"/><category term="DELETE vs TRUNCATE vs DROP in SQL Server"/><category term="DI lifetimes in ASP.NET Core"/><category term="Dapper vs Entity Framework Core in .NET – Complete End-to-End Guide"/><category term="Data Consistency in Microservices"/><category term="Decorator Design Pattern"/><category term="Delete"/><category term="Dependency Injection in ASP.NET Core"/><category term="Dependency Inversion Principle"/><category term="Deploy Docker container to Azure"/><category term="Design Pattern"/><category term="Design Patterns Example"/><category term="DevOps"/><category term="DevOps Build Artifacts"/><category term="DevOps Explanation in detail"/><category term="DevOps Packages"/><category term="DevOps tools architecture"/><category term="DevOps with Docker"/><category term="Devotional Channels"/><category term="Difference between IEnumerable and IQueryable in C#"/><category term="Difference between Singleton and Static in C#"/><category term="Difference between Task and Thread C#"/><category term="Difference between WCF and Web API"/><category term="Digital marketting"/><category term="Direct HTTP/REST Communication Between Microservices"/><category term="Directives"/><category term="Disaster Recovery &amp; Real-Time Scenario"/><category term="Distributed Transactions in Microservices"/><category term="Docker commands."/><category term="Docker containers"/><category term="Docker env variables"/><category term="Docker for beginners"/><category term="Docker programming language"/><category term="Docker tutorial"/><category term="Docker vs Kubernetes"/><category term="Docker vs Virtual Machine"/><category term="Dockerfile example"/><category term="Domain Driven Design"/><category term="Domain-Driven Design (DDD) Explained with a Real-World Banking Project (.NET)"/><category term="Dotnet questions and answers for experience"/><category term="Dynamic Component in Angular"/><category term="EAMCET"/><category term="EAMCET Key"/><category term="Emirates Plane"/><category term="Envoy"/><category term="Event Sourcing"/><category term="Event Streaming"/><category term="Event-Driven Architecture in .NET"/><category term="Examples of Creational"/><category term="Exception handling in WCF"/><category term="Facade Design Pattern"/><category term="Factory Design Pattern in C#"/><category term="Factory Method Design Pattern"/><category term="Factory Pattern"/><category term="Fallback Pattern"/><category term="Fault Contract WCF"/><category term="Façade Pattern Example"/><category term="Final"/><category term="Finding amoung"/><category term="Flyweight Design Pattern"/><category term="Frontend Backend Integration"/><category term="Full Stack Development"/><category term="Future of Programming with AI"/><category term="Future of cloud development"/><category term="GPT"/><category term="GPT-4"/><category term="GST 2.0"/><category term="GST 2025"/><category term="GST Rate Cuts"/><category term="GST for Common People"/><category term="Gang of Four (GoF) Design Patterns"/><category term="Generative AI applications"/><category term="Generative AI benefits"/><category term="Generative AI coding assistant"/><category term="Generative AI vs AI Agents vs Agentic AI: Understanding the Evolution of Artificial Intelligence"/><category term="Generic Class in C#"/><category term="Generic Collection in C#"/><category term="Generic Method in C#"/><category term="Generics in C#"/><category term="GitHub Copilot"/><category term="GitHub Copilot alternative"/><category term="Go in Docker"/><category term="GoF"/><category term="Golang in Kubernetes"/><category term="Google Cloud Next 2025"/><category term="GraphQL tutorial"/><category term="Group discussion"/><category term="Gtalk Login problem"/><category term="Gtalk password problem"/><category term="HCU"/><category term="HD Action Camera"/><category term="HTTP"/><category term="HTTP methods"/><category term="Health tip."/><category term="High Availability"/><category term="High-performance .NET apps"/><category term="How prepare resume"/><category term="How to Configure DevOps Pipelines: A Real-Time CI/CD Example"/><category term="IBM DB2"/><category term="IBM DB2 Interview Questions and Answers (2026) – Complete Guide for Beginners to Experienced Professionals"/><category term="IEnumerable in C# with example"/><category term="IEnumerable vs IQueryable"/><category term="IPL 2016"/><category term="IQueryable in C# with example"/><category term="Improve Angular performance with SSR"/><category term="India GST News"/><category term="Indian premier league"/><category term="Integrate AI/ML models"/><category term="Interface Segregation Principle"/><category term="Internet of Things"/><category term="Interpreter Design Pattern"/><category term="Interview Questions and Answers for Dotnet developers"/><category term="Interview questions and answers"/><category term="IoT dashboard"/><category term="IoT example"/><category term="IoT sensors"/><category term="IoT tutorial"/><category term="Istio"/><category term="Iterator Design Pattern"/><category term="JSON API"/><category term="JWT Authentication &amp; Authorization — Complete Flow"/><category term="Jai sri ram"/><category term="Jai telangana TV"/><category term="Jenkins"/><category term="Kadapa By elections"/><category term="Kannada channels live"/><category term="Kannada news"/><category term="Kannada tv live"/><category term="Kannada tv news"/><category term="Kashimr"/><category term="Kerala"/><category term="Kubernetes DevOps"/><category term="Kubernetes LoadBalancer service example"/><category term="Kubernetes Secrets"/><category term="Kubernetes advantages"/><category term="Kubernetes container orchestration"/><category term="Kubernetes features"/><category term="Kubernetes for beginners"/><category term="Kubernetes importance"/><category term="Kubernetes in cloud"/><category term="Kubernetes on Azure cloud step by step"/><category term="Kubernetes programming language"/><category term="Kubernetes tutorial."/><category term="Kyocera DuraForce Pro Mobile"/><category term="LINQ IEnumerable vs IQueryable"/><category term="LLM"/><category term="LLM Integration"/><category term="Large Language Model"/><category term="Lazy Singleton C# Example"/><category term="Learn TypeScript from Scratch"/><category term="Learn how to create a professional resume for freshers and experienced software professionals. Includes resume format"/><category term="Learn the complete CI/CD pipeline process — from code commit in a local repository to automated deployment using tools like GitHub"/><category term="Learn the essential skills"/><category term="Learn the most popular deployment strategies in CI/CD pipelines including Blue-Green"/><category term="Learn what throttling in Web API is"/><category term="Learning MVC from basics"/><category term="Legacy System Integration"/><category term="Liskov Substitution Principle"/><category term="Load balancing in Web API"/><category term="Lock in windows services"/><category term="MBBS"/><category term="ML.NET tutorial"/><category term="MLearning in .NET"/><category term="MVC"/><category term="MVC Course"/><category term="MVC for Beginners"/><category term="MVC learning"/><category term="MVC tutorials"/><category term="MVVM interview questions"/><category term="Machine Learning in .NET"/><category term="Mail"/><category term="Malaysia goat"/><category term="Mediator Design Pattern"/><category term="Memento Design Pattern"/><category term="Message Broker"/><category term="Message Broker in .NET Core"/><category term="Message Queueing"/><category term="Micro serivice"/><category term="Microservices .NET Core"/><category term="Microservices Communication"/><category term="Microservices with .NET Core"/><category term="Microsoft Web Technologies"/><category term="Middleware in ASP.NET Core"/><category term="Migrating Database to Azure Cloud"/><category term="Modern Design Patterns in Microservices"/><category term="Modern Web App"/><category term="Modi"/><category term="Modi GST Reforms"/><category term="MongoDB with Microsoft Azure and ASP.NET Core"/><category term="Monitor"/><category term="Monolithic vs Microservices"/><category term="Multithreading"/><category term="Mutex"/><category term="N-Tier Architecture..NET Design Patterns"/><category term="NPDCL papers"/><category term="Nadendla on wikileaks"/><category term="Natural Language Processing"/><category term="New Delhi"/><category term="New GST Structure"/><category term="NgRx tutorial"/><category term="Nirosha"/><category term="Notifications"/><category term="Notifications in .NET Core"/><category term="OAuth2"/><category term="OIDC"/><category term="OOP Design"/><category term="OOP Principles"/><category term="Object creation in C# using Factory Pattern"/><category term="Observer Design Pattern"/><category term="Ocelot"/><category term="Ocelot (for .NET Core)"/><category term="Om shiva"/><category term="Open Closed Principle"/><category term="Open source containerization"/><category term="OpenAI (via Azure OpenAI Service or API)"/><category term="OpenAI APIs"/><category term="OpenAI APIs – Complete Guide"/><category term="OpenAI DALL·E"/><category term="OpenAI tools"/><category term="Optimization"/><category term="Orchestration vs Choreography SAGA"/><category term="PM"/><category term="PV sindhu entered into final"/><category term="PV sindhu final"/><category term="Pakisthan"/><category term="Pedhapadam"/><category term="Performance improvement in sql"/><category term="Polly library"/><category term="PostgreSQL"/><category term="PostgreSQL vs SQL Server"/><category term="ProductService → sample microservice"/><category term="Professor jaya shankar"/><category term="Professor jaya shankar sir"/><category term="Prototype Design Pattern"/><category term="Proxy Design Pattern"/><category term="Pub/Sub"/><category term="RAG"/><category term="REST API example"/><category term="REST API in .NET"/><category term="REST best practices .NET"/><category term="REST calls"/><category term="REST principles"/><category term="REST vs GraphQL vs gRPC"/><category term="REST vs SOAP"/><category term="REST vs gRPC"/><category term="RESTful API"/><category term="RESTful API examples"/><category term="RESTful API vs GraphQL"/><category term="RESTful Services"/><category term="RabbitMQ"/><category term="ReactJS"/><category term="ReactJS advantages"/><category term="ReactJS disadvantages"/><category term="ReactJS in .Net Core"/><category term="ReactJS vs Angular 2025"/><category term="Reactive Forms in Angular&#xa;Angular Form Validation"/><category term="Real time example of Angular"/><category term="Real-world examples"/><category term="Recreate"/><category term="Redux in Angular"/><category term="Repository Pattern in .NET"/><category term="Resilience4j"/><category term="Resume preparation"/><category term="Retrieval-Augmented Generation"/><category term="Reusable Code in C#"/><category term="Rohith vemula"/><category term="Rolling"/><category term="SAGA Design Pattern in Microservices"/><category term="SELECT INSERT UPDATE DELETE MERGE"/><category term="SMS in Micro Services."/><category term="SOA"/><category term="SOAP"/><category term="SOLID Principles Overview"/><category term="SOLID principles in C#"/><category term="SQL ABS function"/><category term="SQL JOIN types"/><category term="SQL ROUND example"/><category term="SQL Server IoT"/><category term="SQL Server Machine Learning Services"/><category term="SQL Server ROUND"/><category term="SQL Server math functions"/><category term="SQL Server tutorial"/><category term="SQL absolute value"/><category term="SQL best practices"/><category term="SQL currency rounding"/><category term="SQL interview questions"/><category term="SQL optimization"/><category term="SQL query examples"/><category term="SQL real-time examples"/><category term="SQL rounding functions"/><category term="SQL tutorial"/><category term="SQL vs TSQL difference"/><category term="Sabari Tour"/><category term="Saga"/><category term="Saga Design Pattern – Complete Guide with E-Commerce Example"/><category term="Seats"/><category term="Sending Mail in Micro services"/><category term="Serialization"/><category term="Serilog"/><category term="Server Side Rendering in Angular"/><category term="Service Life Cycle in .NET Core Application"/><category term="SignalR vs Azure Service Bus vs Kafka vs RabbitMQ: Complete Guide with Real-Time Examples and C# Code"/><category term="Single Responsibility Principle"/><category term="Singleton"/><category term="Singleton Design Pattern"/><category term="Singleton Design Pattern in C#"/><category term="Singleton Pattern Real-Time Example in C#"/><category term="Singleton design pattern example in C#"/><category term="Singleton in C#"/><category term="Singleton vs Static Class"/><category term="Singleton vs Static in .NET"/><category term="Singleton vs Using"/><category term="Soap Serialization"/><category term="Software Architecture"/><category term="Software Deployment"/><category term="Software Integration"/><category term="SonarQube"/><category term="Speech to Text .NET"/><category term="Sql Server interview Questions"/><category term="SqlQueries"/><category term="Sr.Software Engineers"/><category term="Standalone component advantages"/><category term="Standalone vs Module in Angular"/><category term="State Design Pattern"/><category term="Static class in C# with example&#xa;When to use Singleton or Static in .NET"/><category term="Strategy Design Pattern"/><category term="Structural"/><category term="Structural Design Pattern"/><category term="Sum"/><category term="Sushma"/><category term="Sushma swaraj"/><category term="T-SQL"/><category term="T-SQL tutorial"/><category term="TET"/><category term="TPL"/><category term="TS TET"/><category term="TS notifications."/><category term="TSQL commands"/><category term="TV 5"/><category term="TV 5 channel"/><category term="TV 5 live"/><category term="TV 5 live streaming"/><category term="TV 9 Kannada"/><category term="TV 9 live"/><category term="TV channels."/><category term="TV kannada"/><category term="TV9 live"/><category term="TV9 news"/><category term="TV9 news channel"/><category term="Tamil tv"/><category term="Tank bund telangana"/><category term="Tankbund"/><category term="Technical Lead Interview Questions and Answers"/><category term="Telagana Movement"/><category term="Telangan Nijalu"/><category term="Telangana Agitation india"/><category term="Telangana NPDCL exam questions"/><category term="Telangana Photos"/><category term="Telangana Rare"/><category term="Telangana Sayudha Poratam"/><category term="Telangana State"/><category term="Telangana State now"/><category term="Telangana TV live"/><category term="Telangana Tannu"/><category term="Telangana Videos"/><category term="Telangana bonalu"/><category term="Telangna"/><category term="Telugu Channels"/><category term="Template Method Design Pattern"/><category term="Terraform"/><category term="Text Analytics sentiment analysis"/><category term="Thread vs Task in async programming"/><category term="Timeout Pattern"/><category term="Top 100 Angular Interview Questions and Answers for 2026"/><category term="Top 100 Azure DevOps Interview Questions"/><category term="Top 100 C# Interview Questions"/><category term="Top 100 Microservices Interview Questions"/><category term="Top 100 Microservices Interview Questions and Answers"/><category term="Top 100 SQL Server Interview Questions"/><category term="Top 100 SQL Server Interview Questions and Answers for Experienced Developers"/><category term="Top 50 System Design Questions"/><category term="Total Agriculture colleges in Telangana"/><category term="Total Engineering colleges in Telangana"/><category term="Total Medical Colleges in Telangana"/><category term="Total amount"/><category term="Truncate"/><category term="Try catch in wcf"/><category term="Type Safety in C#"/><category term="TypeScript"/><category term="TypeScript Generics explained"/><category term="TypeScript OOP tutorial"/><category term="TypeScript for web development"/><category term="TypeScript tutorial for beginners"/><category term="TypeScript vs JavaScript"/><category term="Types of Design Patterns"/><category term="Types of Serialization"/><category term="V6"/><category term="V6 TV live"/><category term="V6 live tv"/><category term="V6 news"/><category term="V6 teenmar"/><category term="VSTO"/><category term="Vault"/><category term="Versioning Strategies in REST API"/><category term="Visitor Design Pattern"/><category term="WCF"/><category term="WCF advantages"/><category term="WPF architecture"/><category term="WPF controls"/><category term="WPF data binding"/><category term="WPF interview answers"/><category term="WPF interview questions"/><category term="WPF layout"/><category term="Web API Best Practices"/><category term="Web API advantages"/><category term="Web API scalability"/><category term="Web Application Development"/><category term="Web Services"/><category term="Web Services vs WCF vs Web API"/><category term="Weight Loss Tips"/><category term="What are Design Patterns?"/><category term="What is Agentic AI"/><category term="What is DevOps"/><category term="What’s new in C#"/><category term="Where to Configure Ports in .NET Core"/><category term="Why do we need Design Patterns?"/><category term="Will AI Replace Software Developers"/><category term="Windows Service"/><category term="Worker Services in .NET"/><category term="Working with Windows Services in .NET"/><category term="XAML interview questions"/><category term="XML Serialization"/><category term="YARP/Ocelot"/><category term="Zuul"/><category term="aaj Tak live"/><category term="abdeslam arrest"/><category term="access modifiers in C#"/><category term="adding images to blog"/><category term="adding images to post"/><category term="adding photos"/><category term="adding video to blog"/><category term="adding videos to blog"/><category term="adding youtube video to blog"/><category term="ads"/><category term="advance tax payment"/><category term="all channels live"/><category term="all live tvs streaming"/><category term="all possible permutations"/><category term="all telugu news channels."/><category term="all tv channels"/><category term="amazon affiliate"/><category term="amazon associates"/><category term="amazon money"/><category term="amazon online money"/><category term="amithab bachan"/><category term="amithab bachan died"/><category term="amithab bachan fake news"/><category term="and .NET"/><category term="and C# Azure Functions code"/><category term="and Docker."/><category term="and Feature Toggles. Understand how they ensure zero downtime and safe releases."/><category term="and Pipes in Angular – Complete Guide with Real-Time Examples"/><category term="and best practices for modernizing legacy .NET systems."/><category term="and best practices."/><category term="and how to implement request rate limiting in ASP.NET Core using custom middleware and built-in rate limiter for better performance"/><category term="and real-world use-cases. Learn which language fits your project and team."/><category term="and roadmap to become an AI techie. From Python and Machine Learning to Cloud AI"/><category term="android"/><category term="android black berry"/><category term="angular interview preparation"/><category term="angular interview questions and answers - 2026"/><category term="angular material"/><category term="appsettings"/><category term="appsettings.json"/><category term="architecture"/><category term="ardhakaticakrasan"/><category term="artificial intelligence"/><category term="asan"/><category term="asian"/><category term="asian big jathara"/><category term="asian big tribal festival"/><category term="asian biggest jathara"/><category term="asianet live"/><category term="asp.net mvc features"/><category term="asynchronous messaging system"/><category term="auth gaurds"/><category term="await"/><category term="ayyapan pictures"/><category term="ayyappa pictures"/><category term="ayyappa wallpapers"/><category term="ayyappan"/><category term="ayyappan images"/><category term="azure release pipeline"/><category term="bahubali"/><category term="bahubali 2"/><category term="bahubali collection"/><category term="bahubali-2"/><category term="bakthi tv live"/><category term="bandaru"/><category term="beginners blogging"/><category term="belguim bomb blast"/><category term="best API architecture"/><category term="best cloud for AI"/><category term="best coding practices in C#"/><category term="best film bahubali"/><category term="best frontend framework 2025"/><category term="best practices C# access modifiers"/><category term="best resume format"/><category term="birla foundation"/><category term="black berry"/><category term="blog creation"/><category term="blog post in easy steps"/><category term="blogger"/><category term="blogging for beginners"/><category term="blogging in easy steps"/><category term="blogging tutorials"/><category term="blogging tutorials for beginners"/><category term="blue green deployment"/><category term="bonala photos"/><category term="bonalu gallery"/><category term="bootstrapApplication example"/><category term="bounded context"/><category term="bounded context example"/><category term="brussels airport"/><category term="build Web API in .NET"/><category term="cakra"/><category term="case filed case on anna Hazare"/><category term="case on anna Hazare"/><category term="cash for vote scandal"/><category term="challenges"/><category term="client-server API"/><category term="cloud comparison 2025"/><category term="cloud datacenters 2025"/><category term="cloud regions comparison"/><category term="codes"/><category term="communication between services"/><category term="content in table"/><category term="context mapping"/><category term="copy embed code to blog"/><category term="cover letter samples"/><category term="create images with AI"/><category term="cricket schedule of IPL 2016"/><category term="currency"/><category term="dalit"/><category term="database programming"/><category term="dd channel"/><category term="dd tv live"/><category term="dependency property"/><category term="deploy .NET app to AKS"/><category term="deployment slots"/><category term="devuda"/><category term="devudu live"/><category term="difference between  .NET Framework vs .NET Core"/><category term="distributed transactions Saga"/><category term="domain-driven design"/><category term="doordarshan"/><category term="doordarshan live"/><category term="dotnet questions for experience  people"/><category term="drop"/><category term="earning money with domain names"/><category term="easy suicide"/><category term="ecosystems"/><category term="emergency calls"/><category term="emergency service locator"/><category term="environment variables"/><category term="event-driven architecture .NET"/><category term="exceptions in wcf"/><category term="experience dotnet questions"/><category term="final match date of IPL"/><category term="find special characters"/><category term="floor ceiling sql"/><category term="flow of Notification s in micro services"/><category term="freshers resume preparation"/><category term="functions"/><category term="gRPC benefits"/><category term="gRPC vs REST"/><category term="get a complete step-by-step guide to start your AI career."/><category term="goat"/><category term="goat dies"/><category term="god live"/><category term="god save me"/><category term="golconda bonala photos"/><category term="google adsense"/><category term="gtalk login fail"/><category term="gtalk problem.gtalk user id and password"/><category term="gupta"/><category term="heatwave"/><category term="hindhi news"/><category term="hindhi news online"/><category term="hot pan"/><category term="how to create blog"/><category term="how to earn money"/><category term="how to get success in group discussion"/><category term="how to get success in interviews"/><category term="how to post in blogger"/><category term="human face goat"/><category term="human face goat in Malaysia"/><category term="hyderabad temparature"/><category term="hyderabad vaccine for zikha"/><category term="improve C# speed"/><category term="in-memory event bus"/><category term="inc"/><category term="income tax portal"/><category term="interceptors"/><category term="interview questions"/><category term="interview tips and tricks"/><category term="it"/><category term="jai baba"/><category term="jaya shankar sir"/><category term="jr.NTR bahubali"/><category term="kati"/><category term="ktr request"/><category term="launchSettings.json"/><category term="launchsettings"/><category term="learn Angular"/><category term="learning Angular"/><category term="learning python"/><category term="live hindhi channel"/><category term="live streaming"/><category term="lord venkateswara temple"/><category term="lucky"/><category term="lucky gupta"/><category term="machine learning"/><category term="malayalam news channels live"/><category term="managed identity Azure AI."/><category term="microservice architecture"/><category term="microservices best practices"/><category term="microservices configuration"/><category term="microservices fault tolerance"/><category term="microservices resilience"/><category term="microservices vs monolithic"/><category term="mobile emergenc6"/><category term="money with domain"/><category term="multi threading"/><category term="mythical"/><category term="namaskaram"/><category term="nirosa"/><category term="nirosha chowdary"/><category term="nirosha suicide in hoste"/><category term="notes"/><category term="observatory"/><category term="om"/><category term="om namo narayana"/><category term="om sai ram"/><category term="omelette"/><category term="optimize C# code"/><category term="paris attackers"/><category term="performance"/><category term="performance tips C#"/><category term="performance tuning in C#"/><category term="planetarium"/><category term="planets"/><category term="port configuration in .net core"/><category term="prabhas bahubali"/><category term="prevention of zikha"/><category term="project details"/><category term="protected internal vs private protected"/><category term="python"/><category term="rajamouli"/><category term="ramyakrishna"/><category term="real-time transcription Azure"/><category term="resilience in .NET"/><category term="resilient architecture"/><category term="resume preparation tips and tricks"/><category term="rio 2016"/><category term="round truncate SQL"/><category term="routing"/><category term="sabarimala photos"/><category term="sammakka"/><category term="sammakka saralamma"/><category term="sammakka saralamma jathara"/><category term="sarakka"/><category term="schedule cricket"/><category term="search engine settings for bloggers"/><category term="search engine technique"/><category term="searchable by google"/><category term="secret management"/><category term="security"/><category term="selling domain names"/><category term="semi final"/><category term="shared DB"/><category term="smart home IoT"/><category term="smriti"/><category term="social boycott"/><category term="software modularization"/><category term="special characters"/><category term="staging slot"/><category term="star plus"/><category term="stars."/><category term="studio n live"/><category term="studio news live"/><category term="successful interview"/><category term="suicide tv anchor"/><category term="sun live"/><category term="sun tv live"/><category term="surya"/><category term="surya namaskaram"/><category term="swami ayyappan"/><category term="swap deployment"/><category term="table in blog"/><category term="table in blog post"/><category term="tamannaha"/><category term="tamil tv live"/><category term="tank bund"/><category term="telanga bonalu photos"/><category term="telangana TV"/><category term="telangana channel"/><category term="telangana jathara"/><category term="telangana mahathma"/><category term="telephone codes"/><category term="telugua news channels"/><category term="text to image AI"/><category term="the role background services in microservices"/><category term="the update process in microservices"/><category term="tooling"/><category term="top 10"/><category term="top 10 tips for earning money."/><category term="total collections of bahubali"/><category term="transaction logs."/><category term="transactions SQL"/><category term="tutorials for blogging and youtube"/><category term="tv anchor"/><category term="tv anchor suicide"/><category term="tv hindhi news"/><category term="tv live"/><category term="tv5"/><category term="unable to login gtalk"/><category term="vaccine for zikha"/><category term="vaddera"/><category term="videos and blogs"/><category term="virus"/><category term="what is EAMCET.how many questions in EAMCET.telangana"/><category term="what is RESTful API"/><category term="white marble"/><category term="who wins the semi final womens"/><category term="why it’s important"/><category term="wikileaks telangana"/><category term="window functions OVER PARTITION BY."/><category term="without pain suicide."/><category term="women&#39;s badminton rio"/><category term="working with ocelot"/><category term="world wide collections of bahubali"/><category term="yahoo ads"/><category term="yoga asanas"/><category term="youtube"/><category term="youtube channel"/><category term="zero downtime deployment"/><category term="zika"/><category term="zikaa"/><category term="zikha"/><category term="zikha virus vaccine"/><title type='text'>Mahesh Info</title><subtitle type='html'>All the tutorials of Dot net, AI, Azure Cloud, Devops, Deployment, information, Interview Preparation, Helping, Resume Preparation, Design Patterns, Sql Server, Micro Services , EDD , DDD, TDD, IT, Software Developement, Team Lead, Tech Lead, Dotnet Architect, UML. Angular , Type Script , Dockers, Kubernetes , Load Balancer, AI Gate Way, Queue , Topic , Azure Service Bus.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>332</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-1700650658946733404</id><published>2026-09-22T17:22:42.491+05:30</published><updated>2026-09-22T20:22:25.581+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Dapper vs Entity Framework Core in .NET – Complete End-to-End Guide"/><title type='text'>Dapper vs Entity Framework Core in .NET – Complete End-to-End Guide</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTH1MpdY9pz1lcZvJXoMTOphr5HmuL7DxaEjFpcootL_7jcmpQnRUbGHLjfbDprvRtCVfbmAhX6-aLezUTf966mdhGXjuMsS9QgXJI_ao-97DGxM37PyiU0WWwz6dQe7CX6R5SeHfOAqDCJEji8afyxbqbvSsRNS-Cn0mav-Ivqi0Qk8VwFJArPZDVRVg/s1536/DapperVsEFCore.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;295&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTH1MpdY9pz1lcZvJXoMTOphr5HmuL7DxaEjFpcootL_7jcmpQnRUbGHLjfbDprvRtCVfbmAhX6-aLezUTf966mdhGXjuMsS9QgXJI_ao-97DGxM37PyiU0WWwz6dQe7CX6R5SeHfOAqDCJEji8afyxbqbvSsRNS-Cn0mav-Ivqi0Qk8VwFJArPZDVRVg/w543-h295/DapperVsEFCore.png&quot; width=&quot;543&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Introduction&lt;/h3&gt;&lt;p&gt;When developing modern &lt;strong&gt;ASP.NET Core Web API applications&lt;/strong&gt;, one of the most important decisions is how the application communicates with the database.&lt;/p&gt;&lt;p&gt;Two popular approaches in the .NET ecosystem are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Entity Framework Core (EF Core)&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dapper&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Both are powerful, but they solve the database-access problem differently.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;EF Core&lt;/strong&gt; is a full-featured Object-Relational Mapper (ORM), while &lt;strong&gt;Dapper&lt;/strong&gt; is a lightweight micro-ORM that provides a thin layer over ADO.NET.&lt;/p&gt;&lt;p&gt;A common interview question is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;What is the difference between Dapper and Entity Framework Core, and when would you use each?&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This article explains the differences from beginner to production level.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. What is Entity Framework Core?&lt;/h1&gt;&lt;p&gt;&lt;strong&gt;Entity Framework Core (EF Core)&lt;/strong&gt; is Microsoft&#39;s modern, cross-platform ORM for .NET.&lt;/p&gt;&lt;p&gt;ORM stands for:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Object Relational Mapping&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;It allows developers to work with database tables using C# classes and LINQ instead of writing SQL for every operation.&lt;/p&gt;&lt;p&gt;For example, suppose we have a database table:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE Employees
(
    Id INT PRIMARY KEY IDENTITY,
    Name NVARCHAR(100),
    Department NVARCHAR(100),
    Salary DECIMAL(18,2)
);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In EF Core, we can create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Employee
{
    public int Id { get; set; }

    public string Name { get; set; }

    public string Department { get; set; }

    public decimal Salary { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then query the database using LINQ:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees = await dbContext.Employees
    .Where(x =&amp;gt; x.Department == &quot;IT&quot;)
    .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core generates the appropriate SQL behind the scenes.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. What is Dapper?&lt;/h1&gt;&lt;p&gt;&lt;strong&gt;Dapper&lt;/strong&gt; is a lightweight micro-ORM for .NET.&lt;/p&gt;&lt;p&gt;It was originally created by the Stack Overflow team and is widely used for high-performance database access.&lt;/p&gt;&lt;p&gt;Unlike EF Core, Dapper does not attempt to provide a complete ORM framework.&lt;/p&gt;&lt;p&gt;You normally write the SQL yourself:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var sql = &quot;&quot;&quot;
          SELECT Id, Name, Department, Salary
          FROM Employees
          WHERE Department = @Department
          &quot;&quot;&quot;;

var employees = await connection.QueryAsync&amp;lt;Employee&amp;gt;(
    sql,
    new { Department = &quot;IT&quot; });&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Dapper executes the SQL and maps the returned rows to the &lt;code inline=&quot;&quot;&gt;Employee&lt;/code&gt; C# class.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Dapper vs EF Core – High-Level Difference&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Dapper&lt;/th&gt;&lt;th&gt;EF Core&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Type&lt;/td&gt;&lt;td&gt;Micro ORM&lt;/td&gt;&lt;td&gt;Full ORM&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SQL&lt;/td&gt;&lt;td&gt;Developer writes SQL&lt;/td&gt;&lt;td&gt;EF can generate SQL&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;LINQ&lt;/td&gt;&lt;td&gt;Limited/direct SQL approach&lt;/td&gt;&lt;td&gt;Extensive LINQ support&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Change Tracking&lt;/td&gt;&lt;td&gt;No built-in change tracker&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Migrations&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Relationships&lt;/td&gt;&lt;td&gt;Manual SQL/mapping&lt;/td&gt;&lt;td&gt;Built-in relationship mapping&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Lazy Loading&lt;/td&gt;&lt;td&gt;No built-in ORM-style lazy loading&lt;/td&gt;&lt;td&gt;Supported with configuration&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Performance&lt;/td&gt;&lt;td&gt;Generally very fast&lt;/td&gt;&lt;td&gt;Generally good, but more abstraction&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Control over SQL&lt;/td&gt;&lt;td&gt;Very high&lt;/td&gt;&lt;td&gt;Medium/High&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Learning Curve&lt;/td&gt;&lt;td&gt;Relatively low&lt;/td&gt;&lt;td&gt;Higher&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CRUD&lt;/td&gt;&lt;td&gt;SQL-based&lt;/td&gt;&lt;td&gt;Object-based/LINQ&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Transactions&lt;/td&gt;&lt;td&gt;ADO.NET transactions&lt;/td&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt; transactions&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Complex queries&lt;/td&gt;&lt;td&gt;Excellent when SQL is known&lt;/td&gt;&lt;td&gt;Excellent with LINQ, but SQL knowledge still useful&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Stored Procedures&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Supported&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Change Tracking&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Database-first&lt;/td&gt;&lt;td&gt;Manual&lt;/td&gt;&lt;td&gt;Supported&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Code-first&lt;/td&gt;&lt;td&gt;No EF-style migrations&lt;/td&gt;&lt;td&gt;Supported&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Best suited for&lt;/td&gt;&lt;td&gt;SQL-centric/high-performance applications&lt;/td&gt;&lt;td&gt;Domain/application-centric applications&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;4. Architecture Difference&lt;/h1&gt;&lt;p&gt;The biggest conceptual difference is the abstraction level.&lt;/p&gt;&lt;h2&gt;Dapper&lt;/h2&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application
     |
     v
Repository
     |
     v
Dapper
     |
     v
ADO.NET
     |
     v
SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You control the SQL.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;EF Core&lt;/h2&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application
     |
     v
Repository / Service
     |
     v
DbContext
     |
     v
EF Core
     |
     v
LINQ
     |
     v
SQL Generation
     |
     v
SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core provides more abstraction.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Basic EF Core Setup&lt;/h1&gt;&lt;p&gt;Suppose we are developing:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core Web API
        |
        v
EmployeeService
        |
        v
EmployeeRepository
        |
        v
EF Core
        |
        v
Azure SQL / SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Install the SQL Server provider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.EntityFrameworkCore.SqlServer&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For migrations:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.EntityFrameworkCore.Tools&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;6. Create DbContext&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class EmployeeDbContext : DbContext
{
    public EmployeeDbContext(
        DbContextOptions&amp;lt;EmployeeDbContext&amp;gt; options)
        : base(options)
    {
    }

    public DbSet&amp;lt;Employee&amp;gt; Employees { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. Configure Connection String&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;ConnectionStrings&quot;: {
    &quot;DefaultConnection&quot;:
      &quot;Server=localhost;Database=EmployeeDb;Trusted_Connection=True;TrustServerCertificate=True&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Register DbContext:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddDbContext&amp;lt;EmployeeDbContext&amp;gt;(options =&amp;gt;
    options.UseSqlServer(
        builder.Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;8. EF Core CRUD Operations&lt;/h1&gt;&lt;h2&gt;Create&lt;/h2&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employee = new Employee
{
    Name = &quot;John&quot;,
    Department = &quot;IT&quot;,
    Salary = 75000
};

dbContext.Employees.Add(employee);

await dbContext.SaveChangesAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core generates an INSERT statement.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. Read&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employee = await dbContext.Employees
    .FirstOrDefaultAsync(x =&amp;gt; x.Id == 10);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;10. Read Multiple Records&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees = await dbContext.Employees
    .Where(x =&amp;gt; x.Department == &quot;IT&quot;)
    .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Update&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employee = await dbContext.Employees
    .FirstOrDefaultAsync(x =&amp;gt; x.Id == 10);

if (employee != null)
{
    employee.Salary = 85000;

    await dbContext.SaveChangesAsync();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core detects the modified property using change tracking.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Delete&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employee = await dbContext.Employees
    .FindAsync(10);

if (employee != null)
{
    dbContext.Employees.Remove(employee);

    await dbContext.SaveChangesAsync();
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;13. Dapper Setup&lt;/h1&gt;&lt;p&gt;Install Dapper:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Dapper&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For SQL Server:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.Data.SqlClient&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;14. Dapper Connection&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.Data.SqlClient;
using System.Data;

public class EmployeeRepository
{
    private readonly string _connectionString;

    public EmployeeRepository(IConfiguration configuration)
    {
        _connectionString =
            configuration.GetConnectionString(&quot;DefaultConnection&quot;)!;
    }

    private IDbConnection CreateConnection()
    {
        return new SqlConnection(_connectionString);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. Dapper SELECT&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;IEnumerable&amp;lt;Employee&amp;gt;&amp;gt; GetEmployeesAsync()
{
    using var connection = CreateConnection();

    const string sql = &quot;&quot;&quot;
        SELECT Id, Name, Department, Salary
        FROM Employees
        &quot;&quot;&quot;;

    return await connection.QueryAsync&amp;lt;Employee&amp;gt;(sql);
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;16. Dapper SELECT By ID&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;Employee?&amp;gt; GetEmployeeAsync(int id)
{
    using var connection = CreateConnection();

    const string sql = &quot;&quot;&quot;
        SELECT Id, Name, Department, Salary
        FROM Employees
        WHERE Id = @Id
        &quot;&quot;&quot;;

    return await connection.QuerySingleOrDefaultAsync&amp;lt;Employee&amp;gt;(
        sql,
        new { Id = id });
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WHERE Id = @Id&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;new { Id = id }&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Dapper maps the parameter safely.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. Dapper INSERT&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;int&amp;gt; CreateEmployeeAsync(Employee employee)
{
    using var connection = CreateConnection();

    const string sql = &quot;&quot;&quot;
        INSERT INTO Employees
        (
            Name,
            Department,
            Salary
        )
        VALUES
        (
            @Name,
            @Department,
            @Salary
        );

        SELECT CAST(SCOPE_IDENTITY() AS INT);
        &quot;&quot;&quot;;

    return await connection.ExecuteScalarAsync&amp;lt;int&amp;gt;(
        sql,
        employee);
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;18. Dapper UPDATE&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;int&amp;gt; UpdateEmployeeAsync(Employee employee)
{
    using var connection = CreateConnection();

    const string sql = &quot;&quot;&quot;
        UPDATE Employees
        SET
            Name = @Name,
            Department = @Department,
            Salary = @Salary
        WHERE Id = @Id
        &quot;&quot;&quot;;

    return await connection.ExecuteAsync(sql, employee);
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;19. Dapper DELETE&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;int&amp;gt; DeleteEmployeeAsync(int id)
{
    using var connection = CreateConnection();

    const string sql = &quot;&quot;&quot;
        DELETE FROM Employees
        WHERE Id = @Id
        &quot;&quot;&quot;;

    return await connection.ExecuteAsync(
        sql,
        new { Id = id });
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Query vs Execute in Dapper&lt;/h1&gt;&lt;p&gt;This is an important interview topic.&lt;/p&gt;&lt;h3&gt;Query&lt;/h3&gt;&lt;p&gt;Use &lt;code inline=&quot;&quot;&gt;Query&lt;/code&gt; when you expect rows back.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees =
    await connection.QueryAsync&amp;lt;Employee&amp;gt;(sql);&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Execute&lt;/h3&gt;&lt;p&gt;Use &lt;code inline=&quot;&quot;&gt;Execute&lt;/code&gt; for INSERT, UPDATE, DELETE.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var affectedRows =
    await connection.ExecuteAsync(sql);&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;ExecuteScalar&lt;/h3&gt;&lt;p&gt;Use when you want one value.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employeeId =
    await connection.ExecuteScalarAsync&amp;lt;int&amp;gt;(sql);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;21. Entity Framework Core Change Tracking&lt;/h1&gt;&lt;p&gt;One of EF Core&#39;s major features is &lt;strong&gt;change tracking&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employee =
    await dbContext.Employees
        .FirstAsync(x =&amp;gt; x.Id == 10);

employee.Salary = 100000;

await dbContext.SaveChangesAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core knows that &lt;code inline=&quot;&quot;&gt;Salary&lt;/code&gt; changed.&lt;/p&gt;&lt;p&gt;It generates the UPDATE statement.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Dapper Does Not Track Changes&lt;/h1&gt;&lt;p&gt;Dapper does not maintain an entity state.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employee = await connection.QuerySingleAsync&amp;lt;Employee&amp;gt;(
    sql,
    new { Id = 10 });

employee.Salary = 100000;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Nothing happens automatically.&lt;/p&gt;&lt;p&gt;You must execute an UPDATE yourself:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await connection.ExecuteAsync(
    updateSql,
    employee);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;23. AsNoTracking in EF Core&lt;/h1&gt;&lt;p&gt;When you only need to read data, change tracking may not be required.&lt;/p&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees = await dbContext.Employees
    .AsNoTracking()
    .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can reduce tracking overhead for read-only queries.&lt;/p&gt;&lt;p&gt;This is especially useful in:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Reporting
Dashboards
Search APIs
Read-only endpoints
Large result sets&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;24. Relationships in EF Core&lt;/h1&gt;&lt;p&gt;Suppose we have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Department
    |
    +---- Employee
    +---- Employee
    +---- Employee&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Entities:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Department
{
    public int Id { get; set; }

    public string Name { get; set; }

    public ICollection&amp;lt;Employee&amp;gt; Employees { get; set; }
        = new List&amp;lt;Employee&amp;gt;();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Employee:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Employee
{
    public int Id { get; set; }

    public string Name { get; set; }

    public int DepartmentId { get; set; }

    public Department Department { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core can configure the relationship.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;modelBuilder.Entity&amp;lt;Employee&amp;gt;()
    .HasOne(e =&amp;gt; e.Department)
    .WithMany(d =&amp;gt; d.Employees)
    .HasForeignKey(e =&amp;gt; e.DepartmentId);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;25. Dapper Relationships&lt;/h1&gt;&lt;p&gt;Dapper doesn&#39;t automatically manage relationships like EF Core.&lt;/p&gt;&lt;p&gt;You normally write SQL joins.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
    e.Id,
    e.Name,
    d.Id,
    d.Name
FROM Employees e
INNER JOIN Departments d
    ON e.DepartmentId = d.Id&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then map the result manually using Dapper&#39;s multi-mapping capabilities or project into DTOs.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. EF Core Include&lt;/h1&gt;&lt;p&gt;EF Core provides &lt;code inline=&quot;&quot;&gt;Include&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees = await dbContext.Employees
    .Include(x =&amp;gt; x.Department)
    .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This tells EF Core to load the related department data.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. Dapper Stored Procedures&lt;/h1&gt;&lt;p&gt;Dapper works very well with stored procedures.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE PROCEDURE GetEmployeesByDepartment
    @Department NVARCHAR(100)
AS
BEGIN
    SELECT
        Id,
        Name,
        Department,
        Salary
    FROM Employees
    WHERE Department = @Department;
END&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Dapper:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees =
    await connection.QueryAsync&amp;lt;Employee&amp;gt;(
        &quot;GetEmployeesByDepartment&quot;,
        new
        {
            Department = &quot;IT&quot;
        },
        commandType: CommandType.StoredProcedure);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;28. EF Core Stored Procedures&lt;/h1&gt;&lt;p&gt;EF Core can also execute stored procedures.&lt;/p&gt;&lt;p&gt;For example, raw SQL can be used:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees =
    await dbContext.Employees
        .FromSqlInterpolated(
            $&quot;EXEC GetEmployeesByDepartment {&quot;IT&quot;}&quot;)
        .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core also provides APIs for executing SQL commands where appropriate.&lt;/p&gt;&lt;p&gt;The important point is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Choosing EF Core does not mean you can never use SQL or stored procedures.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;29. SQL Injection&lt;/h1&gt;&lt;p&gt;Both Dapper and EF Core can be used safely.&lt;/p&gt;&lt;p&gt;The important thing is &lt;strong&gt;parameterization&lt;/strong&gt;.&lt;/p&gt;&lt;h3&gt;Dapper&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;const string sql = &quot;&quot;&quot;
    SELECT *
    FROM Employees
    WHERE Department = @Department
    &quot;&quot;&quot;;

var employees = await connection.QueryAsync&amp;lt;Employee&amp;gt;(
    sql,
    new { Department = department });&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Avoid building SQL using string concatenation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var sql =
    &quot;SELECT * FROM Employees WHERE Department = &#39;&quot; +
    department +
    &quot;&#39;&quot;;&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;30. EF Core Parameterization&lt;/h1&gt;&lt;p&gt;LINQ queries are parameterized by EF Core.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees = await dbContext.Employees
    .Where(x =&amp;gt; x.Department == department)
    .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core generates parameterized SQL.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;31. Transactions with Dapper&lt;/h1&gt;&lt;p&gt;Dapper uses ADO.NET transactions.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using var connection = CreateConnection();

connection.Open();

using var transaction = connection.BeginTransaction();

try
{
    await connection.ExecuteAsync(
        insertEmployeeSql,
        employee,
        transaction);

    await connection.ExecuteAsync(
        updateDepartmentSql,
        department,
        transaction);

    transaction.Commit();
}
catch
{
    transaction.Rollback();
    throw;
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;32. Transactions with EF Core&lt;/h1&gt;&lt;p&gt;EF Core provides transaction support through &lt;code inline=&quot;&quot;&gt;Database&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await using var transaction =
    await dbContext.Database.BeginTransactionAsync();

try
{
    dbContext.Employees.Add(employee);

    await dbContext.SaveChangesAsync();

    department.Budget += 1000;

    await dbContext.SaveChangesAsync();

    await transaction.CommitAsync();
}
catch
{
    await transaction.RollbackAsync();
    throw;
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;33. EF Core Migrations&lt;/h1&gt;&lt;p&gt;One of the major advantages of EF Core is migrations.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet ef migrations add InitialCreate&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet ef database update&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you add a property:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public string Email { get; set; }&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;you can create another migration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet ef migrations add AddEmployeeEmail&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet ef database update&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core manages schema changes through migrations.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;34. Does Dapper Support Migrations?&lt;/h1&gt;&lt;p&gt;No.&lt;/p&gt;&lt;p&gt;Dapper itself is not a database schema migration framework.&lt;/p&gt;&lt;p&gt;You can use tools such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SQL scripts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DbUp&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;FluentMigrator&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Flyway&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Liquibase&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;CI/CD database migration processes&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application
    |
    +---- Dapper
    |
    +---- SQL Scripts
    |
    +---- Migration Tool
    |
    v
SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;35. Performance Comparison&lt;/h1&gt;&lt;p&gt;A common misconception is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Dapper is always faster than EF Core.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;That is too simplistic.&lt;/p&gt;&lt;p&gt;Dapper has a smaller abstraction layer and often performs very well for straightforward SQL queries.&lt;/p&gt;&lt;p&gt;EF Core has additional capabilities such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Change tracking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Identity resolution&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;LINQ translation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Relationship handling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Model metadata&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;State management&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These features have overhead.&lt;/p&gt;&lt;p&gt;However, properly written EF Core queries can perform very well.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees = await dbContext.Employees
    .AsNoTracking()
    .Where(x =&amp;gt; x.Department == &quot;IT&quot;)
    .Select(x =&amp;gt; new EmployeeDto
    {
        Id = x.Id,
        Name = x.Name
    })
    .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This avoids retrieving unnecessary columns and avoids tracking.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. Performance Depends on SQL and Database Design&lt;/h1&gt;&lt;p&gt;Database performance is not determined only by Dapper or EF Core.&lt;/p&gt;&lt;p&gt;Other factors include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Indexes
Query design
Execution plan
Database schema
Network latency
Connection pooling
Number of records
Pagination
Locking
Blocking
CPU
Memory
I/O
Database configuration&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example, a poorly written Dapper query can be slower than a well-written EF Core query.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;37. Pagination with Dapper&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;const string sql = &quot;&quot;&quot;
    SELECT Id, Name, Department, Salary
    FROM Employees
    ORDER BY Id
    OFFSET @Offset ROWS
    FETCH NEXT @PageSize ROWS ONLY
    &quot;&quot;&quot;;

var employees = await connection.QueryAsync&amp;lt;Employee&amp;gt;(
    sql,
    new
    {
        Offset = (pageNumber - 1) * pageSize,
        PageSize = pageSize
    });&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;38. Pagination with EF Core&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees = await dbContext.Employees
    .AsNoTracking()
    .OrderBy(x =&amp;gt; x.Id)
    .Skip((pageNumber - 1) * pageSize)
    .Take(pageSize)
    .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;39. Repository Pattern with EF Core&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IEmployeeRepository
{
    Task&amp;lt;Employee?&amp;gt; GetByIdAsync(int id);

    Task&amp;lt;IEnumerable&amp;lt;Employee&amp;gt;&amp;gt; GetAllAsync();

    Task AddAsync(Employee employee);

    Task UpdateAsync(Employee employee);

    Task DeleteAsync(int id);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Implementation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class EmployeeRepository : IEmployeeRepository
{
    private readonly EmployeeDbContext _context;

    public EmployeeRepository(EmployeeDbContext context)
    {
        _context = context;
    }

    public async Task&amp;lt;Employee?&amp;gt; GetByIdAsync(int id)
    {
        return await _context.Employees
            .FirstOrDefaultAsync(x =&amp;gt; x.Id == id);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;40. Repository Pattern with Dapper&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class EmployeeRepository : IEmployeeRepository
{
    private readonly string _connectionString;

    public EmployeeRepository(IConfiguration configuration)
    {
        _connectionString =
            configuration.GetConnectionString(&quot;DefaultConnection&quot;)!;
    }

    public async Task&amp;lt;Employee?&amp;gt; GetByIdAsync(int id)
    {
        using var connection =
            new SqlConnection(_connectionString);

        const string sql = &quot;&quot;&quot;
            SELECT Id, Name, Department, Salary
            FROM Employees
            WHERE Id = @Id
            &quot;&quot;&quot;;

        return await connection.QuerySingleOrDefaultAsync&amp;lt;Employee&amp;gt;(
            sql,
            new { Id = id });
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;41. CQRS with Dapper and EF Core&lt;/h1&gt;&lt;p&gt;A very common enterprise architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 API
                  |
             Application
                  |
             +----+----+
             |         |
         Commands    Queries
             |         |
             v         v
          EF Core    Dapper
             |         |
             v         v
          Database   Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;h3&gt;Command&lt;/h3&gt;&lt;p&gt;Create employee:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;POST /employees
       |
       v
Command Handler
       |
       v
EF Core
       |
       v
SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Query&lt;/h3&gt;&lt;p&gt;Get employees:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;GET /employees
       |
       v
Query Handler
       |
       v
Dapper
       |
       v
SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This approach can combine the strengths of both technologies.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;42. Real-Time Enterprise Example&lt;/h1&gt;&lt;p&gt;Consider a BPO workforce-management application.&lt;/p&gt;&lt;p&gt;The system contains:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Forecast Service
Workforce Service
Capacity Service
Hiring Service
Employee Service
Reporting Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Suppose the Reporting Service needs a complicated dashboard query:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Employee
    |
Department
    |
Skill
    |
Shift
    |
Forecast
    |
Actual Volume
    |
Utilization&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The query may involve:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Multiple JOINs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Aggregations&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Window functions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;CTEs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Stored procedures&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Complex filtering&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Dapper can be a strong choice when the team wants precise control over the SQL.&lt;/p&gt;&lt;p&gt;For standard application CRUD, EF Core may provide faster development.&lt;/p&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CRUD / Domain Logic
       |
     EF Core

Complex Reporting
       |
     Dapper&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is a &lt;strong&gt;hybrid approach&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;43. Can We Use Dapper and EF Core in the Same Application?&lt;/h1&gt;&lt;p&gt;Yes.&lt;/p&gt;&lt;p&gt;There is no requirement to choose only one.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core API
       |
       +----------------+
       |                |
   EF Core           Dapper
       |                |
       +-------+--------+
               |
          SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use EF Core for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Create
Update
Delete
Domain operations
Change tracking
Relationships&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use Dapper for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Reports
Complex queries
Read-heavy APIs
Stored procedures
Performance-sensitive queries&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;44. Hybrid Repository Example&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class EmployeeService
{
    private readonly EmployeeDbContext _context;
    private readonly IDbConnection _connection;

    public EmployeeService(
        EmployeeDbContext context,
        IDbConnection connection)
    {
        _context = context;
        _connection = connection;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can then use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// EF Core
await _context.Employees.AddAsync(employee);
await _context.SaveChangesAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// Dapper
var result = await _connection.QueryAsync&amp;lt;EmployeeReport&amp;gt;(
    reportSql);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;45. Advantages of Dapper&lt;/h1&gt;&lt;h2&gt;1. Lightweight&lt;/h2&gt;&lt;p&gt;Dapper has a small abstraction layer.&lt;/p&gt;&lt;h2&gt;2. High SQL Control&lt;/h2&gt;&lt;p&gt;Developers write the SQL directly.&lt;/p&gt;&lt;h2&gt;3. Excellent for Complex Queries&lt;/h2&gt;&lt;p&gt;SQL features such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CTE
JOIN
Window Functions
Stored Procedures
Temporary Tables
Aggregation
Database-specific features&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;can be used naturally.&lt;/p&gt;&lt;h2&gt;4. Good Performance&lt;/h2&gt;&lt;p&gt;Dapper avoids many ORM features that introduce additional processing.&lt;/p&gt;&lt;h2&gt;5. Easy to Integrate&lt;/h2&gt;&lt;p&gt;It works directly with ADO.NET connections and transactions.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;46. Disadvantages of Dapper&lt;/h1&gt;&lt;h2&gt;1. More SQL Code&lt;/h2&gt;&lt;p&gt;Developers must write SQL manually.&lt;/p&gt;&lt;h2&gt;2. No Change Tracking&lt;/h2&gt;&lt;p&gt;You must explicitly update the database.&lt;/p&gt;&lt;h2&gt;3. No Built-in Migrations&lt;/h2&gt;&lt;p&gt;A separate migration solution is required.&lt;/p&gt;&lt;h2&gt;4. Relationship Handling&lt;/h2&gt;&lt;p&gt;Complex relationships require additional SQL and mapping.&lt;/p&gt;&lt;h2&gt;5. Maintenance&lt;/h2&gt;&lt;p&gt;Large applications can end up with many SQL strings.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Repository
   |
   +-- SQL Query 1
   +-- SQL Query 2
   +-- SQL Query 3
   +-- SQL Query 4
   +-- SQL Query 5
   ...&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Maintaining these queries requires discipline.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;47. Advantages of EF Core&lt;/h1&gt;&lt;h2&gt;1. Productivity&lt;/h2&gt;&lt;p&gt;CRUD operations require relatively little code.&lt;/p&gt;&lt;h2&gt;2. LINQ&lt;/h2&gt;&lt;p&gt;You can query using strongly typed C# expressions.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees = await context.Employees
    .Where(x =&amp;gt; x.Salary &amp;gt; 50000)
    .OrderBy(x =&amp;gt; x.Name)
    .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;3. Change Tracking&lt;/h2&gt;&lt;p&gt;EF Core automatically tracks entity changes.&lt;/p&gt;&lt;h2&gt;4. Relationships&lt;/h2&gt;&lt;p&gt;Relationships are modeled naturally.&lt;/p&gt;&lt;h2&gt;5. Migrations&lt;/h2&gt;&lt;p&gt;Database schema changes can be managed through migrations.&lt;/p&gt;&lt;h2&gt;6. Strong Typing&lt;/h2&gt;&lt;p&gt;Many errors can be caught at compile time.&lt;/p&gt;&lt;h2&gt;7. Integration with .NET&lt;/h2&gt;&lt;p&gt;EF Core integrates naturally with:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core
Dependency Injection
LINQ
Async/Await
Configuration
Logging
Testing&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;48. Disadvantages of EF Core&lt;/h1&gt;&lt;h2&gt;1. Abstraction Overhead&lt;/h2&gt;&lt;p&gt;EF Core performs more work than a lightweight data-access library.&lt;/p&gt;&lt;h2&gt;2. Generated SQL&lt;/h2&gt;&lt;p&gt;Developers may not have direct control over every aspect of generated SQL.&lt;/p&gt;&lt;h2&gt;3. Learning Curve&lt;/h2&gt;&lt;p&gt;You need to understand:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DbContext
Change Tracking
LINQ
Relationships
Loading strategies
Migrations
Transactions
Query translation&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;4. N+1 Query Problems&lt;/h2&gt;&lt;p&gt;Poorly designed loading can result in many database queries.&lt;/p&gt;&lt;h2&gt;5. Complex SQL&lt;/h2&gt;&lt;p&gt;Some highly database-specific SQL can be more straightforward to express directly using SQL/Dapper.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;49. What is N+1 Query Problem?&lt;/h1&gt;&lt;p&gt;Suppose we load departments:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var departments =
    await context.Departments.ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then separately query employees for each department.&lt;/p&gt;&lt;p&gt;If there are 100 departments:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1 query
+
100 queries
=
101 queries&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is the N+1 problem.&lt;/p&gt;&lt;p&gt;It can cause serious performance issues.&lt;/p&gt;&lt;p&gt;Possible solutions include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Include()&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or projection:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;.Select(...)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or using an optimized SQL query/Dapper.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;50. EF Core Projection&lt;/h1&gt;&lt;p&gt;Instead of loading the entire entity:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var employees = await context.Employees
    .Select(x =&amp;gt; new EmployeeDto
    {
        Id = x.Id,
        Name = x.Name
    })
    .ToListAsync();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can generate SQL that selects only the required columns.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;51. Security Comparison&lt;/h1&gt;&lt;p&gt;Both Dapper and EF Core can be secure.&lt;/p&gt;&lt;p&gt;The developer must follow secure coding practices.&lt;/p&gt;&lt;p&gt;Important practices:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Parameterized queries
Least-privilege database accounts
Secrets management
Azure Key Vault
Managed Identity
Input validation
Authorization
HTTPS
Auditing&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Never put passwords directly into source code.&lt;/p&gt;&lt;p&gt;Bad:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Server=myserver;
User Id=admin;
Password=MyPassword123;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In Azure environments, consider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Managed Identity
        |
        v
Azure SQL&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and/or secure secret management where credentials are required.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;52. Azure SQL with EF Core&lt;/h1&gt;&lt;p&gt;A typical Azure architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Internet
   |
Azure Front Door / Application Gateway
   |
API Management
   |
ASP.NET Core API
   |
EF Core
   |
Azure SQL Database&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;53. Azure SQL with Dapper&lt;/h1&gt;&lt;p&gt;Dapper fits the same architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Internet
   |
API Management
   |
ASP.NET Core API
   |
Dapper
   |
Azure SQL Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The difference is primarily how the application accesses the database.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;54. Testing EF Core&lt;/h1&gt;&lt;p&gt;EF Core repositories/services can be tested using approaches such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Real SQL Server
SQL Server test container
SQLite where appropriate
Mocked abstractions in specific cases&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For realistic database behavior, integration tests against a real SQL Server-compatible database are often more representative than relying exclusively on mocks.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;55. Testing Dapper&lt;/h1&gt;&lt;p&gt;Dapper-based repositories are also commonly tested using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL Server test database
Testcontainers
Docker
Integration tests&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Integration Test
       |
       v
Dapper Repository
       |
       v
SQL Server Container&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This provides realistic SQL execution.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;56. Dependency Injection&lt;/h1&gt;&lt;p&gt;EF Core:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddDbContext&amp;lt;EmployeeDbContext&amp;gt;(
    options =&amp;gt;
        options.UseSqlServer(connectionString));&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Dapper:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddScoped&amp;lt;IDbConnection&amp;gt;(
    _ =&amp;gt; new SqlConnection(connectionString));&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In modern applications, it is also common to create a connection factory abstraction rather than injecting a raw connection everywhere.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;57. Which One Should You Choose?&lt;/h1&gt;&lt;p&gt;There is no universal answer.&lt;/p&gt;&lt;p&gt;Consider the application&#39;s requirements.&lt;/p&gt;&lt;h3&gt;Choose EF Core when:&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CRUD-heavy application
Domain-driven design
Complex entity relationships
Change tracking required
Rapid application development
Code-first migrations
LINQ-heavy application
Strong domain model&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Choose Dapper when:&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL-heavy application
Complex reporting
Existing stored procedures
Fine SQL control required
Read-heavy APIs
Database-specific SQL
Very lightweight data-access layer desired&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Choose both when:&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Business/domain operations -&amp;gt; EF Core

Complex queries/reports -&amp;gt; Dapper&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;58. Interview Question: Is Dapper faster than EF Core?&lt;/h1&gt;&lt;p&gt;A good interview answer:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Dapper generally has less abstraction and less ORM overhead, so it can perform very well for SQL-centric operations. However, it is not correct to say that Dapper is always faster. Actual performance depends on query design, indexing, database workload, network latency, result size, tracking, and application architecture. Properly optimized EF Core queries can also provide excellent performance.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;59. Interview Question: Does Dapper track changes?&lt;/h1&gt;&lt;p&gt;No.&lt;/p&gt;&lt;p&gt;Dapper does not provide EF Core-style change tracking.&lt;/p&gt;&lt;p&gt;The developer explicitly executes INSERT, UPDATE, or DELETE statements.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;60. Interview Question: Does EF Core always generate efficient SQL?&lt;/h1&gt;&lt;p&gt;No.&lt;/p&gt;&lt;p&gt;EF Core generates SQL based on the LINQ expression and model configuration, but developers still need to understand the SQL being generated.&lt;/p&gt;&lt;p&gt;For performance-critical queries, inspect:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Generated SQL
Execution Plan
Indexes
Query duration
Database waits
Logical reads&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;61. Interview Question: Can Dapper call stored procedures?&lt;/h1&gt;&lt;p&gt;Yes.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await connection.QueryAsync&amp;lt;Employee&amp;gt;(
    &quot;GetEmployees&quot;,
    parameters,
    commandType: CommandType.StoredProcedure);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;62. Interview Question: Can EF Core use stored procedures?&lt;/h1&gt;&lt;p&gt;Yes.&lt;/p&gt;&lt;p&gt;EF Core supports raw SQL and stored procedure-related database operations.&lt;/p&gt;&lt;p&gt;However, the exact API depends on whether you are querying entities, executing commands, or using EF Core&#39;s newer modification stored-procedure capabilities.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;63. Interview Question: Can Dapper perform transactions?&lt;/h1&gt;&lt;p&gt;Yes.&lt;/p&gt;&lt;p&gt;Dapper uses ADO.NET transaction support.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using var transaction =
    connection.BeginTransaction();&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;64. Interview Question: Can EF Core and Dapper use the Same Database?&lt;/h1&gt;&lt;p&gt;Yes.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                     SQL Server
                         |
             +-----------+-----------+
             |                       |
          EF Core                 Dapper
             |                       |
       Write operations         Read operations&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;They can coexist in the same application.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;65. Interview Question: Which is better for Microservices?&lt;/h1&gt;&lt;p&gt;Neither is universally better.&lt;/p&gt;&lt;p&gt;The decision should depend on the microservice&#39;s responsibilities.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
    |
    +-- EF Core&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;because it contains domain relationships and transactional business operations.&lt;/p&gt;&lt;p&gt;A:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Reporting Service
    |
    +-- Dapper&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;may be appropriate when it is primarily SQL/reporting focused.&lt;/p&gt;&lt;p&gt;Different microservices can use different data-access technologies.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;66. Recommended Enterprise Architecture&lt;/h1&gt;&lt;p&gt;For a large ASP.NET Core application, a practical architecture can be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Client
                      |
                      v
                API Management
                      |
                      v
                ASP.NET Core
                      |
              +-------+-------+
              |               |
          Commands          Queries
              |               |
              v               v
           EF Core          Dapper
              |               |
              +-------+-------+
                      |
                  SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important principle is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Select the data-access technology based on the use case rather than choosing a technology simply because it is popular.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;67. Dapper vs EF Core – Final Comparison&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Area&lt;/th&gt;&lt;th&gt;Dapper&lt;/th&gt;&lt;th&gt;EF Core&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Abstraction&lt;/td&gt;&lt;td&gt;Low&lt;/td&gt;&lt;td&gt;High&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SQL Control&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CRUD Productivity&lt;/td&gt;&lt;td&gt;Good&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Change Tracking&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;LINQ&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Relationships&lt;/td&gt;&lt;td&gt;Manual&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Migrations&lt;/td&gt;&lt;td&gt;External&lt;/td&gt;&lt;td&gt;Built-in&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Stored Procedures&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Supported&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Complex SQL&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Performance&lt;/td&gt;&lt;td&gt;Very good&lt;/td&gt;&lt;td&gt;Very good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Learning&lt;/td&gt;&lt;td&gt;Easier initially&lt;/td&gt;&lt;td&gt;More concepts&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Domain Modeling&lt;/td&gt;&lt;td&gt;Manual&lt;/td&gt;&lt;td&gt;Strong&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Read Models&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Write Models&lt;/td&gt;&lt;td&gt;Good&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Reporting&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Good/Excellent depending on query&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Large Enterprise Application&lt;/td&gt;&lt;td&gt;Very good&lt;/td&gt;&lt;td&gt;Very good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Hybrid Usage&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;68. Real-World Recommendation&lt;/h1&gt;&lt;p&gt;For a typical enterprise .NET application, don&#39;t think:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Dapper OR EF Core&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Think:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Where does each technology provide the most value?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                   ASP.NET Core
                         |
                 Application Layer
                         |
             +-----------+-----------+
             |                       |
        Business Commands          Queries
             |                       |
             v                       v
          EF Core                 Dapper
             |                       |
             +-----------+-----------+
                         |
                     SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EF Core can handle:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Aggregate updates
CRUD
Transactions
Relationships
Change tracking
Domain operations&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Dapper can handle:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Reports
Dashboards
Complex joins
Read models
Stored procedures
SQL-specific operations
Performance-sensitive queries&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;69. Final Conclusion&lt;/h1&gt;&lt;p&gt;Both &lt;strong&gt;Dapper and Entity Framework Core are excellent database-access technologies for .NET&lt;/strong&gt;, but they have different philosophies.&lt;/p&gt;&lt;h3&gt;Dapper&lt;/h3&gt;&lt;p&gt;Think:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;I want control over my SQL and a lightweight mapping layer.&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;EF Core&lt;/h3&gt;&lt;p&gt;Think:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;I want an ORM that manages entities, relationships, tracking, LINQ and database schema evolution.&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;For many enterprise applications, the best architecture is not necessarily choosing one exclusively.&lt;/p&gt;&lt;p&gt;A hybrid approach can be very effective:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             ASP.NET Core Application
                       |
          +------------+------------+
          |                         |
       EF Core                    Dapper
          |                         |
    Business/Data               Reporting/
    modifications               Read models
          |                         |
          +------------+------------+
                       |
                    SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The most important skill for a senior .NET developer is not simply knowing &lt;strong&gt;Dapper vs EF Core&lt;/strong&gt;, but understanding:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;How SQL is executed&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How connections are managed&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How transactions work&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How indexes affect queries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to avoid N+1 queries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to optimize EF Core queries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to write efficient Dapper SQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to analyze execution plans&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to handle concurrency&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to design repositories and services&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to secure database access&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to monitor production database performance&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Ultimately, &lt;strong&gt;database design, SQL quality, indexing, query patterns, and architecture usually have a much larger impact on application performance than simply selecting Dapper or EF Core.&lt;/strong&gt;&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Quick Interview Summary&lt;/h2&gt;&lt;p&gt;If an interviewer asks:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&quot;Dapper or EF Core — which one would you choose?&quot;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;A strong answer is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;I would choose based on the application&#39;s requirements. EF Core is useful when we need an ORM with LINQ, change tracking, relationships, migrations and strong domain modeling. Dapper is useful when we need fine-grained SQL control, lightweight data access, complex reporting queries or existing stored procedures. In an enterprise application, I can also use both — EF Core for transactional/domain operations and Dapper for optimized read models and reporting. I would validate the decision using actual query performance, execution plans and application requirements rather than assuming one technology is always faster.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This is structured to work as a &lt;strong&gt;technical blog article&lt;/strong&gt; and also as an &lt;strong&gt;interview-preparation reference&lt;/strong&gt;. If you want, I can next turn this into a &lt;strong&gt;Dapper vs EF Core Part-2 with a complete ASP.NET Core Web API project, SQL Server database, Repository + Unit of Work + CQRS, and production-ready code&lt;/strong&gt;.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/1700650658946733404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/1700650658946733404' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1700650658946733404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1700650658946733404'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/09/dapper-vs-entity-framework-core-in-net.html' title='Dapper vs Entity Framework Core in .NET – Complete End-to-End Guide'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTH1MpdY9pz1lcZvJXoMTOphr5HmuL7DxaEjFpcootL_7jcmpQnRUbGHLjfbDprvRtCVfbmAhX6-aLezUTf966mdhGXjuMsS9QgXJI_ao-97DGxM37PyiU0WWwz6dQe7CX6R5SeHfOAqDCJEji8afyxbqbvSsRNS-Cn0mav-Ivqi0Qk8VwFJArPZDVRVg/s72-w543-h295-c/DapperVsEFCore.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-5501672326634871478</id><published>2026-09-17T08:53:13.999+05:30</published><updated>2026-09-17T08:53:14.000+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="MongoDB with Microsoft Azure and ASP.NET Core"/><title type='text'>MongoDB with Microsoft Azure and ASP.NET Core – Complete End-to-End Guide with Real-Time E-Commerce Example</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggmCDatJdkPyU8-GfuuAe57v5eLBWp5vQjdYc3acSCsQ7ESRz-poiSL6lQ4ofVIWmZJxFuf63Efu79ftzbz5Cs3sU4TPFcEtWSRrX7M-9NcdM_LR4LVHMGg0gTWfEJDqcZe8Jzdnw3wXQ99SHHy1KvhKKSCjd4JfnkVr-Gq8OzupYFSD8lEkcwL6mdkqE/s1536/MangoDB.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;316&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggmCDatJdkPyU8-GfuuAe57v5eLBWp5vQjdYc3acSCsQ7ESRz-poiSL6lQ4ofVIWmZJxFuf63Efu79ftzbz5Cs3sU4TPFcEtWSRrX7M-9NcdM_LR4LVHMGg0gTWfEJDqcZe8Jzdnw3wXQ99SHHy1KvhKKSCjd4JfnkVr-Gq8OzupYFSD8lEkcwL6mdkqE/w475-h316/MangoDB.png&quot; width=&quot;475&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Introduction&lt;/h3&gt;&lt;p&gt;Modern applications often need a database that can handle:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Large volumes of data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Rapidly changing data structures&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;High read/write workloads&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Horizontal scalability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JSON-based application data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Microservices architectures&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Event-driven applications&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;MongoDB&lt;/strong&gt; is a popular NoSQL document database designed for these types of workloads.&lt;/p&gt;&lt;p&gt;When MongoDB is deployed using &lt;strong&gt;MongoDB Atlas on Microsoft Azure&lt;/strong&gt;, we can build a cloud-native architecture where:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular / React / Mobile
          |
          v
     Azure Front Door
          |
          v
 Azure API Management
          |
          v
 ASP.NET Core Web API
          |
          v
     MongoDB Atlas
       on Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;MongoDB Atlas is MongoDB&#39;s fully managed cloud database service, and Atlas supports Microsoft Azure as a cloud provider. (&lt;a href=&quot;https://www.mongodb.com/docs/atlas/cloud-providers-regions/?utm_source=chatgpt.com&quot; title=&quot;Cloud Providers and Regions - Atlas - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. What is MongoDB?&lt;/h1&gt;&lt;p&gt;MongoDB is a &lt;strong&gt;NoSQL document-oriented database&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Unlike SQL Server, where data is normally organized as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Database
   |
   +-- Tables
          |
          +-- Rows&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;MongoDB organizes data as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Database
   |
   +-- Collections
          |
          +-- Documents&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A MongoDB document looks similar to JSON:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;customerId&quot;: &quot;CUST1001&quot;,
  &quot;name&quot;: &quot;Ravi Kumar&quot;,
  &quot;email&quot;: &quot;ravi@example.com&quot;,
  &quot;city&quot;: &quot;Hyderabad&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Internally MongoDB stores documents using &lt;strong&gt;BSON&lt;/strong&gt;, which extends JSON with additional data types.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. SQL Server vs MongoDB&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;SQL Server&lt;/th&gt;&lt;th&gt;MongoDB&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Database&lt;/td&gt;&lt;td&gt;Database&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Table&lt;/td&gt;&lt;td&gt;Collection&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Row&lt;/td&gt;&lt;td&gt;Document&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Column&lt;/td&gt;&lt;td&gt;Field&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Primary Key&lt;/td&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;_id&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;JOIN&lt;/td&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;$lookup&lt;/code&gt; / application-level modeling&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Stored Procedure&lt;/td&gt;&lt;td&gt;Application/service logic&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Relational&lt;/td&gt;&lt;td&gt;Document-oriented&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Fixed schema commonly used&lt;/td&gt;&lt;td&gt;Flexible document schema&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SQL&lt;/td&gt;&lt;td&gt;MongoDB Query API&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;For example, SQL Server might contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customers
-------------------------
CustomerId
Name
Email
City&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;MongoDB could contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;_id&quot;: &quot;CUST1001&quot;,
  &quot;name&quot;: &quot;Ravi Kumar&quot;,
  &quot;email&quot;: &quot;ravi@example.com&quot;,
  &quot;city&quot;: &quot;Hyderabad&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;3. What is MongoDB Atlas?&lt;/h1&gt;&lt;p&gt;&lt;strong&gt;MongoDB Atlas&lt;/strong&gt; is the managed cloud service for MongoDB.&lt;/p&gt;&lt;p&gt;Instead of installing and maintaining MongoDB servers yourself, Atlas manages much of the database infrastructure.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Your Application
       |
       | MongoDB Driver
       |
       v
+----------------------+
|   MongoDB Atlas      |
|                      |
|  MongoDB Cluster     |
|                      |
|  Database            |
|    |                 |
|  Collection          |
|    |                 |
|  Documents           |
+----------------------+&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Atlas can deploy MongoDB clusters on Microsoft Azure. (&lt;a href=&quot;https://www.mongodb.com/docs/atlas/reference/microsoft-azure/?utm_source=chatgpt.com&quot; title=&quot;Microsoft Azure - Atlas - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;4. Why MongoDB on Azure?&lt;/h1&gt;&lt;p&gt;A common enterprise architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure
│
├── Azure Front Door
│
├── API Management
│
├── AKS / App Service
│       │
│       └── ASP.NET Core APIs
│
├── Key Vault
│
├── Application Insights
│
└── MongoDB Atlas
        │
        └── MongoDB Cluster&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Advantages include:&lt;/p&gt;&lt;h3&gt;Scalability&lt;/h3&gt;&lt;p&gt;MongoDB can scale horizontally using sharding.&lt;/p&gt;&lt;h3&gt;High availability&lt;/h3&gt;&lt;p&gt;Atlas supports replica-set based deployments, and Azure availability zones can be used for supported regions. (&lt;a href=&quot;https://www.mongodb.com/docs/atlas/reference/microsoft-azure/?utm_source=chatgpt.com&quot; title=&quot;Microsoft Azure - Atlas - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;h3&gt;Managed infrastructure&lt;/h3&gt;&lt;p&gt;Atlas manages much of the operational database infrastructure.&lt;/p&gt;&lt;h3&gt;Flexible document model&lt;/h3&gt;&lt;p&gt;Different documents can contain different fields when your application requires a flexible schema.&lt;/p&gt;&lt;h3&gt;Cloud integration&lt;/h3&gt;&lt;p&gt;Applications running on Azure can connect to MongoDB Atlas using standard or private networking approaches.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Real-Time Example&lt;/h1&gt;&lt;p&gt;Let&#39;s take an &lt;strong&gt;E-Commerce Order Management System&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Suppose customers place orders through an Angular application.&lt;/p&gt;&lt;p&gt;Architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                Customer
                   |
                   v
            Angular Application
                   |
                   v
           Azure API Management
                   |
                   v
          ASP.NET Core Web API
                   |
       +-----------+-----------+
       |                       |
       v                       v
 MongoDB Atlas             Azure Service Bus
       |                       |
       v                       v
 Orders Collection       Other Microservices&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Order Service needs to store:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Customer information&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Order information&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Products&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Quantity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Price&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Shipping address&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Payment status&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Order status&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Created date&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;MongoDB is well suited to representing this as a document.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. MongoDB Data Model&lt;/h1&gt;&lt;p&gt;Our database can be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ECommerceDB
   |
   +-- Orders
   |
   +-- Customers
   |
   +-- Products&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For this example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Database:
ECommerceDB

Collection:
Orders&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. Sample MongoDB Document&lt;/h1&gt;&lt;p&gt;An order could look like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;_id&quot;: &quot;ORD10001&quot;,
  &quot;customer&quot;: {
    &quot;customerId&quot;: &quot;CUST1001&quot;,
    &quot;name&quot;: &quot;Ravi Kumar&quot;,
    &quot;email&quot;: &quot;ravi@example.com&quot;
  },
  &quot;items&quot;: [
    {
      &quot;productId&quot;: &quot;P1001&quot;,
      &quot;productName&quot;: &quot;Laptop&quot;,
      &quot;quantity&quot;: 1,
      &quot;unitPrice&quot;: 75000
    },
    {
      &quot;productId&quot;: &quot;P1002&quot;,
      &quot;productName&quot;: &quot;Mouse&quot;,
      &quot;quantity&quot;: 2,
      &quot;unitPrice&quot;: 1500
    }
  ],
  &quot;shippingAddress&quot;: {
    &quot;street&quot;: &quot;Hitech City&quot;,
    &quot;city&quot;: &quot;Hyderabad&quot;,
    &quot;state&quot;: &quot;Telangana&quot;,
    &quot;country&quot;: &quot;India&quot;,
    &quot;postalCode&quot;: &quot;500081&quot;
  },
  &quot;paymentStatus&quot;: &quot;Paid&quot;,
  &quot;orderStatus&quot;: &quot;Confirmed&quot;,
  &quot;totalAmount&quot;: 78000,
  &quot;createdAt&quot;: &quot;2026-09-17T08:30:00Z&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice that customer, items, and shipping information can be represented naturally inside the document.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. MongoDB Terminology&lt;/h1&gt;&lt;p&gt;Understanding the terminology is important.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;MongoDB
   |
   +-- Database
          |
          +-- Collection
                  |
                  +-- Document
                          |
                          +-- Field&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For our application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;MongoDB
   |
   +-- ECommerceDB
          |
          +-- Orders
          |
          +-- Customers
          |
          +-- Products&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;9. Create MongoDB Atlas on Azure&lt;/h1&gt;&lt;p&gt;Go to MongoDB Atlas and create an Atlas organization/project.&lt;/p&gt;&lt;p&gt;When creating your cluster, select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Cloud Provider:
Microsoft Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then select an appropriate Azure region.&lt;/p&gt;&lt;p&gt;MongoDB currently lists Azure regions including &lt;strong&gt;Central India, South India and West India&lt;/strong&gt;, among many other supported Azure regions. Availability and cluster-tier support vary by region. (&lt;a href=&quot;https://www.mongodb.com/docs/atlas/reference/microsoft-azure/?utm_source=chatgpt.com&quot; title=&quot;Microsoft Azure - Atlas - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;For an application primarily running in India, an appropriate India region can reduce network latency, subject to your application&#39;s requirements and the cluster tier available there.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. Create Database User&lt;/h1&gt;&lt;p&gt;Create a MongoDB database user such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Username:
ecommerce-api-user&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use a strong password.&lt;/p&gt;&lt;p&gt;Do &lt;strong&gt;not&lt;/strong&gt; hard-code the password in source code.&lt;/p&gt;&lt;p&gt;Bad:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var connectionString =
    &quot;mongodb+srv://user:password@cluster.mongodb.net&quot;;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead, use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Key Vault
       |
       v
ASP.NET Core
       |
       v
MongoDB Atlas&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Configure Network Access&lt;/h1&gt;&lt;p&gt;Atlas provides network controls that determine which clients can connect.&lt;/p&gt;&lt;p&gt;For development, you may configure an appropriate IP access rule.&lt;/p&gt;&lt;p&gt;For production, consider private networking where appropriate.&lt;/p&gt;&lt;p&gt;A production architecture could be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure VNet
   |
   +-----------------------+
   |                       |
   v                       v
AKS                    Private Endpoint
   |                       |
   |                       v
   +--------------&amp;gt; MongoDB Atlas&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;MongoDB documents different connection approaches, including standard connections, peering and private endpoints depending on how the application network is configured. (&lt;a href=&quot;https://www.mongodb.com/docs/atlas/driver-connection/?utm_source=chatgpt.com&quot; title=&quot;Connect to a Cluster via Client Libraries - Atlas - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Get MongoDB Connection String&lt;/h1&gt;&lt;p&gt;From Atlas, obtain the application connection string.&lt;/p&gt;&lt;p&gt;It generally resembles:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;mongodb+srv://&amp;lt;username&amp;gt;:&amp;lt;password&amp;gt;@cluster0.xxxxx.mongodb.net/&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The MongoDB .NET driver uses the connection URI together with &lt;code inline=&quot;&quot;&gt;MongoClient&lt;/code&gt; to establish the connection. (&lt;a href=&quot;https://www.mongodb.com/docs/drivers/csharp/current/connect/connection-targets/?utm_source=chatgpt.com&quot; title=&quot;Choose a Connection Target - .NET/C# Driver - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Never publish your real connection string in GitHub or your blog.&lt;/strong&gt;&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. Create ASP.NET Core Web API&lt;/h1&gt;&lt;p&gt;Create the project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet new webapi -n Ecommerce.Api&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Move into the project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;cd Ecommerce.Api&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Install the MongoDB .NET driver:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package MongoDB.Driver&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;MongoDB provides an official .NET/C# driver for connecting .NET applications to MongoDB deployments including Atlas. (&lt;a href=&quot;https://www.mongodb.com/docs/drivers/csharp/current/get-started/?utm_source=chatgpt.com&quot; title=&quot;Get Started with the .NET/C# Driver - .NET/C# Driver - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. Configure appsettings.json&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;MongoDB&quot;: {
    &quot;ConnectionString&quot;: &quot;mongodb+srv://&amp;lt;username&amp;gt;:&amp;lt;password&amp;gt;@cluster0.xxxxx.mongodb.net/&quot;,
    &quot;DatabaseName&quot;: &quot;ECommerceDB&quot;,
    &quot;OrdersCollectionName&quot;: &quot;Orders&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For production, don&#39;t store the actual secret directly in &lt;code inline=&quot;&quot;&gt;appsettings.json&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Key Vault
      |
      v
ASP.NET Core Configuration
      |
      v
MongoDB Driver&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;MongoDB&#39;s own REST API tutorial demonstrates storing the MongoDB URI, database name, and collection name in application configuration. (&lt;a href=&quot;https://www.mongodb.com/docs/drivers/csharp/current/crud/restful-api-tutorial/?utm_source=chatgpt.com&quot; title=&quot;Create a RESTful API - .NET/C# Driver - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;15. Create MongoDB Settings Class&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Configuration/
    MongoDbSettings.cs&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class MongoDbSettings
{
    public string ConnectionString { get; set; } = string.Empty;

    public string DatabaseName { get; set; } = string.Empty;

    public string OrdersCollectionName { get; set; } = string.Empty;
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;16. Create Order Model&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

public class Order
{
    [BsonId]
    public string Id { get; set; } = string.Empty;

    public Customer Customer { get; set; } = new();

    public List&amp;lt;OrderItem&amp;gt; Items { get; set; } = new();

    public ShippingAddress ShippingAddress { get; set; } = new();

    public decimal TotalAmount { get; set; }

    public string PaymentStatus { get; set; } = string.Empty;

    public string OrderStatus { get; set; } = string.Empty;

    public DateTime CreatedAt { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;17. Customer Model&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Customer
{
    public string CustomerId { get; set; } = string.Empty;

    public string Name { get; set; } = string.Empty;

    public string Email { get; set; } = string.Empty;
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;18. OrderItem Model&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderItem
{
    public string ProductId { get; set; } = string.Empty;

    public string ProductName { get; set; } = string.Empty;

    public int Quantity { get; set; }

    public decimal UnitPrice { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;19. ShippingAddress Model&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class ShippingAddress
{
    public string Street { get; set; } = string.Empty;

    public string City { get; set; } = string.Empty;

    public string State { get; set; } = string.Empty;

    public string Country { get; set; } = string.Empty;

    public string PostalCode { get; set; } = string.Empty;
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Create MongoDB Service&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Services/
    OrderService.cs&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using MongoDB.Driver;

public class OrderService
{
    private readonly IMongoCollection&amp;lt;Order&amp;gt; _orders;

    public OrderService(IConfiguration configuration)
    {
        var connectionString =
            configuration[&quot;MongoDB:ConnectionString&quot;];

        var databaseName =
            configuration[&quot;MongoDB:DatabaseName&quot;];

        var collectionName =
            configuration[&quot;MongoDB:OrdersCollectionName&quot;];

        var client = new MongoClient(connectionString);

        var database = client.GetDatabase(databaseName);

        _orders = database.GetCollection&amp;lt;Order&amp;gt;(collectionName);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The basic MongoDB .NET architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;MongoDB Connection String
          |
          v
     MongoClient
          |
          v
      Database
          |
          v
     Collection
          |
          v
      Documents&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;21. Insert Order&lt;/h1&gt;&lt;p&gt;Add:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task CreateAsync(Order order)
{
    await _orders.InsertOneAsync(order);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Complete example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task CreateAsync(Order order)
{
    order.Id = $&quot;ORD{DateTime.UtcNow.Ticks}&quot;;

    order.CreatedAt = DateTime.UtcNow;

    await _orders.InsertOneAsync(order);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;MongoDB creates the document in the &lt;code inline=&quot;&quot;&gt;Orders&lt;/code&gt; collection.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Insert Sample Data&lt;/h1&gt;&lt;p&gt;You can insert this document:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;_id&quot;: &quot;ORD10001&quot;,
  &quot;customer&quot;: {
    &quot;customerId&quot;: &quot;CUST1001&quot;,
    &quot;name&quot;: &quot;Ravi Kumar&quot;,
    &quot;email&quot;: &quot;ravi@example.com&quot;
  },
  &quot;items&quot;: [
    {
      &quot;productId&quot;: &quot;P1001&quot;,
      &quot;productName&quot;: &quot;Laptop&quot;,
      &quot;quantity&quot;: 1,
      &quot;unitPrice&quot;: 75000
    },
    {
      &quot;productId&quot;: &quot;P1002&quot;,
      &quot;productName&quot;: &quot;Mouse&quot;,
      &quot;quantity&quot;: 2,
      &quot;unitPrice&quot;: 1500
    }
  ],
  &quot;shippingAddress&quot;: {
    &quot;street&quot;: &quot;Hitech City&quot;,
    &quot;city&quot;: &quot;Hyderabad&quot;,
    &quot;state&quot;: &quot;Telangana&quot;,
    &quot;country&quot;: &quot;India&quot;,
    &quot;postalCode&quot;: &quot;500081&quot;
  },
  &quot;totalAmount&quot;: 78000,
  &quot;paymentStatus&quot;: &quot;Paid&quot;,
  &quot;orderStatus&quot;: &quot;Confirmed&quot;,
  &quot;createdAt&quot;: &quot;2026-09-17T08:30:00Z&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;23. Retrieve All Orders&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;List&amp;lt;Order&amp;gt;&amp;gt; GetAllAsync()
{
    return await _orders
        .Find(_ =&amp;gt; true)
        .ToListAsync();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;.Find(_ =&amp;gt; true)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;means:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Return all documents.&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;24. Retrieve Order by ID&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;Order?&amp;gt; GetByIdAsync(string id)
{
    return await _orders
        .Find(x =&amp;gt; x.Id == id)
        .FirstOrDefaultAsync();
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;25. Search Orders by Customer&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;List&amp;lt;Order&amp;gt;&amp;gt; GetByCustomerAsync(
    string customerId)
{
    return await _orders
        .Find(x =&amp;gt; x.Customer.CustomerId == customerId)
        .ToListAsync();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This demonstrates querying a nested document property.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. Search Orders by City&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;List&amp;lt;Order&amp;gt;&amp;gt; GetByCityAsync(
    string city)
{
    return await _orders
        .Find(x =&amp;gt; x.ShippingAddress.City == city)
        .ToListAsync();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders/city/Hyderabad&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;27. Update an Order&lt;/h1&gt;&lt;p&gt;Suppose an order changes from:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Confirmed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Shipped&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can write:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task UpdateStatusAsync(
    string id,
    string status)
{
    var filter =
        Builders&amp;lt;Order&amp;gt;.Filter.Eq(x =&amp;gt; x.Id, id);

    var update =
        Builders&amp;lt;Order&amp;gt;.Update
            .Set(x =&amp;gt; x.OrderStatus, status);

    await _orders.UpdateOneAsync(
        filter,
        update);
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;28. Delete an Order&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task DeleteAsync(string id)
{
    await _orders.DeleteOneAsync(
        x =&amp;gt; x.Id == id);
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;29. Create Controller&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route(&quot;api/[controller]&quot;)]
public class OrdersController : ControllerBase
{
    private readonly OrderService _service;

    public OrdersController(OrderService service)
    {
        _service = service;
    }

    [HttpGet]
    public async Task&amp;lt;IActionResult&amp;gt; GetAll()
    {
        var orders = await _service.GetAllAsync();

        return Ok(orders);
    }

    [HttpGet(&quot;{id}&quot;)]
    public async Task&amp;lt;IActionResult&amp;gt; GetById(string id)
    {
        var order = await _service.GetByIdAsync(id);

        if (order == null)
            return NotFound();

        return Ok(order);
    }

    [HttpPost]
    public async Task&amp;lt;IActionResult&amp;gt; Create(Order order)
    {
        await _service.CreateAsync(order);

        return Ok(order);
    }

    [HttpDelete(&quot;{id}&quot;)]
    public async Task&amp;lt;IActionResult&amp;gt; Delete(string id)
    {
        await _service.DeleteAsync(id);

        return NoContent();
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;30. Register MongoDB Service&lt;/h1&gt;&lt;p&gt;In &lt;code inline=&quot;&quot;&gt;Program.cs&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddSingleton&amp;lt;OrderService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var app = builder.Build();

app.MapControllers();

app.Run();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A simplified architecture becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HTTP Request
     |
     v
OrdersController
     |
     v
OrderService
     |
     v
MongoClient
     |
     v
MongoDB Atlas
     |
     v
Orders Collection&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;31. POST Request Example&lt;/h1&gt;&lt;p&gt;Send:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders
Content-Type: application/json&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Request body:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;customer&quot;: {
    &quot;customerId&quot;: &quot;CUST1002&quot;,
    &quot;name&quot;: &quot;Suresh&quot;,
    &quot;email&quot;: &quot;suresh@example.com&quot;
  },
  &quot;items&quot;: [
    {
      &quot;productId&quot;: &quot;P2001&quot;,
      &quot;productName&quot;: &quot;Mobile Phone&quot;,
      &quot;quantity&quot;: 1,
      &quot;unitPrice&quot;: 45000
    }
  ],
  &quot;shippingAddress&quot;: {
    &quot;street&quot;: &quot;Madhapur&quot;,
    &quot;city&quot;: &quot;Hyderabad&quot;,
    &quot;state&quot;: &quot;Telangana&quot;,
    &quot;country&quot;: &quot;India&quot;,
    &quot;postalCode&quot;: &quot;500081&quot;
  },
  &quot;totalAmount&quot;: 45000,
  &quot;paymentStatus&quot;: &quot;Paid&quot;,
  &quot;orderStatus&quot;: &quot;Confirmed&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;32. GET Request&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Response:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;[
  {
    &quot;_id&quot;: &quot;ORD10001&quot;,
    &quot;customer&quot;: {
      &quot;customerId&quot;: &quot;CUST1001&quot;,
      &quot;name&quot;: &quot;Ravi Kumar&quot;
    },
    &quot;totalAmount&quot;: 78000,
    &quot;orderStatus&quot;: &quot;Confirmed&quot;
  }
]&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;33. MongoDB Query Example&lt;/h1&gt;&lt;p&gt;MongoDB shell query:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.find({
    &quot;customer.customerId&quot;: &quot;CUST1001&quot;
})&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Another example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.find({
    &quot;shippingAddress.city&quot;: &quot;Hyderabad&quot;
})&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Find paid orders:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.find({
    &quot;paymentStatus&quot;: &quot;Paid&quot;
})&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;34. MongoDB Operators&lt;/h1&gt;&lt;p&gt;MongoDB provides many query operators.&lt;/p&gt;&lt;h3&gt;Greater Than&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.find({
    &quot;totalAmount&quot;: {
        $gt: 50000
    }
})&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Less Than&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.find({
    &quot;totalAmount&quot;: {
        $lt: 50000
    }
})&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Greater Than or Equal&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.find({
    &quot;totalAmount&quot;: {
        $gte: 50000
    }
})&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;IN&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.find({
    &quot;orderStatus&quot;: {
        $in: [&quot;Confirmed&quot;, &quot;Shipped&quot;]
    }
})&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;35. MongoDB Indexes&lt;/h1&gt;&lt;p&gt;Indexes are extremely important for production applications.&lt;/p&gt;&lt;p&gt;Suppose we frequently search:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CustomerId&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create an index:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.createIndex({
    &quot;customer.customerId&quot;: 1
})&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For city:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.createIndex({
    &quot;shippingAddress.city&quot;: 1
})&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For order status:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.createIndex({
    &quot;orderStatus&quot;: 1
})&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application should create indexes based on actual query patterns rather than creating indexes on every field.&lt;/p&gt;&lt;p&gt;MongoDB&#39;s .NET driver documentation includes dedicated guidance for creating and managing indexes. (&lt;a href=&quot;https://www.mongodb.com/docs/drivers/csharp/current/?utm_source=chatgpt.com&quot; title=&quot;MongoDB .NET/C# Driver - .NET/C# Driver - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. Compound Index&lt;/h1&gt;&lt;p&gt;Suppose the application frequently queries:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer + Order Status&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.createIndex({
    &quot;customer.customerId&quot;: 1,
    &quot;orderStatus&quot;: 1
})&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can support queries such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.find({
    &quot;customer.customerId&quot;: &quot;CUST1001&quot;,
    &quot;orderStatus&quot;: &quot;Confirmed&quot;
})&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;37. MongoDB Aggregation&lt;/h1&gt;&lt;p&gt;Aggregation is one of MongoDB&#39;s powerful features.&lt;/p&gt;&lt;p&gt;Suppose we want:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Total sales by city&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.aggregate([
    {
        $group: {
            _id: &quot;$shippingAddress.city&quot;,
            totalSales: {
                $sum: &quot;$totalAmount&quot;
            }
        }
    }
])&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example result:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;[
  {
    &quot;_id&quot;: &quot;Hyderabad&quot;,
    &quot;totalSales&quot;: 2500000
  },
  {
    &quot;_id&quot;: &quot;Bangalore&quot;,
    &quot;totalSales&quot;: 1800000
  }
]&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;38. Aggregation Pipeline&lt;/h1&gt;&lt;p&gt;MongoDB aggregation works as a pipeline:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Documents
    |
    v
   $match
    |
    v
  $group
    |
    v
  $sort
    |
    v
 Result&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db.Orders.aggregate([
    {
        $match: {
            &quot;paymentStatus&quot;: &quot;Paid&quot;
        }
    },
    {
        $group: {
            _id: &quot;$shippingAddress.city&quot;,
            totalSales: {
                $sum: &quot;$totalAmount&quot;
            }
        }
    },
    {
        $sort: {
            totalSales: -1
        }
    }
])&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;39. Consuming MongoDB Data from Angular&lt;/h1&gt;&lt;p&gt;The frontend does &lt;strong&gt;not normally connect directly to MongoDB&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
   | HTTP
   v
ASP.NET Core Web API
   |
   | MongoDB Driver
   v
MongoDB Atlas&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Angular service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;@Injectable({
  providedIn: &#39;root&#39;
})
export class OrderService {

  private apiUrl = &#39;https://api.example.com/api/orders&#39;;

  constructor(private http: HttpClient) {}

  getOrders() {
    return this.http.get&amp;lt;any[]&amp;gt;(this.apiUrl);
  }

  getOrder(id: string) {
    return this.http.get&amp;lt;any&amp;gt;(
      `${this.apiUrl}/${id}`
    );
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Component:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;export class OrdersComponent {

  orders: any[] = [];

  constructor(
    private orderService: OrderService
  ) {}

  ngOnInit() {

    this.orderService
      .getOrders()
      .subscribe(data =&amp;gt; {
        this.orders = data;
      });

  }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;40. Complete Data Flow&lt;/h1&gt;&lt;p&gt;When the Angular application requests orders:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1. User opens Orders screen
             |
             v
2. Angular sends HTTP GET
             |
             v
3. Azure API Management
             |
             v
4. ASP.NET Core API
             |
             v
5. OrderService
             |
             v
6. MongoDB Driver
             |
             v
7. MongoDB Atlas
             |
             v
8. Orders Collection
             |
             v
9. MongoDB returns documents
             |
             v
10. ASP.NET Core returns JSON
             |
             v
11. Angular displays data&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;41. Production Azure Architecture&lt;/h1&gt;&lt;p&gt;For a larger enterprise system, the architecture could look like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Internet
                            |
                            v
                  +-------------------+
                  | Azure Front Door  |
                  +-------------------+
                            |
                            v
                  +-------------------+
                  | Azure API         |
                  | Management        |
                  +-------------------+
                            |
                            v
                  +-------------------+
                  | Azure Application |
                  | / AKS             |
                  +-------------------+
                            |
               +------------+------------+
               |                         |
               v                         v
        Order Microservice       Customer Service
               |                         |
               v                         v
        MongoDB Atlas              MongoDB Atlas
               |
               v
       Orders Collection&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Supporting services:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Key Vault
Azure Monitor
Application Insights
Azure Service Bus
Azure Container Registry
Azure DevOps&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;42. MongoDB with Microservices&lt;/h1&gt;&lt;p&gt;MongoDB works particularly well with microservice architectures when each service owns its data.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
     |
     v
OrderDB
     |
     +-- Orders

Customer Service
     |
     v
CustomerDB
     |
     +-- Customers

Product Service
     |
     v
ProductDB
     |
     +-- Products&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead of:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;All Microservices
       |
       v
One Shared Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;we can use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service --------&amp;gt; Order Database

Customer Service -----&amp;gt; Customer Database

Product Service ------&amp;gt; Product Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This helps maintain service ownership and reduces tight database coupling.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;43. MongoDB and Azure Service Bus&lt;/h1&gt;&lt;p&gt;Consider an order workflow:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer
   |
   v
Order API
   |
   v
MongoDB
   |
   v
Order Created
   |
   v
Azure Service Bus
   |
   +-----------&amp;gt; Inventory Service
   |
   +-----------&amp;gt; Payment Service
   |
   +-----------&amp;gt; Notification Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;eventType&quot;: &quot;OrderCreated&quot;,
  &quot;orderId&quot;: &quot;ORD10001&quot;,
  &quot;customerId&quot;: &quot;CUST1001&quot;,
  &quot;totalAmount&quot;: 78000
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;MongoDB stores the order state while Azure Service Bus can be used for asynchronous communication between services.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;44. Security Architecture&lt;/h1&gt;&lt;p&gt;A production architecture should avoid exposing database credentials.&lt;/p&gt;&lt;p&gt;Recommended:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Key Vault
       |
       | Secret
       v
ASP.NET Core
       |
       | TLS
       v
MongoDB Atlas&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead of:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;appsettings.json
       |
       +-- username
       +-- password&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Key Vault
   |
   v
Managed Identity
   |
   v
ASP.NET Core&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Also consider:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;TLS encryption&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Network restrictions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Private connectivity where appropriate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Least-privilege database users&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secret rotation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Application-level authentication and authorization&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Audit and monitoring&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;45. Azure Deployment Flow&lt;/h1&gt;&lt;p&gt;A typical CI/CD pipeline could be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer
    |
    v
Git Repository
    |
    v
Azure DevOps Pipeline
    |
    +---- Build
    |
    +---- Unit Tests
    |
    +---- Security Scan
    |
    +---- Docker Build
    |
    +---- Push to ACR
    |
    v
Azure AKS
    |
    v
ASP.NET Core Container
    |
    v
MongoDB Atlas&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;46. Docker Example&lt;/h1&gt;&lt;p&gt;A simplified Dockerfile:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-dockerfile&quot;&gt;FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base

WORKDIR /app

EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build

WORKDIR /src

COPY . .

RUN dotnet restore

RUN dotnet publish \
    -c Release \
    -o /app/publish

FROM base AS final

WORKDIR /app

COPY --from=build /app/publish .

ENTRYPOINT [&quot;dotnet&quot;, &quot;Ecommerce.Api.dll&quot;]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The container can then be deployed to Azure services such as AKS or another appropriate Azure hosting platform.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;47. Performance Considerations&lt;/h1&gt;&lt;p&gt;When using MongoDB in production, pay attention to:&lt;/p&gt;&lt;h3&gt;1. Indexes&lt;/h3&gt;&lt;p&gt;Create indexes for frequently executed queries.&lt;/p&gt;&lt;h3&gt;2. Document Size&lt;/h3&gt;&lt;p&gt;Avoid unnecessarily huge documents.&lt;/p&gt;&lt;h3&gt;3. Query Projection&lt;/h3&gt;&lt;p&gt;Retrieve only the fields you need when appropriate.&lt;/p&gt;&lt;h3&gt;4. Connection Management&lt;/h3&gt;&lt;p&gt;Reuse &lt;code inline=&quot;&quot;&gt;MongoClient&lt;/code&gt; rather than creating a new client for every request.&lt;/p&gt;&lt;h3&gt;5. Pagination&lt;/h3&gt;&lt;p&gt;Don&#39;t return millions of records in a single API request.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;GET /api/orders?page=1&amp;amp;pageSize=50&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;6. Monitoring&lt;/h3&gt;&lt;p&gt;Monitor:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CPU
Memory
Disk
Connections
Query performance
Latency
Operations per second&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;48. Pagination Example&lt;/h1&gt;&lt;p&gt;A simple MongoDB pagination query:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;List&amp;lt;Order&amp;gt;&amp;gt; GetPagedAsync(
    int page,
    int pageSize)
{
    return await _orders
        .Find(_ =&amp;gt; true)
        .Skip((page - 1) * pageSize)
        .Limit(pageSize)
        .ToListAsync();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;page = 1
pageSize = 20&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;MongoDB returns the first 20 documents.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;49. MongoDB Repository Pattern&lt;/h1&gt;&lt;p&gt;For larger applications, you can introduce a repository layer:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Controller
    |
    v
Application Service
    |
    v
Repository
    |
    v
MongoDB&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IOrderRepository
{
    Task&amp;lt;List&amp;lt;Order&amp;gt;&amp;gt; GetAllAsync();

    Task&amp;lt;Order?&amp;gt; GetByIdAsync(string id);

    Task CreateAsync(Order order);

    Task UpdateAsync(Order order);

    Task DeleteAsync(string id);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Implementation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderRepository : IOrderRepository
{
    private readonly IMongoCollection&amp;lt;Order&amp;gt; _orders;

    public OrderRepository(IMongoDatabase database)
    {
        _orders = database.GetCollection&amp;lt;Order&amp;gt;(&quot;Orders&quot;);
    }

    public async Task&amp;lt;List&amp;lt;Order&amp;gt;&amp;gt; GetAllAsync()
    {
        return await _orders
            .Find(_ =&amp;gt; true)
            .ToListAsync();
    }

    public async Task&amp;lt;Order?&amp;gt; GetByIdAsync(string id)
    {
        return await _orders
            .Find(x =&amp;gt; x.Id == id)
            .FirstOrDefaultAsync();
    }

    public async Task CreateAsync(Order order)
    {
        await _orders.InsertOneAsync(order);
    }

    public async Task UpdateAsync(Order order)
    {
        await _orders.ReplaceOneAsync(
            x =&amp;gt; x.Id == order.Id,
            order);
    }

    public async Task DeleteAsync(string id)
    {
        await _orders.DeleteOneAsync(
            x =&amp;gt; x.Id == id);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;50. Recommended Enterprise Project Structure&lt;/h1&gt;&lt;p&gt;A clean architecture could look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Ecommerce.Api
│
├── Controllers
│     └── OrdersController.cs
│
├── Models
│     ├── Order.cs
│     ├── Customer.cs
│     └── OrderItem.cs
│
├── DTOs
│     ├── CreateOrderRequest.cs
│     └── OrderResponse.cs
│
├── Services
│     └── OrderService.cs
│
├── Repositories
│     ├── IOrderRepository.cs
│     └── OrderRepository.cs
│
├── Configuration
│     └── MongoDbSettings.cs
│
├── Program.cs
│
└── appsettings.json&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;51. MongoDB vs SQL Server – When to Use Which?&lt;/h1&gt;&lt;p&gt;MongoDB can be useful when:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Data is naturally document-oriented&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Schema changes frequently&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;High-scale workloads require horizontal scaling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Application data is naturally represented as JSON-like documents&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Microservices need independently owned data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Flexible document structures are valuable&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;SQL Server can be preferable when:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Strong relational modeling is central&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Complex joins dominate the workload&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Existing enterprise applications rely heavily on relational features&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Strong transactional relational constraints are fundamental&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The choice should be based on workload and data requirements rather than simply choosing NoSQL because it is newer.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;52. Real-Time End-to-End Example&lt;/h1&gt;&lt;p&gt;Let&#39;s put everything together.&lt;/p&gt;&lt;p&gt;Suppose a customer purchases a laptop.&lt;/p&gt;&lt;h3&gt;Step 1 – Customer&lt;/h3&gt;&lt;p&gt;Customer submits:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Laptop
Quantity: 1
Price: ₹75,000&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 2 – Angular&lt;/h3&gt;&lt;p&gt;Angular sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 3 – Azure API Management&lt;/h3&gt;&lt;p&gt;APIM handles API gateway responsibilities.&lt;/p&gt;&lt;h3&gt;Step 4 – ASP.NET Core&lt;/h3&gt;&lt;p&gt;The Order Controller receives the request.&lt;/p&gt;&lt;h3&gt;Step 5 – Order Service&lt;/h3&gt;&lt;p&gt;The service validates the order.&lt;/p&gt;&lt;h3&gt;Step 6 – MongoDB&lt;/h3&gt;&lt;p&gt;The Order Service saves:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;_id&quot;: &quot;ORD10001&quot;,
  &quot;customer&quot;: {
    &quot;customerId&quot;: &quot;CUST1001&quot;
  },
  &quot;items&quot;: [
    {
      &quot;productId&quot;: &quot;P1001&quot;,
      &quot;quantity&quot;: 1,
      &quot;unitPrice&quot;: 75000
    }
  ],
  &quot;totalAmount&quot;: 75000,
  &quot;orderStatus&quot;: &quot;Confirmed&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 7 – Event&lt;/h3&gt;&lt;p&gt;The service publishes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreated&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;to Azure Service Bus.&lt;/p&gt;&lt;h3&gt;Step 8 – Inventory&lt;/h3&gt;&lt;p&gt;Inventory Service receives the event.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Laptop Stock
100 → 99&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 9 – Payment&lt;/h3&gt;&lt;p&gt;Payment Service processes payment.&lt;/p&gt;&lt;h3&gt;Step 10 – Notification&lt;/h3&gt;&lt;p&gt;Notification Service sends the order confirmation.&lt;/p&gt;&lt;p&gt;Complete flow:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
   v
Azure API Management
   |
   v
Order API
   |
   v
Order Service
   |
   +--------------------+
   |                    |
   v                    v
MongoDB Atlas       Azure Service Bus
   |                    |
   |             +------+------+
   |             |             |
   |             v             v
   |        Inventory      Payment
   |                         |
   |                         v
   |                    Notification
   |
   v
Order Status&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;53. Important Production Best Practices&lt;/h1&gt;&lt;h3&gt;Database&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use appropriate indexes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Design documents around access patterns.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid unnecessarily large documents.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitor slow queries.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use appropriate replication/high availability configuration.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Application&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Reuse &lt;code inline=&quot;&quot;&gt;MongoClient&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use asynchronous APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement pagination.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use DTOs rather than exposing internal models directly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validate incoming requests.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Security&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Never commit passwords.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use Azure Key Vault.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use least-privilege database accounts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Restrict network access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use encrypted connections.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Azure&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use Application Insights/Azure Monitor.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use managed identities where applicable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use private networking where appropriate.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use CI/CD.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use autoscaling based on workload requirements.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Architecture&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Keep database ownership with the appropriate service.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use Service Bus for asynchronous communication where appropriate.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Don&#39;t make every microservice directly access every other service&#39;s database.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;54. Complete Architecture Summary&lt;/h1&gt;&lt;p&gt;The complete enterprise architecture can be represented as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         USERS
                           |
                           v
                    Angular / Mobile
                           |
                           v
                  +-------------------+
                  | Azure Front Door  |
                  +-------------------+
                           |
                           v
                  +-------------------+
                  | Azure API         |
                  | Management        |
                  +-------------------+
                           |
                           v
                +-----------------------+
                | Azure AKS / App       |
                | Service               |
                +-----------------------+
                           |
                           v
                 ASP.NET Core Web API
                           |
              +------------+-------------+
              |                          |
              v                          v
       MongoDB Atlas              Azure Service Bus
              |                          |
              v                    +-----+------+
       ECommerceDB                 |            |
              |                    v            v
          Collections          Inventory     Payment
              |
       +------+------+
       |             |
    Orders        Customers
       |
       v
   Products
       
Supporting Services:
       
Azure Key Vault
Azure Monitor
Application Insights
Azure Container Registry
Azure DevOps&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;55. Conclusion&lt;/h1&gt;&lt;p&gt;MongoDB provides a document-oriented approach to data storage that can be particularly useful for modern cloud-native and microservices applications.&lt;/p&gt;&lt;p&gt;When combined with &lt;strong&gt;MongoDB Atlas on Microsoft Azure&lt;/strong&gt;, an ASP.NET Core application can follow a cloud architecture such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Frontend
   ↓
Azure API Management
   ↓
ASP.NET Core
   ↓
MongoDB Atlas on Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For an enterprise application, this can be extended with:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Front Door
       ↓
API Management
       ↓
AKS
       ↓
Microservices
       ↓
MongoDB Atlas
       +
Azure Service Bus
       +
Azure Key Vault
       +
Application Insights&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The official MongoDB .NET driver provides the APIs needed to connect to Atlas and perform CRUD, aggregation, indexing, and other database operations. (&lt;a href=&quot;https://www.mongodb.com/docs/drivers/csharp/current/get-started/?utm_source=chatgpt.com&quot; title=&quot;Get Started with the .NET/C# Driver - .NET/C# Driver - MongoDB Docs&quot;&gt;MongoDB&lt;/a&gt;)&lt;/p&gt;&lt;h3&gt;Useful official references&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.mongodb.com/docs/atlas/reference/microsoft-azure/?utm_source=chatgpt.com&quot;&gt;MongoDB Atlas on Microsoft Azure&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://www.mongodb.com/docs/drivers/csharp/current/?utm_source=chatgpt.com&quot;&gt;MongoDB .NET/C# Driver documentation&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://www.mongodb.com/docs/drivers/csharp/current/get-started/?utm_source=chatgpt.com&quot;&gt;.NET Driver – Get Started&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://www.mongodb.com/docs/atlas/driver-connection/?utm_source=chatgpt.com&quot;&gt;MongoDB Atlas Driver Connection Guide&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/5501672326634871478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/5501672326634871478' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/5501672326634871478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/5501672326634871478'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/09/mongodb-with-microsoft-azure-and-aspnet.html' title='MongoDB with Microsoft Azure and ASP.NET Core – Complete End-to-End Guide with Real-Time E-Commerce Example'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggmCDatJdkPyU8-GfuuAe57v5eLBWp5vQjdYc3acSCsQ7ESRz-poiSL6lQ4ofVIWmZJxFuf63Efu79ftzbz5Cs3sU4TPFcEtWSRrX7M-9NcdM_LR4LVHMGg0gTWfEJDqcZe8Jzdnw3wXQ99SHHy1KvhKKSCjd4JfnkVr-Gq8OzupYFSD8lEkcwL6mdkqE/s72-w475-h316-c/MangoDB.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-9208179068113817930</id><published>2026-09-16T08:31:06.303+05:30</published><updated>2026-09-16T08:31:06.304+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Terraform"/><title type='text'>Terraform: Complete Guide with Real-Time Azure and .NET Microservices Example -2026</title><content type='html'>&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2&gt;Introduction&lt;/h2&gt;&lt;p&gt;In modern cloud-based application development, manually creating and configuring infrastructure through the Azure Portal, AWS Console, or other cloud management portals can become difficult as applications grow.&lt;/p&gt;&lt;p&gt;A typical enterprise .NET application may require multiple infrastructure components such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Virtual Network&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Kubernetes Service (AKS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Container Registry (ACR)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure SQL Database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Service Bus&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure API Management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Application Gateway&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Application Insights&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Monitor&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Storage Accounts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Managed Identities&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Creating all these resources manually can be time-consuming and error-prone.&lt;/p&gt;&lt;p&gt;This is where &lt;strong&gt;Terraform&lt;/strong&gt; becomes extremely useful.&lt;/p&gt;&lt;p&gt;Terraform allows us to define infrastructure using code and manage that infrastructure consistently across different environments such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Development&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;QA&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;UAT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Production&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Terraform is an &lt;strong&gt;Infrastructure as Code (IaC)&lt;/strong&gt; tool developed by HashiCorp.&lt;/p&gt;&lt;p&gt;Instead of manually creating infrastructure, we describe what infrastructure we need in Terraform configuration files, and Terraform creates and manages those resources for us.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. What Is Terraform?&lt;/h1&gt;&lt;p&gt;Terraform is an Infrastructure as Code tool used to provision and manage infrastructure using configuration files.&lt;/p&gt;&lt;p&gt;For example, instead of opening the Azure Portal and manually creating a Resource Group, we can write:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_resource_group&quot; &quot;oneview&quot; {
  name     = &quot;rg-oneview-dev&quot;
  location = &quot;East US&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform interprets this configuration and creates the corresponding Azure Resource Group.&lt;/p&gt;&lt;p&gt;The basic idea is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform Configuration
        |
        v
    Terraform
        |
        v
   Azure Provider
        |
        v
 Azure Infrastructure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform can manage infrastructure from many platforms and services.&lt;/p&gt;&lt;p&gt;Examples include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Microsoft Azure&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Amazon Web Services&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Google Cloud&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kubernetes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;GitHub&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Databases&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring platforms&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SaaS applications&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;2. What Is Infrastructure as Code?&lt;/h1&gt;&lt;p&gt;Infrastructure as Code means managing infrastructure through machine-readable configuration files instead of manually configuring infrastructure.&lt;/p&gt;&lt;h3&gt;Traditional Approach&lt;/h3&gt;&lt;p&gt;Suppose we need to create an AKS cluster.&lt;/p&gt;&lt;p&gt;An engineer may manually:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Open Azure Portal&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create Resource Group&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create Virtual Network&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create Subnet&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create AKS&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configure networking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configure identity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configure permissions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configure monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Connect AKS with ACR&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This process can be repeated for every environment.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer
    |
    v
Azure Portal
    |
    +--&amp;gt; Resource Group
    +--&amp;gt; VNet
    +--&amp;gt; Subnet
    +--&amp;gt; AKS
    +--&amp;gt; ACR
    +--&amp;gt; SQL
    +--&amp;gt; Service Bus&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The problem is that manual configuration can introduce inconsistencies.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DEV  -&amp;gt; 2 AKS nodes
QA   -&amp;gt; 3 AKS nodes
UAT  -&amp;gt; 4 AKS nodes
PROD -&amp;gt; 6 AKS nodes&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Some differences may be intentional, while others may happen because of manual configuration.&lt;/p&gt;&lt;h3&gt;Infrastructure as Code Approach&lt;/h3&gt;&lt;p&gt;With Terraform:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform Code
      |
      v
Terraform Plan
      |
      v
Terraform Apply
      |
      v
Azure Infrastructure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The infrastructure configuration is stored in Git just like application source code.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Why Do We Need Terraform?&lt;/h1&gt;&lt;p&gt;Terraform solves several infrastructure management problems.&lt;/p&gt;&lt;h2&gt;3.1 Automation&lt;/h2&gt;&lt;p&gt;Infrastructure can be created automatically.&lt;/p&gt;&lt;h2&gt;3.2 Repeatability&lt;/h2&gt;&lt;p&gt;The same infrastructure configuration can be reused for multiple environments.&lt;/p&gt;&lt;h2&gt;3.3 Version Control&lt;/h2&gt;&lt;p&gt;Terraform files can be stored in Git.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Git
 |
 +-- Terraform Code
 |
 +-- Version History
 |
 +-- Pull Requests
 |
 +-- Code Reviews&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;3.4 Consistency&lt;/h2&gt;&lt;p&gt;Dev, QA, UAT, and Production can use standardized infrastructure modules.&lt;/p&gt;&lt;h2&gt;3.5 Disaster Recovery&lt;/h2&gt;&lt;p&gt;Infrastructure can be recreated from code when appropriate.&lt;/p&gt;&lt;h2&gt;3.6 Collaboration&lt;/h2&gt;&lt;p&gt;Multiple developers, architects, and DevOps engineers can work with the same infrastructure definition.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;4. Terraform Architecture&lt;/h1&gt;&lt;p&gt;The Terraform architecture can be represented as follows:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                Terraform Configuration
                         |
                         v
                  Terraform CLI
                         |
          +--------------+--------------+
          |                             |
          v                             v
   Terraform State                 Terraform Provider
                                        |
                                        v
                                  Azure APIs
                                        |
                                        v
                              Azure Infrastructure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The major components are:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Terraform CLI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform Configuration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Providers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Resources&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Variables&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Data Sources&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;State&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Backend&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Modules&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Outputs&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Let&#39;s understand each one.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Terraform Configuration Files&lt;/h1&gt;&lt;p&gt;Terraform configuration files generally use the &lt;code inline=&quot;&quot;&gt;.tf&lt;/code&gt; extension.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;main.tf
variables.tf
outputs.tf
provider.tf
network.tf
aks.tf
sql.tf
servicebus.tf&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform reads all &lt;code inline=&quot;&quot;&gt;.tf&lt;/code&gt; files in the working directory.&lt;/p&gt;&lt;p&gt;Therefore, we don&#39;t have to put everything into one file.&lt;/p&gt;&lt;p&gt;A large enterprise project can be organized into multiple files.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. HCL — HashiCorp Configuration Language&lt;/h1&gt;&lt;p&gt;Terraform configurations are generally written using &lt;strong&gt;HCL&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_resource_group&quot; &quot;oneview&quot; {
  name     = &quot;rg-oneview-dev&quot;
  location = &quot;East US&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The syntax is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;resource &quot;RESOURCE_TYPE&quot; &quot;RESOURCE_NAME&quot; {
    configuration
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In this example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;resource
   |
   +-- azurerm_resource_group
   |
   +-- oneview&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. Terraform Providers&lt;/h1&gt;&lt;p&gt;A provider allows Terraform to communicate with an external platform or service.&lt;/p&gt;&lt;p&gt;For Azure, we commonly use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;azurerm&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;terraform {
  required_providers {
    azurerm = {
      source  = &quot;hashicorp/azurerm&quot;
      version = &quot;~&amp;gt; 4.0&quot;
    }
  }
}

provider &quot;azurerm&quot; {
  features {}
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The provider acts as the bridge between Terraform and Azure.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
    |
    v
Azure Provider
    |
    v
Azure API
    |
    v
Azure Resources&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;8. Installing Terraform&lt;/h1&gt;&lt;p&gt;After installing Terraform, verify the installation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform version&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You should see the installed Terraform version.&lt;/p&gt;&lt;p&gt;For Azure development, Azure CLI is also useful.&lt;/p&gt;&lt;p&gt;Check Azure CLI:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az version&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Login to Azure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az login&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can then select the required Azure subscription.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az account set --subscription &quot;&amp;lt;subscription-id&amp;gt;&quot;&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;9. Real-Time Project Example&lt;/h1&gt;&lt;p&gt;Let&#39;s consider a real-world .NET application called:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;OneView Workforce Planning Platform&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Suppose OneView contains the following microservices:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Forecast Service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Workforce Service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Capacity Service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Hiring Service&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;A possible architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Users
                           |
                           v
                  Application Gateway
                           |
                           v
                  Azure API Management
                           |
          +----------------+----------------+
          |                |                |
          v                v                v
    Forecast API     Workforce API     Capacity API
          |                |                |
          +----------------+----------------+
                           |
                           v
                  Azure Service Bus
                           |
                           v
                     Hiring Service
                           |
                           v
                      Azure SQL&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Supporting Azure services might include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;AKS
ACR
Azure SQL
Service Bus
Key Vault
API Management
Application Gateway
Application Insights
Azure Monitor
Virtual Network
Managed Identity&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform can provision much of this infrastructure.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. Creating the Terraform Project&lt;/h1&gt;&lt;p&gt;Let&#39;s create the following project structure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;oneview-infrastructure/
│
├── provider.tf
├── variables.tf
├── resource-group.tf
├── network.tf
├── acr.tf
├── aks.tf
├── servicebus.tf
├── outputs.tf
└── terraform.tfvars&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a larger enterprise project, we can later convert these resources into reusable modules.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;11. Configure Azure Provider&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;provider.tf&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Add:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;terraform {
  required_version = &quot;&amp;gt;= 1.6.0&quot;

  required_providers {
    azurerm = {
      source  = &quot;hashicorp/azurerm&quot;
      version = &quot;~&amp;gt; 4.0&quot;
    }
  }
}

provider &quot;azurerm&quot; {
  features {}
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This tells Terraform that the project uses the Azure Resource Manager provider.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Create Azure Resource Group&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;resource-group.tf&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_resource_group&quot; &quot;oneview&quot; {
  name     = var.resource_group_name
  location = var.location

  tags = {
    Environment = var.environment
    Application = &quot;OneView&quot;
    ManagedBy   = &quot;Terraform&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead of hardcoding values, we are using variables.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. Terraform Variables&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;variables.tf&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;variable &quot;resource_group_name&quot; {
  description = &quot;Azure Resource Group name&quot;
  type        = string
}

variable &quot;location&quot; {
  description = &quot;Azure region&quot;
  type        = string
  default     = &quot;East US&quot;
}

variable &quot;environment&quot; {
  description = &quot;Deployment environment&quot;
  type        = string
  default     = &quot;dev&quot;
}

variable &quot;aks_node_count&quot; {
  description = &quot;Number of AKS nodes&quot;
  type        = number
  default     = 2
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;terraform.tfvars&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource_group_name = &quot;rg-oneview-dev&quot;
location            = &quot;East US&quot;
environment         = &quot;dev&quot;
aks_node_count      = 2&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;14. Terraform Init&lt;/h1&gt;&lt;p&gt;Navigate to the project directory:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;cd oneview-infrastructure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Run:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform init&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform downloads the required provider and initializes the working directory.&lt;/p&gt;&lt;p&gt;Typical flow:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform Project
       |
       v
terraform init
       |
       v
Download Providers
       |
       v
Initialized&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. Terraform Validate&lt;/h1&gt;&lt;p&gt;Before creating infrastructure, validate the configuration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform validate&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This checks the Terraform configuration for syntax and configuration errors.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. Terraform Format&lt;/h1&gt;&lt;p&gt;Terraform provides a formatting command:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform fmt&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This automatically formats Terraform files according to Terraform&#39;s standard formatting rules.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. Terraform Plan&lt;/h1&gt;&lt;p&gt;Now execute:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform plan&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform calculates what changes are required.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Plan: 1 to add, 0 to change, 0 to destroy.&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important point is:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;terraform plan previews changes.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;It is normally used before applying infrastructure changes.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;18. Terraform Apply&lt;/h1&gt;&lt;p&gt;To create the infrastructure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform apply&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform displays the planned changes and asks for confirmation.&lt;/p&gt;&lt;p&gt;Enter:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;yes&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform then creates the resources.&lt;/p&gt;&lt;p&gt;You can also use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform apply -auto-approve&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, automatic approval should be used carefully, especially for production environments.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;19. Creating Azure Virtual Network&lt;/h1&gt;&lt;p&gt;Now let&#39;s create networking.&lt;/p&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;network.tf&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_virtual_network&quot; &quot;oneview&quot; {
  name                = &quot;vnet-oneview&quot;
  location            = azurerm_resource_group.oneview.location
  resource_group_name = azurerm_resource_group.oneview.name
  address_space       = [&quot;10.10.0.0/16&quot;]

  tags = {
    Environment = var.environment
    Application = &quot;OneView&quot;
    ManagedBy   = &quot;Terraform&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create an AKS subnet:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_subnet&quot; &quot;aks&quot; {
  name                 = &quot;snet-aks&quot;
  resource_group_name  = azurerm_resource_group.oneview.name
  virtual_network_name = azurerm_virtual_network.oneview.name
  address_prefixes     = [&quot;10.10.1.0/24&quot;]
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Creating Azure Container Registry&lt;/h1&gt;&lt;p&gt;.NET microservices can be packaged as Docker containers.&lt;/p&gt;&lt;p&gt;Those container images can be stored in Azure Container Registry.&lt;/p&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;acr.tf&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_container_registry&quot; &quot;oneview&quot; {
  name                = &quot;acroneviewdev123&quot;
  resource_group_name = azurerm_resource_group.oneview.name
  location            = azurerm_resource_group.oneview.location

  sku = &quot;Standard&quot;

  admin_enabled = false

  tags = {
    Environment = var.environment
    Application = &quot;OneView&quot;
    ManagedBy   = &quot;Terraform&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application deployment flow becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET Source Code
       |
       v
Docker Build
       |
       v
Container Image
       |
       v
Azure Container Registry
       |
       v
AKS&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;21. Creating Azure Kubernetes Service&lt;/h1&gt;&lt;p&gt;Now let&#39;s create AKS.&lt;/p&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;aks.tf&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_kubernetes_cluster&quot; &quot;oneview&quot; {

  name                = &quot;aks-oneview-dev&quot;
  location            = azurerm_resource_group.oneview.location
  resource_group_name = azurerm_resource_group.oneview.name
  dns_prefix          = &quot;oneview-dev&quot;

  default_node_pool {
    name       = &quot;system&quot;
    node_count = var.aks_node_count
    vm_size    = &quot;Standard_D2s_v5&quot;
  }

  identity {
    type = &quot;SystemAssigned&quot;
  }

  tags = {
    Environment = var.environment
    Application = &quot;OneView&quot;
    ManagedBy   = &quot;Terraform&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform now understands that AKS belongs to the resource group.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Terraform Dependency Management&lt;/h1&gt;&lt;p&gt;Terraform automatically identifies many dependencies by analyzing resource references.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource_group_name = azurerm_resource_group.oneview.name&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform understands:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Resource Group
       |
       v
      AKS&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore, Terraform creates the Resource Group before AKS.&lt;/p&gt;&lt;p&gt;This is called an &lt;strong&gt;implicit dependency&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;23. Explicit Dependencies&lt;/h1&gt;&lt;p&gt;Sometimes Terraform cannot determine a dependency automatically.&lt;/p&gt;&lt;p&gt;In those cases, we can use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;depends_on = [
  azurerm_resource_group.oneview
]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;some_resource&quot; &quot;example&quot; {

  # configuration

  depends_on = [
    azurerm_resource_group.oneview
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It is generally preferable to rely on implicit dependencies whenever possible.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;24. Connect AKS with ACR&lt;/h1&gt;&lt;p&gt;AKS needs permission to pull container images from ACR.&lt;/p&gt;&lt;p&gt;We can assign the &lt;code inline=&quot;&quot;&gt;AcrPull&lt;/code&gt; role to the AKS kubelet identity.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_role_assignment&quot; &quot;aks_acr&quot; {

  principal_id = azurerm_kubernetes_cluster.oneview
    .kubelet_identity[0]
    .object_id

  role_definition_name = &quot;AcrPull&quot;

  scope = azurerm_container_registry.oneview.id

  skip_service_principal_aad_check = true
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The relationship is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Container Registry
          |
          | AcrPull
          v
         AKS
          |
          v
      Kubernetes
          |
          v
       .NET Pods&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;25. Azure Service Bus with Terraform&lt;/h1&gt;&lt;p&gt;In a microservices architecture, Azure Service Bus can be used for asynchronous communication.&lt;/p&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;servicebus.tf&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_servicebus_namespace&quot; &quot;oneview&quot; {

  name                = &quot;sb-oneview-dev&quot;
  location            = azurerm_resource_group.oneview.location
  resource_group_name = azurerm_resource_group.oneview.name

  sku = &quot;Standard&quot;

  tags = {
    Environment = var.environment
    Application = &quot;OneView&quot;
    ManagedBy   = &quot;Terraform&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create a topic:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_servicebus_topic&quot; &quot;forecast_events&quot; {

  name         = &quot;forecast-events&quot;
  namespace_id = azurerm_servicebus_namespace.oneview.id
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create a subscription:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &quot;azurerm_servicebus_subscription&quot; &quot;workforce&quot; {

  name               = &quot;workforce-subscription&quot;
  topic_id           = azurerm_servicebus_topic.forecast_events.id
  max_delivery_count = 10
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The communication flow becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Forecast Service
       |
       | ForecastCreated
       v
forecast-events
       |
       v
workforce-subscription
       |
       v
Workforce Service&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;26. Terraform Outputs&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;outputs.tf&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;output &quot;resource_group_name&quot; {
  value = azurerm_resource_group.oneview.name
}

output &quot;aks_cluster_name&quot; {
  value = azurerm_kubernetes_cluster.oneview.name
}

output &quot;acr_login_server&quot; {
  value = azurerm_container_registry.oneview.login_server
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After applying the configuration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform output&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform can display the output values.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. Terraform State&lt;/h1&gt;&lt;p&gt;One of the most important concepts in Terraform is &lt;strong&gt;state&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Terraform maintains information about infrastructure it manages.&lt;/p&gt;&lt;p&gt;The local state file is commonly:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;terraform.tfstate&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform Configuration
          |
          v
     Desired State
          |
          |
Terraform State
          |
          v
     Actual Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform uses state to understand relationships between configuration and infrastructure.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;28. Why Remote State Is Important&lt;/h1&gt;&lt;p&gt;In a team environment, storing state only on an individual developer&#39;s machine is usually not appropriate.&lt;/p&gt;&lt;p&gt;Imagine:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer A
     |
Developer B
     |
Developer C
     |
Azure DevOps
     |
     v
Shared Terraform State&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For Azure, an Azure Storage Account can be used as a remote backend.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;terraform {
  backend &quot;azurerm&quot; {
    resource_group_name  = &quot;rg-terraform-state&quot;
    storage_account_name = &quot;tfstateoneview&quot;
    container_name       = &quot;tfstate&quot;
    key                  = &quot;oneview-dev.tfstate&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The backend infrastructure should generally be bootstrapped separately before configuring the project to use it.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;29. Terraform State Locking&lt;/h1&gt;&lt;p&gt;Consider this situation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer A --------+
                    |
Developer B --------+----&amp;gt; Terraform State
                    |
CI/CD Pipeline -----+&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If multiple operations modify the same state concurrently, problems can occur.&lt;/p&gt;&lt;p&gt;Remote backends can provide state locking or concurrency controls, depending on the backend.&lt;/p&gt;&lt;p&gt;Therefore, enterprise Terraform implementations should carefully design:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Remote state&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;State isolation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Locking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access control&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Backup&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Recovery&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;30. Terraform Modules&lt;/h1&gt;&lt;p&gt;As Terraform projects become larger, we should avoid putting hundreds or thousands of lines into a single file.&lt;/p&gt;&lt;p&gt;Terraform supports reusable &lt;strong&gt;modules&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;terraform/
│
├── modules/
│   ├── network/
│   ├── aks/
│   ├── acr/
│   ├── sql/
│   ├── servicebus/
│   ├── keyvault/
│   └── apim/
│
└── environments/
    ├── dev/
    ├── qa/
    ├── uat/
    └── prod/&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A module can encapsulate a reusable infrastructure component.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;31. Example Terraform Module&lt;/h1&gt;&lt;p&gt;Suppose we have an AKS module:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;modules/
└── aks/
    ├── main.tf
    ├── variables.tf
    └── outputs.tf&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The root configuration can call it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;module &quot;aks&quot; {

  source = &quot;./modules/aks&quot;

  resource_group_name = azurerm_resource_group.oneview.name
  location            = var.location
  node_count          = var.aks_node_count
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The same module can then be reused by different environments.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;32. Multiple Environments&lt;/h1&gt;&lt;p&gt;A real enterprise application normally has:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DEV
QA
UAT
PROD&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can structure Terraform as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;environments/
│
├── dev/
│   ├── main.tf
│   └── terraform.tfvars
│
├── qa/
│   ├── main.tf
│   └── terraform.tfvars
│
├── uat/
│   ├── main.tf
│   └── terraform.tfvars
│
└── prod/
    ├── main.tf
    └── terraform.tfvars&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;h3&gt;Development&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;environment    = &quot;dev&quot;
aks_node_count = 2&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Production&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;environment    = &quot;prod&quot;
aks_node_count = 5&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The infrastructure module can remain reusable while environment-specific values are separated.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;33. Terraform Data Sources&lt;/h1&gt;&lt;p&gt;A Terraform resource creates or manages infrastructure.&lt;/p&gt;&lt;p&gt;A &lt;strong&gt;data source&lt;/strong&gt; reads information about existing infrastructure.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;data &quot;azurerm_resource_group&quot; &quot;shared&quot; {
  name = &quot;rg-shared-services&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can then access:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;data.azurerm_resource_group.shared.location&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is particularly useful when an enterprise already has shared infrastructure.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Existing Shared Infrastructure
             |
      +------+------+
      |             |
      v             v
   Shared VNet   Key Vault
      |
      v
Application Terraform&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform doesn&#39;t necessarily need to create every resource itself.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;34. Terraform Drift&lt;/h1&gt;&lt;p&gt;Drift occurs when infrastructure changes outside Terraform.&lt;/p&gt;&lt;p&gt;Suppose Terraform defines:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;AKS Node Count = 3&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But someone manually changes Azure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;AKS Node Count = 5&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Desired State = 3

Actual State = 5&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is infrastructure drift.&lt;/p&gt;&lt;p&gt;Running:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform plan&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;can reveal differences Terraform detects between the configuration/state and the infrastructure.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;35. Terraform Import&lt;/h1&gt;&lt;p&gt;Suppose an Azure resource already exists:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Portal
     |
     v
Existing Resource&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But Terraform doesn&#39;t currently manage it.&lt;/p&gt;&lt;p&gt;Terraform supports importing existing resources into Terraform state.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Existing Azure Resource
          |
          v
    Terraform Import
          |
          v
   Terraform State&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After import, you should ensure the Terraform configuration accurately represents the resource.&lt;/p&gt;&lt;p&gt;Modern Terraform also supports declarative import blocks for import workflows.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. Terraform Lifecycle&lt;/h1&gt;&lt;p&gt;Terraform provides lifecycle controls.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;lifecycle {
  prevent_destroy = true
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can be useful for resources where accidental destruction would be especially undesirable.&lt;/p&gt;&lt;p&gt;Another lifecycle option is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;lifecycle {
  ignore_changes = [
    tags
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Lifecycle rules should be used carefully because they can change Terraform&#39;s normal reconciliation behavior.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;37. Terraform with Docker&lt;/h1&gt;&lt;p&gt;Terraform and Docker solve different problems.&lt;/p&gt;&lt;h3&gt;Docker&lt;/h3&gt;&lt;p&gt;Docker packages applications into containers.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET Application
       |
       v
Docker Build
       |
       v
Container Image&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Terraform&lt;/h3&gt;&lt;p&gt;Terraform provisions infrastructure.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
    |
    +--&amp;gt; AKS
    +--&amp;gt; ACR
    +--&amp;gt; VNet
    +--&amp;gt; SQL
    +--&amp;gt; Service Bus&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Together:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET Application
       |
       v
Docker Image
       |
       v
ACR
       |
       v
AKS
       ^
       |
 Terraform&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;38. Terraform with Kubernetes&lt;/h1&gt;&lt;p&gt;Terraform and Kubernetes YAML also have different responsibilities.&lt;/p&gt;&lt;p&gt;Terraform can provision:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure
 |
 +--&amp;gt; VNet
 +--&amp;gt; AKS
 +--&amp;gt; ACR
 +--&amp;gt; SQL
 +--&amp;gt; Service Bus&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Kubernetes can manage:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;AKS
 |
 +--&amp;gt; Deployment
 +--&amp;gt; Service
 +--&amp;gt; Ingress
 +--&amp;gt; ConfigMap
 +--&amp;gt; Secret
 +--&amp;gt; HPA&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
    |
    v
Infrastructure
    |
    v
AKS
    |
    v
Kubernetes
    |
    v
.NET Microservices&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform can also manage Kubernetes resources, but organizations often separate infrastructure provisioning from application deployment for operational clarity.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;39. Terraform with Azure DevOps&lt;/h1&gt;&lt;p&gt;Terraform becomes especially powerful when integrated with CI/CD.&lt;/p&gt;&lt;p&gt;A typical pipeline looks like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer
    |
    v
Git Commit
    |
    v
Azure DevOps
    |
    +--&amp;gt; terraform fmt
    |
    +--&amp;gt; terraform validate
    |
    +--&amp;gt; terraform plan
    |
    v
Approval
    |
    v
terraform apply
    |
    v
Azure Infrastructure&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;40. Example Azure DevOps Terraform Pipeline&lt;/h1&gt;&lt;p&gt;A simplified example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:

- task: TerraformInstaller@1
  inputs:
    terraformVersion: &#39;latest&#39;

- script: |
    terraform init
  displayName: &#39;Terraform Init&#39;

- script: |
    terraform fmt -check
  displayName: &#39;Terraform Format Check&#39;

- script: |
    terraform validate
  displayName: &#39;Terraform Validate&#39;

- script: |
    terraform plan
  displayName: &#39;Terraform Plan&#39;

- script: |
    terraform apply -auto-approve
  displayName: &#39;Terraform Apply&#39;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A production pipeline should additionally consider:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure service connections&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secure authentication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Remote state&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Plan artifacts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Approval gates&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Environment protection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Separate plan/apply stages&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secret management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Policy checks&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;41. Terraform and Security&lt;/h1&gt;&lt;p&gt;Security is extremely important when managing infrastructure.&lt;/p&gt;&lt;p&gt;Never hardcode sensitive credentials:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;password = &quot;MyPassword123&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead, use mechanisms such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Managed Identity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Workload Identity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure DevOps secret variables&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secure pipeline variables&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Environment variables&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
    |
    v
Azure Identity
    |
    v
Key Vault
    |
    v
Secrets&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;42. Sensitive Variables&lt;/h1&gt;&lt;p&gt;Terraform supports sensitive variables.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;variable &quot;database_password&quot; {
  type      = string
  sensitive = true
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This helps prevent the value from being displayed in normal Terraform output.&lt;/p&gt;&lt;p&gt;However, marking a value as sensitive does not automatically remove it from Terraform state. Therefore, state itself must be securely stored and access-controlled.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;43. Terraform Workspaces&lt;/h1&gt;&lt;p&gt;Terraform supports workspaces.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform workspace new dev&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform workspace new qa&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform workspace new prod&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Select a workspace:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform workspace select dev&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Workspaces can be useful in certain scenarios, but for larger enterprise environments, separate environment directories and isolated remote states can sometimes provide clearer isolation.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;44. Important Terraform Commands&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Command&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform init&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Initializes Terraform&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform fmt&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Formats Terraform files&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform validate&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Validates configuration&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform plan&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Shows proposed changes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform apply&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Creates/updates infrastructure&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform destroy&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Destroys managed infrastructure&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform output&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Displays outputs&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform show&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Displays state/plan information&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform state list&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Lists resources in state&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform state show&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Shows a resource from state&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform providers&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Displays configured providers&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;terraform workspace list&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Lists workspaces&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;45. Terraform Destroy&lt;/h1&gt;&lt;p&gt;Terraform can also remove infrastructure that it manages.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform destroy&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Terraform shows the resources it intends to destroy.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Plan: 0 to add, 0 to change, 10 to destroy.&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After confirmation, Terraform removes the managed resources.&lt;/p&gt;&lt;p&gt;This command should be used with extreme care in production.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;46. Terraform vs ARM Templates vs Bicep&lt;/h1&gt;&lt;p&gt;For Azure architects, this is an important interview topic.&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Terraform&lt;/th&gt;&lt;th&gt;ARM Templates&lt;/th&gt;&lt;th&gt;Bicep&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Provider&lt;/td&gt;&lt;td&gt;HashiCorp&lt;/td&gt;&lt;td&gt;Microsoft&lt;/td&gt;&lt;td&gt;Microsoft&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;AWS&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;GCP&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Multi-cloud&lt;/td&gt;&lt;td&gt;Strong&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Syntax&lt;/td&gt;&lt;td&gt;HCL&lt;/td&gt;&lt;td&gt;JSON&lt;/td&gt;&lt;td&gt;Bicep&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Modules&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure Native&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CI/CD&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Bicep is an Azure-native Infrastructure as Code language.&lt;/p&gt;&lt;p&gt;Terraform is particularly attractive when an organization wants a common IaC approach across multiple providers or already has a mature Terraform ecosystem.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;47. Terraform vs Ansible&lt;/h1&gt;&lt;p&gt;Terraform and Ansible are also frequently compared.&lt;/p&gt;&lt;h3&gt;Terraform&lt;/h3&gt;&lt;p&gt;Primarily focuses on infrastructure provisioning.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
    |
    +--&amp;gt; Network
    +--&amp;gt; VM
    +--&amp;gt; AKS
    +--&amp;gt; Database
    +--&amp;gt; Storage&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Ansible&lt;/h3&gt;&lt;p&gt;Primarily focuses on configuration and automation.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Ansible
    |
    +--&amp;gt; Install packages
    +--&amp;gt; Configure servers
    +--&amp;gt; Deploy configuration
    +--&amp;gt; Execute operational tasks&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Simplified:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
    |
    v
Provision Infrastructure

Ansible
    |
    v
Configure / Automate Systems&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;48. Terraform vs Docker vs Kubernetes&lt;/h1&gt;&lt;p&gt;These three technologies solve different problems.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
    |
    v
Infrastructure Provisioning

Docker
    |
    v
Application Containerization

Kubernetes
    |
    v
Container Orchestration&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a .NET microservices platform:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
    |
    +--&amp;gt; Azure VNet
    +--&amp;gt; AKS
    +--&amp;gt; ACR
    +--&amp;gt; SQL
    +--&amp;gt; Service Bus
    |
    v
Docker
    |
    v
.NET Container
    |
    v
ACR
    |
    v
Kubernetes / AKS
    |
    v
Running Microservices&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;49. Complete OneView Terraform Architecture&lt;/h1&gt;&lt;p&gt;Let&#39;s put everything together.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Internet
                            |
                            v
                  Application Gateway
                            |
                            v
                   Azure API Management
                            |
                            v
                           AKS
                            |
          +-----------------+-----------------+
          |                 |                 |
          v                 v                 v
    Forecast API      Workforce API     Capacity API
          |                 |                 |
          +-----------------+-----------------+
                            |
                            v
                    Azure Service Bus
                            |
                            v
                     Hiring Service
                            |
                            v
                       Azure SQL


Supporting Azure Services
-------------------------

        +-----------------------------+
        | Azure Container Registry    |
        | Azure Key Vault             |
        | Application Insights        |
        | Azure Monitor               |
        | Managed Identity             |
        | Virtual Network             |
        +-----------------------------+

                 ^
                 |
              Terraform
                 |
                 v
          Infrastructure as Code&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;50. End-to-End Terraform Deployment Flow&lt;/h1&gt;&lt;p&gt;A complete enterprise deployment can look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                     Developer
                         |
                         v
                  Git Repository
                         |
                         v
                  Azure DevOps
                         |
            +------------+------------+
            |                         |
            v                         v
       Terraform                  Application
          Code                       Code
            |                         |
            v                         v
    terraform validate          Docker Build
            |                         |
            v                         v
      terraform plan               ACR
            |                         |
            v                         v
        Approval                    AKS
            |
            v
    terraform apply
            |
            v
      Azure Infrastructure
            |
     +------+------+------+
     |      |      |      |
     v      v      v      v
    VNet   AKS    SQL   Service Bus&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;51. Enterprise Terraform Repository Structure&lt;/h1&gt;&lt;p&gt;A production-style Terraform repository can look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;terraform-infrastructure/
│
├── modules/
│   │
│   ├── network/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   └── outputs.tf
│   │
│   ├── aks/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   └── outputs.tf
│   │
│   ├── acr/
│   ├── sql/
│   ├── servicebus/
│   ├── keyvault/
│   ├── apim/
│   └── monitoring/
│
├── environments/
│   │
│   ├── dev/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   └── terraform.tfvars
│   │
│   ├── qa/
│   │
│   ├── uat/
│   │
│   └── prod/
│
└── pipelines/
    ├── terraform-plan.yml
    └── terraform-apply.yml&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This structure provides:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Reusable Modules
       +
Environment Isolation
       +
CI/CD Automation
       +
Version Control&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;52. Terraform Best Practices&lt;/h1&gt;&lt;h2&gt;1. Use Remote State&lt;/h2&gt;&lt;p&gt;Use an appropriate remote backend instead of relying on local state for team-managed infrastructure.&lt;/p&gt;&lt;h2&gt;2. Use Modules&lt;/h2&gt;&lt;p&gt;Create reusable modules for common infrastructure components.&lt;/p&gt;&lt;h2&gt;3. Never Hardcode Secrets&lt;/h2&gt;&lt;p&gt;Use Key Vault, managed identities, and secure CI/CD mechanisms.&lt;/p&gt;&lt;h2&gt;4. Use Git&lt;/h2&gt;&lt;p&gt;Store Terraform code in source control.&lt;/p&gt;&lt;h2&gt;5. Review Terraform Plans&lt;/h2&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;terraform plan&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;before applying important infrastructure changes.&lt;/p&gt;&lt;h2&gt;6. Use Environment Isolation&lt;/h2&gt;&lt;p&gt;Separate development and production state appropriately.&lt;/p&gt;&lt;h2&gt;7. Use Naming Standards&lt;/h2&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;rg-oneview-dev
rg-oneview-qa
rg-oneview-uat
rg-oneview-prod&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;8. Use Resource Tags&lt;/h2&gt;&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;tags = {
  Application = &quot;OneView&quot;
  Environment = &quot;Production&quot;
  Owner       = &quot;PlatformTeam&quot;
  ManagedBy   = &quot;Terraform&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;9. Implement CI/CD&lt;/h2&gt;&lt;p&gt;Terraform should be integrated with your organization&#39;s DevOps process.&lt;/p&gt;&lt;h2&gt;10. Protect Production&lt;/h2&gt;&lt;p&gt;Production infrastructure should have:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Approval processes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Restricted permissions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Remote state&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secure credentials&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Policy validation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Backup/recovery processes&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;53. Terraform in a .NET Solution Architect&#39;s Architecture&lt;/h1&gt;&lt;p&gt;From a Solution Architect perspective, Terraform is not responsible for writing the .NET application.&lt;/p&gt;&lt;p&gt;Instead, it manages the infrastructure required to run the application.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                   .NET Application
                         |
                         v
                    Docker Image
                         |
                         v
                         ACR
                         |
                         v
                        AKS
                         |
       +-----------------+----------------+
       |                 |                |
       v                 v                v
 Forecast           Workforce         Capacity
 Service             Service           Service
       |                 |                |
       +-----------------+----------------+
                         |
                         v
                  Service Bus
                         |
                         v
                   Hiring Service
                         |
                         v
                    Azure SQL


Terraform manages:
-------------------

VNet
AKS
ACR
SQL
Service Bus
Key Vault
APIM
Application Gateway
Monitoring
Identity&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This separation is important.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Application code describes what the application does.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Terraform describes what infrastructure the application needs.&lt;/strong&gt;&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;54. Real-World Scenario&lt;/h1&gt;&lt;p&gt;Suppose a company wants to create a new production environment for OneView.&lt;/p&gt;&lt;p&gt;Without Terraform:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Engineer
   |
   +--&amp;gt; Create Resource Group
   +--&amp;gt; Create VNet
   +--&amp;gt; Create Subnets
   +--&amp;gt; Create ACR
   +--&amp;gt; Create AKS
   +--&amp;gt; Create SQL
   +--&amp;gt; Create Service Bus
   +--&amp;gt; Create Key Vault
   +--&amp;gt; Configure APIM
   +--&amp;gt; Configure Monitoring
   +--&amp;gt; Configure Permissions&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With Terraform:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform Repository
        |
        v
terraform plan
        |
        v
Approval
        |
        v
terraform apply
        |
        v
Azure Infrastructure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The infrastructure definition becomes repeatable, reviewable, and version controlled.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;55. Terraform Workflow — Summary&lt;/h1&gt;&lt;p&gt;The standard Terraform workflow is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             Write Terraform Code
                      |
                      v
              terraform init
                      |
                      v
             terraform fmt
                      |
                      v
           terraform validate
                      |
                      v
              terraform plan
                      |
                      v
                 Review
                      |
                      v
             terraform apply
                      |
                      v
             Azure Resources
                      |
                      v
             Monitor / Maintain
                      |
                      v
               Code Changes
                      |
                      v
             terraform plan&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;56. Important Terraform Concepts for Interviews&lt;/h1&gt;&lt;p&gt;If you are preparing for a .NET Solution Architect, Azure Architect, or DevOps interview, the following Terraform topics are particularly important:&lt;/p&gt;&lt;h3&gt;Terraform Fundamentals&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;What is Terraform?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is Infrastructure as Code?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is HCL?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is a provider?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is a resource?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is a data source?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is a variable?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is an output?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;State Management&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;What is Terraform state?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Why is state required?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is remote state?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is state locking?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is state drift?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How do you secure Terraform state?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Modules&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;What is a Terraform module?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Why use modules?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How do you create reusable modules?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How do you pass variables into modules?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How do modules expose outputs?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Enterprise&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Terraform with Azure DevOps&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform with AKS&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform with ACR&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform with Azure SQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform with Service Bus&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform with Key Vault&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform with API Management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform with Application Gateway&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform with Managed Identity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Terraform with Azure Monitor&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;57. Key Takeaways&lt;/h1&gt;&lt;p&gt;Terraform provides a consistent way to manage cloud infrastructure through code.&lt;/p&gt;&lt;p&gt;The most important concepts are:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
   |
   +--&amp;gt; Infrastructure as Code
   |
   +--&amp;gt; Providers
   |
   +--&amp;gt; Resources
   |
   +--&amp;gt; Variables
   |
   +--&amp;gt; Data Sources
   |
   +--&amp;gt; State
   |
   +--&amp;gt; Remote Backend
   |
   +--&amp;gt; Modules
   |
   +--&amp;gt; Outputs
   |
   +--&amp;gt; Plan
   |
   +--&amp;gt; Apply
   |
   +--&amp;gt; Destroy&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a modern .NET microservices application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Terraform
    |
    +--&amp;gt; Azure Infrastructure
             |
             +--&amp;gt; VNet
             +--&amp;gt; AKS
             +--&amp;gt; ACR
             +--&amp;gt; Azure SQL
             +--&amp;gt; Service Bus
             +--&amp;gt; Key Vault
             +--&amp;gt; APIM
             +--&amp;gt; Application Gateway
             +--&amp;gt; Monitoring&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application itself can then be built using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET
  |
  v
Docker
  |
  v
ACR
  |
  v
AKS&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore, Terraform plays an important role in creating a repeatable and automated cloud foundation for modern .NET applications.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Terraform is much more than a tool for creating Azure resources.&lt;/p&gt;&lt;p&gt;In an enterprise environment, Terraform can become an important part of the overall &lt;strong&gt;Cloud Infrastructure and DevOps strategy&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;A typical modern architecture can combine:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET
 +
Docker
 +
Kubernetes / AKS
 +
Azure
 +
Terraform
 +
Azure DevOps&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;where:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;.NET&lt;/strong&gt; develops the business applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Docker&lt;/strong&gt; packages applications into containers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;AKS&lt;/strong&gt; orchestrates containers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Azure&lt;/strong&gt; provides cloud infrastructure and managed services&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Terraform&lt;/strong&gt; provisions and manages infrastructure as code&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Azure DevOps&lt;/strong&gt; automates the CI/CD lifecycle&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The result is a repeatable, automated, version-controlled infrastructure platform that can support development through production environments.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Terraform + Azure + .NET + Kubernetes + DevOps&lt;/strong&gt; is therefore a powerful combination for building and operating modern enterprise applications.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/9208179068113817930/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/9208179068113817930' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/9208179068113817930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/9208179068113817930'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/09/terraform-complete-guide-with-real-time.html' title='Terraform: Complete Guide with Real-Time Azure and .NET Microservices Example -2026'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-2973116997971896545</id><published>2026-08-31T13:26:13.185+05:30</published><updated>2026-08-31T13:26:13.186+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure Red Hat OpenShift?"/><title type='text'>Azure Red Hat OpenShift (ARO) with .NET Core — Complete Guide with Real-Time Example</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq8CXoGhuWUmxCABp2RI1r7N1qpppuQtqO23veScouwfM2KOZLcqkyzqQl7uS2V7QmJEjJWfoIpiuGB4A0r60WwXNxQKZxPGZYwIF9vovzqtlSmpSCGJilIsN6of5rCac4hn4ZP1u6nTjTjVTy3Zq0rQ2zop_tgG-RXC_pj1GFnfPk2riSsmLcVpEI-u8/s1536/AzureOpenShift.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;329&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq8CXoGhuWUmxCABp2RI1r7N1qpppuQtqO23veScouwfM2KOZLcqkyzqQl7uS2V7QmJEjJWfoIpiuGB4A0r60WwXNxQKZxPGZYwIF9vovzqtlSmpSCGJilIsN6of5rCac4hn4ZP1u6nTjTjVTy3Zq0rQ2zop_tgG-RXC_pj1GFnfPk2riSsmLcVpEI-u8/w506-h329/AzureOpenShift.png&quot; width=&quot;506&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Important clarification:&lt;/strong&gt; Azure Red Hat OpenShift (ARO) is &lt;strong&gt;not mandatory for .NET Core/.NET applications&lt;/strong&gt;. It is an enterprise container platform that can be an excellent choice when an organization wants OpenShift/Kubernetes capabilities with Azure-managed infrastructure. Microsoft describes ARO as a fully managed OpenShift service jointly operated and supported by Microsoft and Red Hat. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot; title=&quot;Introduction to Azure Red Hat OpenShift - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt;1. What is Azure Red Hat OpenShift?&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Azure Red Hat OpenShift (ARO)&lt;/strong&gt; is Microsoft&#39;s managed &lt;strong&gt;Red Hat OpenShift&lt;/strong&gt; service running on Azure.&lt;/p&gt;&lt;p&gt;In simple terms:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET Application
       ↓
Docker Container
       ↓
OpenShift
       ↓
Azure Red Hat OpenShift
       ↓
Microsoft Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;OpenShift extends Kubernetes with additional enterprise capabilities and developer/operator tooling. ARO gives you those OpenShift capabilities without requiring your team to manually operate the underlying OpenShift control plane and infrastructure. Microsoft and Red Hat jointly engineer, operate, and support the service. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot; title=&quot;Introduction to Azure Red Hat OpenShift - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;ARO clusters are deployed into your Azure subscription, while Microsoft and Red Hat handle major platform-management responsibilities such as patching and monitoring of the managed cluster components. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot; title=&quot;Introduction to Azure Red Hat OpenShift - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. Why do we need OpenShift?&lt;/h1&gt;&lt;p&gt;Imagine an organization has &lt;strong&gt;50 microservices&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    API Gateway
                        |
        +---------------+---------------+
        |               |               |
   Order Service   Payment Service   Customer Service
        |               |               |
      SQL DB          SQL DB          Redis
        |
   Notification
      Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each service may have:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Different deployments&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Different versions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Different resource requirements&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Multiple replicas&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Health checks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Networking requirements&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secrets&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configuration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Logging&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Autoscaling&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Managing all of this manually becomes difficult.&lt;/p&gt;&lt;p&gt;A container orchestration platform can manage these workloads.&lt;/p&gt;&lt;p&gt;OpenShift provides Kubernetes-based orchestration plus additional platform capabilities. ARO packages this as a managed Azure service. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot; title=&quot;Introduction to Azure Red Hat OpenShift - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Is Azure OpenShift mandatory for .NET Core?&lt;/h1&gt;&lt;h2&gt;❌ No.&lt;/h2&gt;&lt;p&gt;This is one of the most important points.&lt;/p&gt;&lt;p&gt;A .NET application can run on:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;IIS
Azure App Service
Azure Container Apps
Azure Kubernetes Service
Azure Red Hat OpenShift
Windows Services
Linux
Docker
Virtual Machines
On-premises servers&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core Web API
       |
       +----&amp;gt; IIS
       |
       +----&amp;gt; Azure App Service
       |
       +----&amp;gt; Docker
       |
       +----&amp;gt; AKS
       |
       +----&amp;gt; ARO&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So &lt;strong&gt;.NET does not require OpenShift&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;The decision depends on your organization&#39;s architecture, operational requirements, existing platform standards, compliance requirements, and team expertise.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;4. Why would an enterprise choose ARO?&lt;/h1&gt;&lt;p&gt;ARO becomes particularly interesting when an organization wants:&lt;/p&gt;&lt;h3&gt;1. Kubernetes&lt;/h3&gt;&lt;p&gt;OpenShift is built on Kubernetes.&lt;/p&gt;&lt;h3&gt;2. Enterprise OpenShift platform&lt;/h3&gt;&lt;p&gt;Organizations that already standardize on Red Hat OpenShift can use ARO while keeping their workloads on Azure.&lt;/p&gt;&lt;h3&gt;3. Managed platform&lt;/h3&gt;&lt;p&gt;Microsoft and Red Hat manage important parts of the platform, reducing the amount of cluster administration required from application teams. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot; title=&quot;Introduction to Azure Red Hat OpenShift - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;h3&gt;4. Containerized microservices&lt;/h3&gt;&lt;p&gt;.NET applications can be packaged as containers and deployed as independent workloads.&lt;/p&gt;&lt;h3&gt;5. Scaling&lt;/h3&gt;&lt;p&gt;Multiple replicas of a service can run simultaneously.&lt;/p&gt;&lt;h3&gt;6. Security and identity&lt;/h3&gt;&lt;p&gt;ARO supports integration with Microsoft Entra ID and Kubernetes RBAC. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot; title=&quot;Introduction to Azure Red Hat OpenShift - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;h3&gt;7. CI/CD&lt;/h3&gt;&lt;p&gt;It can be integrated with enterprise CI/CD pipelines.&lt;/p&gt;&lt;h3&gt;8. Hybrid-cloud strategy&lt;/h3&gt;&lt;p&gt;OpenShift can be useful for organizations that want consistency between OpenShift environments across different infrastructure.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. ARO Architecture&lt;/h1&gt;&lt;p&gt;A simplified architecture looks like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                   Internet
                      |
                      ↓
                Azure Front Door
                      |
                      ↓
             Application Gateway
                      |
                      ↓
             Azure Red Hat OpenShift
              ┌───────────────────┐
              │    OpenShift      │
              │     Cluster       │
              │                   │
              │  ┌─────────────┐  │
              │  │   Router    │  │
              │  └──────┬──────┘  │
              │         │         │
              │  ┌──────┴──────┐  │
              │  │   Service   │  │
              │  └──────┬──────┘  │
              │         │         │
              │   ┌─────┴─────┐   │
              │   │   Pods    │   │
              │   │           │   │
              │   │ .NET API  │   │
              │   │ .NET API  │   │
              │   │ .NET API  │   │
              │   └───────────┘   │
              └───────────────────┘
                       |
                Azure SQL Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ARO provides single-tenant, high-availability OpenShift clusters on Azure. (&lt;a href=&quot;https://learn.microsoft.com/et-ee/azure/openshift/?utm_source=chatgpt.com&quot; title=&quot;Azure Red Hat OpenShift documentation - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. Important OpenShift Terminology&lt;/h1&gt;&lt;p&gt;Before deploying .NET, understand these concepts.&lt;/p&gt;&lt;h2&gt;Cluster&lt;/h2&gt;&lt;p&gt;The complete OpenShift environment.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ARO Cluster
   |
   +-- Control Plane
   |
   +-- Worker Nodes
   |
   +-- Networking
   |
   +-- Storage
   |
   +-- Operators&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Node&lt;/h2&gt;&lt;p&gt;A node is a machine that runs workloads.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker Node
   |
   +-- Pod
   +-- Pod
   +-- Pod&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Pod&lt;/h2&gt;&lt;p&gt;A Pod is the basic Kubernetes/OpenShift unit in which containers run.&lt;/p&gt;&lt;p&gt;For a simple .NET API:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pod
 |
 +-- .NET Container&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you have three replicas:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pod 1 → .NET API
Pod 2 → .NET API
Pod 3 → .NET API&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Deployment&lt;/h2&gt;&lt;p&gt;Defines how your application should be deployed.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;replicas: 3&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;means we want three instances.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Service&lt;/h2&gt;&lt;p&gt;Provides stable networking to the Pods.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             Service
                |
       +--------+--------+
       |        |        |
      Pod      Pod      Pod&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Route&lt;/h2&gt;&lt;p&gt;OpenShift Route exposes an application outside the cluster.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Internet
   |
   ↓
OpenShift Route
   |
   ↓
Service
   |
   ↓
Pods&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. Real-Time .NET Microservices Example&lt;/h1&gt;&lt;p&gt;Let&#39;s design an e-commerce application.&lt;/p&gt;&lt;p&gt;We have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;E-Commerce
    |
    +-- Product Service
    |
    +-- Order Service
    |
    +-- Payment Service
    |
    +-- Inventory Service
    |
    +-- Notification Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Suppose the Order Service is built using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core Web API
.NET 10
C#
Entity Framework Core
SQL Server
Docker&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We want:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 Client
                   |
                   ↓
              OpenShift
                   |
             Order Service
                   |
        +----------+----------+
        |          |          |
        ↓          ↓          ↓
    Payment    Inventory   Notification&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;8. Create the .NET API&lt;/h1&gt;&lt;p&gt;Create the project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet new webapi -n OrderService
cd OrderService&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example API:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

var app = builder.Build();

app.MapControllers();

app.Run();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Controller:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.AspNetCore.Mvc;

namespace OrderService.Controllers;

[ApiController]
[Route(&quot;api/orders&quot;)]
public class OrdersController : ControllerBase
{
    [HttpGet(&quot;{id}&quot;)]
    public IActionResult GetOrder(int id)
    {
        return Ok(new
        {
            OrderId = id,
            Product = &quot;Laptop&quot;,
            Quantity = 2,
            Status = &quot;Confirmed&quot;
        });
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders/1001&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;returns:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;orderId&quot;: 1001,
  &quot;product&quot;: &quot;Laptop&quot;,
  &quot;quantity&quot;: 2,
  &quot;status&quot;: &quot;Confirmed&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;9. Containerize the .NET Application&lt;/h1&gt;&lt;p&gt;OpenShift runs containerized workloads, so we can create a Docker image for our API.&lt;/p&gt;&lt;p&gt;Example &lt;code inline=&quot;&quot;&gt;Dockerfile&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-dockerfile&quot;&gt;FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build

WORKDIR /src

COPY . .

RUN dotnet restore

RUN dotnet publish -c Release \
    -o /app/publish \
    --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:10.0

WORKDIR /app

COPY --from=build /app/publish .

EXPOSE 8080

ENTRYPOINT [&quot;dotnet&quot;, &quot;OrderService.dll&quot;]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The basic flow becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;C# Code
   ↓
dotnet publish
   ↓
Docker Image
   ↓
Container Registry
   ↓
OpenShift
   ↓
Pod&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;10. Build the Docker Image&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;docker build -t orderservice:1.0 .&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Test locally:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;docker run -p 8080:8080 orderservice:1.0&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;http://localhost:8080/api/orders/1001&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Push Image to Container Registry&lt;/h1&gt;&lt;p&gt;In an enterprise environment, you could use a container registry such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Container Registry&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;docker tag orderservice:1.0 \
    myregistry.azurecr.io/orderservice:1.0

docker push \
    myregistry.azurecr.io/orderservice:1.0&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the image is available to OpenShift.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Deploy the .NET Application to OpenShift&lt;/h1&gt;&lt;p&gt;A Kubernetes/OpenShift Deployment could look like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: apps/v1
kind: Deployment
metadata:
  name: order-service
spec:
  replicas: 3

  selector:
    matchLabels:
      app: order-service

  template:
    metadata:
      labels:
        app: order-service

    spec:
      containers:
        - name: order-service

          image: myregistry.azurecr.io/orderservice:1.0

          ports:
            - containerPort: 8080

          resources:
            requests:
              cpu: &quot;250m&quot;
              memory: &quot;256Mi&quot;

            limits:
              cpu: &quot;500m&quot;
              memory: &quot;512Mi&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;replicas: 3&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;OpenShift will run three Pods.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             Order Service
                   |
       +-----------+-----------+
       |           |           |
       ↓           ↓           ↓
     Pod 1       Pod 2       Pod 3&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If one Pod becomes unavailable, the platform can maintain the desired replica state.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. Create an OpenShift Service&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: v1
kind: Service

metadata:
  name: order-service

spec:
  selector:
    app: order-service

  ports:
    - port: 80
      targetPort: 8080&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Service
   |
   +---- Pod 1
   |
   +---- Pod 2
   |
   +---- Pod 3&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application doesn&#39;t need to know which Pod receives the request.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. Expose the API using an OpenShift Route&lt;/h1&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: route.openshift.io/v1
kind: Route

metadata:
  name: order-service

spec:
  to:
    kind: Service
    name: order-service

  port:
    targetPort: 8080&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The resulting flow is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Client
  |
  | HTTPS
  ↓
OpenShift Route
  |
  ↓
Service
  |
  +--------+--------+
  |        |        |
 Pod 1    Pod 2    Pod 3&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. Deploy Using &lt;code inline=&quot;&quot;&gt;oc&lt;/code&gt;&lt;/h1&gt;&lt;p&gt;OpenShift provides the &lt;code inline=&quot;&quot;&gt;oc&lt;/code&gt; command-line client.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;oc login &amp;lt;your-cluster&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create/select a project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;oc new-project ecommerce&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Deploy:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;oc apply -f deployment.yaml&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;oc apply -f service.yaml&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Route:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;oc apply -f route.yaml&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Check Pods:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;oc get pods&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;NAME                             READY   STATUS
order-service-7c8d9f7c5d-abc12   1/1     Running
order-service-7c8d9f7c5d-def34   1/1     Running
order-service-7c8d9f7c5d-ghi56   1/1     Running&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;16. What Happens When Traffic Increases?&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Normal traffic
   ↓
3 Pods&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;During a festival sale:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Traffic increases
       ↓
Autoscaling
       ↓
5 Pods
       ↓
10 Pods&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;              Service
                 |
       +---------+---------+
       |         |         |
      Pod       Pod       Pod
       |         |         |
       +---------+---------+
                 |
            More traffic
                 ↓
          Additional Pods&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is one of the major advantages of container orchestration.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. Health Checks&lt;/h1&gt;&lt;p&gt;A production .NET application shouldn&#39;t simply be considered healthy because its process is running.&lt;/p&gt;&lt;p&gt;ASP.NET Core provides health-check support.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddHealthChecks();

var app = builder.Build();

app.MapHealthChecks(&quot;/health&quot;);

app.MapControllers();

app.Run();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /health&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;can be used by the platform to determine application health.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;18. Configure Kubernetes/OpenShift Probes&lt;/h1&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;livenessProbe:
  httpGet:
    path: /health
    port: 8080

  initialDelaySeconds: 10
  periodSeconds: 10

readinessProbe:
  httpGet:
    path: /health
    port: 8080

  initialDelaySeconds: 5
  periodSeconds: 5&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There are two important concepts:&lt;/p&gt;&lt;h3&gt;Liveness&lt;/h3&gt;&lt;p&gt;&quot;Is my application alive?&quot;&lt;/p&gt;&lt;h3&gt;Readiness&lt;/h3&gt;&lt;p&gt;&quot;Can my application receive traffic?&quot;&lt;/p&gt;&lt;p&gt;This distinction is extremely important in microservices.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;19. Configuration Management&lt;/h1&gt;&lt;p&gt;Don&#39;t hard-code:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var connectionString =
    &quot;Server=production-server;Database=Orders...&quot;;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead use configuration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var connectionString =
    builder.Configuration.GetConnectionString(&quot;OrdersDb&quot;);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Environment-specific values can then be supplied through OpenShift configuration mechanisms.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;env:
  - name: ASPNETCORE_ENVIRONMENT
    value: Production

  - name: ConnectionStrings__OrdersDb
    valueFrom:
      secretKeyRef:
        name: orders-db-secret
        key: connection-string&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Secrets&lt;/h1&gt;&lt;p&gt;Never put passwords directly into:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Dockerfile
Git repository
deployment.yaml
source code&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead use a Secret.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;oc create secret generic orders-db-secret \
  --from-literal=connection-string=&quot;YOUR-CONNECTION-STRING&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then the application can consume it through an environment variable.&lt;/p&gt;&lt;p&gt;For enterprise Azure environments, you can also integrate workloads with Azure identity capabilities rather than relying on long-lived credentials. ARO supports managed and workload identities. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/howto-create-openshift-cluster?utm_source=chatgpt.com&quot; title=&quot;Create an Azure Red Hat OpenShift cluster with managed identities - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;21. Scaling a .NET Microservice&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
Current replicas = 3&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can scale manually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;oc scale deployment/order-service --replicas=5&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
     |
     +-- Pod 1
     +-- Pod 2
     +-- Pod 3
     +-- Pod 4
     +-- Pod 5&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In production, autoscaling can be configured based on resource utilization and other supported metrics.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Rolling Deployment&lt;/h1&gt;&lt;p&gt;Suppose version 1.0 is running:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pod 1 → v1
Pod 2 → v1
Pod 3 → v1&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You deploy:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;v2&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The platform can perform a rolling update rather than stopping every instance simultaneously.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pod 1 → v2
Pod 2 → v1
Pod 3 → v1

Pod 1 → v2
Pod 2 → v2
Pod 3 → v1

Pod 1 → v2
Pod 2 → v2
Pod 3 → v2&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This helps reduce application downtime during deployments.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;23. Real-Time E-Commerce Architecture&lt;/h1&gt;&lt;p&gt;Now let&#39;s put everything together.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Customers
                             |
                             ↓
                    Azure Front Door
                             |
                             ↓
                    OpenShift Route
                             |
                             ↓
                      API Gateway
                             |
       +---------------------+---------------------+
       |                     |                     |
       ↓                     ↓                     ↓
 Order Service        Product Service       Customer Service
       |                     |                     |
       ↓                     ↓                     ↓
 Payment Service       Inventory Service      Redis
       |
       ↓
 Notification Service
       |
       ↓
 Azure Service Bus&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each microservice can have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET API
   ↓
Docker Image
   ↓
Container Registry
   ↓
OpenShift Deployment
   ↓
Pods
   ↓
Service
   ↓
Route&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;24. How .NET and OpenShift Work Together&lt;/h1&gt;&lt;p&gt;The relationship is important to understand:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET
 ↓
Application Framework

Docker
 ↓
Application Packaging

Kubernetes
 ↓
Container Orchestration

OpenShift
 ↓
Enterprise Kubernetes Platform

Azure Red Hat OpenShift
 ↓
Managed OpenShift on Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So ARO isn&#39;t replacing .NET.&lt;/p&gt;&lt;p&gt;It provides the &lt;strong&gt;platform on which your containerized .NET applications can run&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;25. OpenShift vs AKS&lt;/h1&gt;&lt;p&gt;This is a very common interview question.&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;AKS&lt;/th&gt;&lt;th&gt;Azure Red Hat OpenShift&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Technology&lt;/td&gt;&lt;td&gt;Kubernetes&lt;/td&gt;&lt;td&gt;OpenShift/Kubernetes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure managed service&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Microsoft&lt;/td&gt;&lt;td&gt;Managed service&lt;/td&gt;&lt;td&gt;Jointly operated with Red Hat&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Red Hat ecosystem&lt;/td&gt;&lt;td&gt;Not central&lt;/td&gt;&lt;td&gt;Strong&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;OpenShift tooling&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Kubernetes workloads&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;.NET support&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Enterprise OpenShift standard&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Best fit&lt;/td&gt;&lt;td&gt;Azure/Kubernetes environments&lt;/td&gt;&lt;td&gt;Organizations standardized on OpenShift&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Microsoft explicitly describes ARO as an Azure-managed OpenShift service jointly engineered, operated, and supported by Microsoft and Red Hat. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot; title=&quot;Introduction to Azure Red Hat OpenShift - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. OpenShift vs Azure App Service&lt;/h1&gt;&lt;p&gt;These solve different problems.&lt;/p&gt;&lt;h3&gt;Azure App Service&lt;/h3&gt;&lt;p&gt;Best when:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;I have a web application/API
        ↓
I want managed hosting
        ↓
I don&#39;t need Kubernetes&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;ARO&lt;/h3&gt;&lt;p&gt;Better suited when:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;I have many containerized services
        ↓
I need Kubernetes/OpenShift
        ↓
I need enterprise container orchestration&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Don&#39;t introduce OpenShift simply because you are using .NET.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. OpenShift vs Docker&lt;/h1&gt;&lt;p&gt;Another common misunderstanding:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Docker and OpenShift are not competitors in the same sense.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Docker packages the application.&lt;/p&gt;&lt;p&gt;OpenShift orchestrates containerized workloads.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET Application
       ↓
Docker Image
       ↓
OpenShift
       ↓
Pods
       ↓
Services
       ↓
Routes&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;28. Why .NET Applications Work Well on OpenShift&lt;/h1&gt;&lt;p&gt;Red Hat provides supported .NET container images and OpenShift guidance for .NET applications. For example, Red Hat&#39;s documentation describes &lt;code inline=&quot;&quot;&gt;dotnet&lt;/code&gt; SDK images and corresponding runtime/ASP.NET runtime image streams for OpenShift. (&lt;a href=&quot;https://docs.redhat.com/en/documentation/net/9.0/html/getting_started_with_.net_on_openshift_container_platform/con_overview-of-dotnet-on-openshift_getting-started-with-dotnet-on-openshift?utm_source=chatgpt.com&quot; title=&quot;Chapter 1. Overview | Getting started with .NET on OpenShift Container Platform | .NET | 9.0 | Red Hat Documentation&quot;&gt;Red Hat Documentation&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;That means an enterprise can standardize on:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET
+
Red Hat Enterprise Linux/UBI-based containers
+
OpenShift
+
Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET 10
   ↓
ASP.NET Core
   ↓
Red Hat UBI-based container
   ↓
OpenShift
   ↓
Azure Red Hat OpenShift&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Red Hat&#39;s current documentation includes guidance for running .NET 10 on OpenShift and provides &lt;code inline=&quot;&quot;&gt;dotnet&lt;/code&gt;, &lt;code inline=&quot;&quot;&gt;dotnet-runtime&lt;/code&gt;, and &lt;code inline=&quot;&quot;&gt;dotnet-aspnet&lt;/code&gt; image streams. (&lt;a href=&quot;https://docs.redhat.com/en/documentation/net/10.0/html-single/getting_started_with_.net_on_openshift_container_platform/getting_started_with_.net_on_openshift_container_platform?utm_source=chatgpt.com&quot; title=&quot;Getting started with .NET on OpenShift Container Platform | .NET | 10.0 | Red Hat Documentation&quot;&gt;Red Hat Documentation&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;29. CI/CD Pipeline&lt;/h1&gt;&lt;p&gt;A typical enterprise pipeline might look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer
    |
    ↓
Git Repository
    |
    ↓
CI Pipeline
    |
    +-- Build
    +-- Unit Tests
    +-- SonarQube
    +-- Security Scan
    +-- Docker Build
    |
    ↓
Container Registry
    |
    ↓
CD Pipeline
    |
    ↓
ARO
    |
    ↓
OpenShift Deployment
    |
    ↓
Pods&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;docker build -t orderservice:1.0 .
docker push myregistry.azurecr.io/orderservice:1.0

oc apply -f deployment.yaml&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In a real enterprise pipeline, image tags would normally be immutable version/build identifiers rather than simply &lt;code inline=&quot;&quot;&gt;latest&lt;/code&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;30. What Happens When a Pod Fails?&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service

Pod 1 → Running
Pod 2 → Running
Pod 3 → Failed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The desired state says:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;replicas = 3&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The orchestration layer can create another Pod:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pod 1 → Running
Pod 2 → Running
Pod 3 → Failed
Pod 4 → Starting&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Eventually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pod 1 → Running
Pod 2 → Running
Pod 4 → Running&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application therefore doesn&#39;t have to manually detect and recreate failed instances.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;31. Production Architecture&lt;/h1&gt;&lt;p&gt;A mature enterprise architecture could look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Internet
                       |
                       ↓
                Azure Front Door
                       |
                       ↓
              WAF / Load Balancing
                       |
                       ↓
              Azure Red Hat OpenShift
                       |
        +--------------+--------------+
        |              |              |
        ↓              ↓              ↓
   API Gateway      Services       Workers
        |              |              |
        |        +-----+-----+        |
        |        |     |     |        |
        ↓        ↓     ↓     ↓        ↓
     Orders   Payment Inventory Customer
        |
        ↓
  Azure Service Bus
        |
        ↓
 Notification Worker
        |
        ↓
 External Systems

Supporting services:

Azure SQL
Azure Cache for Redis
Azure Key Vault
Azure Container Registry
Application monitoring
Centralized logging
CI/CD&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;32. Is ARO Mandatory in Microservices?&lt;/h1&gt;&lt;p&gt;Again:&lt;/p&gt;&lt;h2&gt;❌ No.&lt;/h2&gt;&lt;p&gt;Microservices can run on:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;AKS
ARO
Azure Container Apps
Docker Compose
ECS
GKE
Self-managed Kubernetes
Virtual Machines
Other container platforms&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The correct architecture decision is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Business Requirements
        ↓
Non-functional Requirements
        ↓
Platform Requirements
        ↓
Choose Hosting Platform&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Not:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET
 ↓
Must use ARO ❌&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;33. When Should You Choose ARO?&lt;/h1&gt;&lt;p&gt;Choose ARO when your organization needs things such as:&lt;/p&gt;&lt;h3&gt;Enterprise OpenShift standardization&lt;/h3&gt;&lt;p&gt;Your company already uses OpenShift across environments.&lt;/p&gt;&lt;h3&gt;Kubernetes + OpenShift ecosystem&lt;/h3&gt;&lt;p&gt;You need OpenShift-specific platform capabilities and workflows.&lt;/p&gt;&lt;h3&gt;Managed Azure deployment&lt;/h3&gt;&lt;p&gt;You want OpenShift deployed into Azure while Microsoft and Red Hat handle important platform operations. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot; title=&quot;Introduction to Azure Red Hat OpenShift - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;h3&gt;Large microservices platform&lt;/h3&gt;&lt;p&gt;You have many containerized services and need centralized orchestration.&lt;/p&gt;&lt;h3&gt;Hybrid-cloud consistency&lt;/h3&gt;&lt;p&gt;You want an OpenShift-based application platform that can fit into broader hybrid-cloud strategies.&lt;/p&gt;&lt;h3&gt;Enterprise security/governance&lt;/h3&gt;&lt;p&gt;You need platform-level identity, RBAC, networking, policy, and operational controls.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;34. When Should You NOT Choose ARO?&lt;/h1&gt;&lt;p&gt;If you have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;One ASP.NET Core API&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and your requirement is simply:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Host the API&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ARO could be unnecessary complexity.&lt;/p&gt;&lt;p&gt;You might choose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure App Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;instead.&lt;/p&gt;&lt;p&gt;Likewise, if your team already has strong Azure Kubernetes expertise and doesn&#39;t need OpenShift, &lt;strong&gt;AKS may be a more natural choice&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;35. ARO Interview Question&lt;/h1&gt;&lt;h3&gt;Q: Is Azure Red Hat OpenShift mandatory for .NET Core?&lt;/h3&gt;&lt;h3&gt;Answer:&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;No. Azure Red Hat OpenShift is not mandatory for .NET Core applications. .NET applications can run on Azure App Service, Azure Container Apps, AKS, virtual machines, Docker, and other platforms. ARO is a managed OpenShift platform on Azure and is mainly selected when an organization needs enterprise OpenShift/Kubernetes capabilities, OpenShift standardization, hybrid-cloud consistency, or specific operational and governance requirements.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;That&#39;s the answer I&#39;d recommend giving in a .NET Architect interview.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. The Most Important Concept&lt;/h1&gt;&lt;p&gt;Remember this hierarchy:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             .NET
              │
              │ builds
              ↓
        ASP.NET Core API
              │
              │ packaged as
              ↓
          Docker Image
              │
              │ deployed to
              ↓
          OpenShift
              │
              │ hosted on
              ↓
       Azure Red Hat OpenShift
              │
              ↓
           Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;ARO is the hosting/orchestration platform—not a requirement of the .NET framework.&lt;/strong&gt;&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;37. Final Summary&lt;/h1&gt;&lt;p&gt;Azure Red Hat OpenShift combines &lt;strong&gt;Azure + Red Hat OpenShift + Kubernetes-based container orchestration + managed platform operations&lt;/strong&gt;. Microsoft says ARO provides fully managed OpenShift clusters, with Microsoft and Red Hat jointly engineering, operating, and supporting the service. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot; title=&quot;Introduction to Azure Red Hat OpenShift - Azure Red Hat OpenShift | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;For a .NET microservices application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET Microservice
       ↓
Docker Container
       ↓
Container Registry
       ↓
Azure Red Hat OpenShift
       ↓
OpenShift Deployment
       ↓
Pods
       ↓
Service
       ↓
Route
       ↓
Users&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The key takeaway is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Don&#39;t choose ARO because you use .NET. Choose ARO when your application&#39;s operational, architectural, enterprise, or organizational requirements justify an OpenShift platform.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Official references&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/intro-openshift?utm_source=chatgpt.com&quot;&gt;Azure Red Hat OpenShift — Microsoft Learn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/et-ee/azure/openshift/?utm_source=chatgpt.com&quot;&gt;Azure Red Hat OpenShift documentation&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.redhat.com/en/documentation/net/10.0/html-single/getting_started_with_.net_on_openshift_container_platform/getting_started_with_.net_on_openshift_container_platform?utm_source=chatgpt.com&quot;&gt;.NET on OpenShift — Red Hat documentation&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/openshift/create-cluster?utm_source=chatgpt.com&quot;&gt;Create an Azure Red Hat OpenShift cluster&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you&#39;re publishing this as a blog, a strong title would be &lt;strong&gt;“Azure Red Hat OpenShift (ARO) with .NET 10: Complete Guide to Deploying ASP.NET Core Microservices with Real-Time E-Commerce Example”&lt;/strong&gt;.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/2973116997971896545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/2973116997971896545' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/2973116997971896545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/2973116997971896545'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/azure-red-hat-openshift-aro-with-net.html' title='Azure Red Hat OpenShift (ARO) with .NET Core — Complete Guide with Real-Time Example'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq8CXoGhuWUmxCABp2RI1r7N1qpppuQtqO23veScouwfM2KOZLcqkyzqQl7uS2V7QmJEjJWfoIpiuGB4A0r60WwXNxQKZxPGZYwIF9vovzqtlSmpSCGJilIsN6of5rCac4hn4ZP1u6nTjTjVTy3Zq0rQ2zop_tgG-RXC_pj1GFnfPk2riSsmLcVpEI-u8/s72-w506-h329-c/AzureOpenShift.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-3117194860262762199</id><published>2026-08-31T12:59:32.286+05:30</published><updated>2026-08-31T12:59:32.286+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Worker Services in .NET"/><title type='text'>Worker Services in .NET — Complete Guide</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisVgstJYjBmH0NLGvM4Andb00I3Z4WVKaDmtIsvYaz7g4F2Qqkpw4xYPnvOpeNP1VnslrxaZ_5e___kGWTFsTM-o9MC-SJGoVDiytdKmOuXYap0HRyyHx7X8DgExGH_SPZdwFRVA2XVY3NVB8zhmRcmFmgm4vRyFSQ1D9PGv1CJ8tTGm-9ZfzXF3TAOrs/s1536/workerservices.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;311&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisVgstJYjBmH0NLGvM4Andb00I3Z4WVKaDmtIsvYaz7g4F2Qqkpw4xYPnvOpeNP1VnslrxaZ_5e___kGWTFsTM-o9MC-SJGoVDiytdKmOuXYap0HRyyHx7X8DgExGH_SPZdwFRVA2XVY3NVB8zhmRcmFmgm4vRyFSQ1D9PGv1CJ8tTGm-9ZfzXF3TAOrs/w468-h311/workerservices.png&quot; width=&quot;468&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2&gt;1. What is a Worker Service?&lt;/h2&gt;&lt;p&gt;A &lt;strong&gt;Worker Service&lt;/strong&gt; is a .NET application designed to run continuously in the background.&lt;/p&gt;&lt;p&gt;Unlike an ASP.NET Core Web API:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Web API
   ↓
HTTP Request
   ↓
Controller
   ↓
Business Logic
   ↓
HTTP Response&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A Worker Service generally works like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker Service
      ↓
Background Process
      ↓
Read Message / Timer / Event
      ↓
Business Logic
      ↓
Database / External API
      ↓
Continue Processing&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A Worker Service can run as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Windows Service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Linux systemd service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Docker container&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kubernetes Pod&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Container Apps&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure App Service background process in appropriate hosting models&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;VM-hosted process&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kubernetes CronJob for scheduled/batch work&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;2. Why do we need Worker Services?&lt;/h1&gt;&lt;p&gt;Consider an e-commerce application.&lt;/p&gt;&lt;p&gt;A customer places an order:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer
   ↓
Order API
   ↓
Create Order
   ↓
Return response&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But after creating the order, many things may need to happen:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Created
    │
    ├── Send Email
    ├── Generate Invoice
    ├── Update Inventory
    ├── Send Notification
    ├── Create Shipment
    └── Update Analytics&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Doing all of these inside the API request can make the API slow.&lt;/p&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 ┌───────────────┐
Customer ───────►│   Order API   │
                 └───────┬───────┘
                         │
                         │ OrderCreated
                         ▼
                 ┌───────────────┐
                 │ Message Queue │
                 └───────┬───────┘
                         │
          ┌──────────────┼──────────────┐
          ▼              ▼              ▼
   Email Worker    Inventory Worker  Invoice Worker&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is where Worker Services become extremely useful.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Worker Service vs BackgroundService&lt;/h1&gt;&lt;p&gt;These two terms are related but not exactly the same.&lt;/p&gt;&lt;h2&gt;Worker Service&lt;/h2&gt;&lt;p&gt;A &lt;strong&gt;Worker Service&lt;/strong&gt; is a .NET project/application template designed for long-running background workloads.&lt;/p&gt;&lt;p&gt;You can create one using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet new worker -n OrderProcessing.Worker&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It normally contains:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderProcessing.Worker
│
├── Program.cs
├── Worker.cs
└── appsettings.json&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;BackgroundService&lt;/h2&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt; is a base class provided by .NET for implementing long-running background work.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Worker : BackgroundService
{
    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            Console.WriteLine(&quot;Worker is running...&quot;);

            await Task.Delay(
                TimeSpan.FromSeconds(5),
                stoppingToken);
        }
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker Service
      │
      └── Hosting Model
             │
             └── BackgroundService
                    │
                    └── ExecuteAsync()&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;4. Basic Worker Service Architecture&lt;/h1&gt;&lt;p&gt;A typical Worker Service looks like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;┌─────────────────────────────────────┐
│         .NET Worker Service         │
│                                     │
│  Generic Host                       │
│       │                             │
│       ├── Dependency Injection      │
│       ├── Configuration             │
│       ├── Logging                   │
│       ├── Configuration             │
│       └── Hosted Services           │
│                  │                  │
│                  ▼                  │
│          BackgroundService          │
│                  │                  │
│                  ▼                  │
│           ExecuteAsync()            │
│                  │                  │
│                  ▼                  │
│          Business Processing        │
└─────────────────────────────────────┘&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;5. Creating a Worker Service&lt;/h1&gt;&lt;p&gt;Create the project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet new worker -n OrderProcessing.Worker&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Move into the project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;cd OrderProcessing.Worker&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Run it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet run&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The default template will create something similar to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Worker : BackgroundService
{
    private readonly ILogger&amp;lt;Worker&amp;gt; _logger;

    public Worker(ILogger&amp;lt;Worker&amp;gt; logger)
    {
        _logger = logger;
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            _logger.LogInformation(
                &quot;Worker running at: {time}&quot;,
                DateTimeOffset.Now);

            await Task.Delay(
                1000,
                stoppingToken);
        }
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;6. Understanding ExecuteAsync()&lt;/h1&gt;&lt;p&gt;This is the most important method.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;protected override async Task ExecuteAsync(
    CancellationToken stoppingToken)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Worker Service calls this method when the application starts.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application Starts
       ↓
Host Starts
       ↓
Worker Starts
       ↓
ExecuteAsync()
       ↓
while loop
       ↓
Background processing&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. Why CancellationToken is important&lt;/h1&gt;&lt;p&gt;Suppose your worker is running:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker
  ↓
Processing
  ↓
Processing
  ↓
Processing&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now Kubernetes sends a termination signal.&lt;/p&gt;&lt;p&gt;The worker should stop gracefully.&lt;/p&gt;&lt;p&gt;That&#39;s why we use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;CancellationToken stoppingToken&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;while (!stoppingToken.IsCancellationRequested)
{
    await ProcessOrderAsync(stoppingToken);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When cancellation occurs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Kubernetes
     ↓
SIGTERM
     ↓
CancellationToken
     ↓
Worker stops&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is especially important in production microservices.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. Real-Time Example — Order Processing Microservice&lt;/h1&gt;&lt;p&gt;Let&#39;s build a realistic architecture.&lt;/p&gt;&lt;p&gt;Imagine an e-commerce system:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer
   ↓
Order API
   ↓
Azure Service Bus
   ↓
Order Processing Worker
   ↓
Order Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The API doesn&#39;t need to process everything synchronously.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. Step 1 — Order API&lt;/h1&gt;&lt;p&gt;The API receives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Request:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;customerId&quot;: 1001,
  &quot;productId&quot;: 5001,
  &quot;quantity&quot;: 2
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The API creates the order.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[ApiController]
[Route(&quot;api/orders&quot;)]
public class OrdersController : ControllerBase
{
    [HttpPost]
    public async Task&amp;lt;IActionResult&amp;gt; CreateOrder(
        CreateOrderRequest request)
    {
        var order = new Order
        {
            Id = Guid.NewGuid(),
            CustomerId = request.CustomerId,
            ProductId = request.ProductId,
            Quantity = request.Quantity,
            Status = &quot;Pending&quot;
        };

        // Save order

        // Publish OrderCreated event

        return Accepted(order);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;return Accepted(order);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The API doesn&#39;t need to wait for the complete background processing.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. Step 2 — Create an Event&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderCreatedEvent
{
    public Guid OrderId { get; set; }

    public int CustomerId { get; set; }

    public int ProductId { get; set; }

    public int Quantity { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The API publishes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreatedEvent&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;to a message broker.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Service Bus&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
    │
    │ OrderCreatedEvent
    ▼
Azure Service Bus
    │
    ▼
Order Processing Worker&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Step 3 — Create Worker Service&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet new worker -n OrderProcessing.Worker&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Install the Azure Service Bus package:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Azure.Messaging.ServiceBus&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;12. Configure Service Bus&lt;/h1&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;appsettings.json&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;ServiceBus&quot;: {
    &quot;ConnectionString&quot;: &quot;YOUR_CONNECTION_STRING&quot;,
    &quot;QueueName&quot;: &quot;orders&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In production, don&#39;t put secrets directly into &lt;code inline=&quot;&quot;&gt;appsettings.json&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Managed Identity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Environment variables&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kubernetes Secrets&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;13. Create Worker&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderWorker : BackgroundService
{
    private readonly ILogger&amp;lt;OrderWorker&amp;gt; _logger;
    private readonly ServiceBusProcessor _processor;

    public OrderWorker(
        IConfiguration configuration,
        ILogger&amp;lt;OrderWorker&amp;gt; logger)
    {
        _logger = logger;

        var connectionString =
            configuration[&quot;ServiceBus:ConnectionString&quot;];

        var queueName =
            configuration[&quot;ServiceBus:QueueName&quot;];

        var client = new ServiceBusClient(connectionString);

        _processor = client.CreateProcessor(queueName);
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        _processor.ProcessMessageAsync += ProcessMessage;
        _processor.ProcessErrorAsync += ProcessError;

        await _processor.StartProcessingAsync(
            stoppingToken);

        try
        {
            await Task.Delay(
                Timeout.Infinite,
                stoppingToken);
        }
        catch (OperationCanceledException)
        {
            // Application shutting down
        }

        await _processor.StopProcessingAsync();
    }

    private async Task ProcessMessage(
        ProcessMessageEventArgs args)
    {
        var messageBody =
            args.Message.Body.ToString();

        _logger.LogInformation(
            &quot;Received Order: {Message}&quot;,
            messageBody);

        // Process order

        await args.CompleteMessageAsync(args.Message);
    }

    private Task ProcessError(
        ProcessErrorEventArgs args)
    {
        _logger.LogError(
            args.Exception,
            &quot;Error processing message&quot;);

        return Task.CompletedTask;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;14. Register Worker in Program.cs&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddHostedService&amp;lt;OrderWorker&amp;gt;();

var host = builder.Build();

host.Run();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is the key line:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddHostedService&amp;lt;OrderWorker&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It tells .NET:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Start this Worker when the application starts.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;15. Complete Processing Flow&lt;/h1&gt;&lt;p&gt;Now the entire flow becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             CUSTOMER
                 │
                 ▼
          ┌──────────────┐
          │   Order API  │
          └──────┬───────┘
                 │
                 │ Save Order
                 ▼
          ┌──────────────┐
          │ Azure SQL DB │
          └──────────────┘
                 │
                 │ Publish Event
                 ▼
        ┌───────────────────┐
        │  Azure Service Bus│
        │      orders       │
        └─────────┬─────────┘
                  │
                  ▼
        ┌─────────────────────┐
        │ Order Worker Service│
        └──────────┬──────────┘
                   │
          ┌────────┼─────────┐
          ▼        ▼         ▼
       Inventory  Payment   Notification&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is a very common microservice architecture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. Worker Service with Dependency Injection&lt;/h1&gt;&lt;p&gt;Don&#39;t put all business logic inside:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Worker.cs&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker
  │
  ▼
OrderProcessor
  │
  ├── OrderRepository
  ├── InventoryService
  ├── PaymentService
  └── NotificationService&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IOrderProcessor
{
    Task ProcessAsync(
        OrderCreatedEvent order,
        CancellationToken cancellationToken);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Implementation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderProcessor : IOrderProcessor
{
    private readonly ILogger&amp;lt;OrderProcessor&amp;gt; _logger;

    public OrderProcessor(
        ILogger&amp;lt;OrderProcessor&amp;gt; logger)
    {
        _logger = logger;
    }

    public async Task ProcessAsync(
        OrderCreatedEvent order,
        CancellationToken cancellationToken)
    {
        _logger.LogInformation(
            &quot;Processing Order {OrderId}&quot;,
            order.OrderId);

        // Business logic

        await Task.CompletedTask;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Register:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddScoped&amp;lt;IOrderProcessor, OrderProcessor&amp;gt;();
builder.Services.AddHostedService&amp;lt;OrderWorker&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;17. Important Issue — Scoped Services&lt;/h1&gt;&lt;p&gt;This is a very important interview question.&lt;/p&gt;&lt;p&gt;A Worker Service itself is generally effectively singleton-like because it lives for the lifetime of the host.&lt;/p&gt;&lt;p&gt;But services such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DbContext
Repository
UnitOfWork&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;are usually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Scoped&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You shouldn&#39;t inject a scoped &lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt; directly into a long-lived singleton worker.&lt;/p&gt;&lt;p&gt;Instead use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;IServiceScopeFactory&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderWorker : BackgroundService
{
    private readonly IServiceScopeFactory _scopeFactory;

    public OrderWorker(
        IServiceScopeFactory scopeFactory)
    {
        _scopeFactory = scopeFactory;
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            using var scope =
                _scopeFactory.CreateScope();

            var processor =
                scope.ServiceProvider
                    .GetRequiredService&amp;lt;IOrderProcessor&amp;gt;();

            await processor.ProcessAsync(
                stoppingToken);

            await Task.Delay(
                TimeSpan.FromSeconds(10),
                stoppingToken);
        }
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This creates a new DI scope for each processing cycle.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;18. Worker + Entity Framework Core&lt;/h1&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderProcessor : IOrderProcessor
{
    private readonly ApplicationDbContext _db;

    public OrderProcessor(ApplicationDbContext db)
    {
        _db = db;
    }

    public async Task ProcessAsync(
        CancellationToken cancellationToken)
    {
        var orders = await _db.Orders
            .Where(x =&amp;gt; x.Status == &quot;Pending&quot;)
            .ToListAsync(cancellationToken);

        foreach (var order in orders)
        {
            order.Status = &quot;Processed&quot;;
        }

        await _db.SaveChangesAsync(
            cancellationToken);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Register:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddDbContext&amp;lt;ApplicationDbContext&amp;gt;(
    options =&amp;gt;
        options.UseSqlServer(
            builder.Configuration.GetConnectionString(
                &quot;DefaultConnection&quot;)));&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;19. Worker Service for Scheduled Processing&lt;/h1&gt;&lt;p&gt;Workers aren&#39;t limited to queues.&lt;/p&gt;&lt;p&gt;You can also execute tasks periodically.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class ReportWorker : BackgroundService
{
    private readonly ILogger&amp;lt;ReportWorker&amp;gt; _logger;

    public ReportWorker(
        ILogger&amp;lt;ReportWorker&amp;gt; logger)
    {
        _logger = logger;
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        using var timer = new PeriodicTimer(
            TimeSpan.FromMinutes(5));

        while (await timer.WaitForNextTickAsync(
            stoppingToken))
        {
            await GenerateReportAsync(
                stoppingToken);
        }
    }

    private async Task GenerateReportAsync(
        CancellationToken cancellationToken)
    {
        _logger.LogInformation(
            &quot;Generating report at {Time}&quot;,
            DateTimeOffset.Now);

        await Task.CompletedTask;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Worker Service for File Processing&lt;/h1&gt;&lt;p&gt;Another real-world example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer uploads CSV
       ↓
Blob Storage
       ↓
Queue
       ↓
Worker
       ↓
Read CSV
       ↓
Validate records
       ↓
Insert database
       ↓
Move file to Processed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is excellent for Worker Services because processing can take several minutes.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;21. Worker Service for Email Processing&lt;/h1&gt;&lt;p&gt;Architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application
     │
     ▼
Email Queue
     │
     ▼
Email Worker
     │
     ├── Read message
     ├── Validate
     ├── Send email
     └── Complete message&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This prevents email processing from slowing down the main API.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Worker Service in Microservices&lt;/h1&gt;&lt;p&gt;Suppose your system contains:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
Payment Service
Inventory Service
Notification Service
Shipping Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
     │
     ▼
Order Worker

Payment Worker

Inventory Worker

Notification Worker

Shipping Worker&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each worker can be independently deployed and scaled.&lt;/p&gt;&lt;p&gt;This follows an important microservice principle:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A microservice should own a specific business capability.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;23. Scaling Workers&lt;/h1&gt;&lt;p&gt;Suppose there are:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;100 messages/hour&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;One worker might be enough.&lt;/p&gt;&lt;p&gt;But suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;100,000 messages/hour&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can run:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             Queue
               │
       ┌───────┼───────┐
       ▼       ▼       ▼
    Worker 1 Worker 2 Worker 3&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In Kubernetes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Deployment
     │
     ├── Pod 1
     ├── Pod 2
     ├── Pod 3
     └── Pod 4&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Multiple workers consume messages from the same queue.&lt;/p&gt;&lt;p&gt;The broker distributes messages between consumers.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;24. Worker Service + Kubernetes&lt;/h1&gt;&lt;p&gt;A Worker can run as a container.&lt;/p&gt;&lt;p&gt;Dockerfile:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-dockerfile&quot;&gt;FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src

COPY . .

RUN dotnet restore

RUN dotnet publish \
    -c Release \
    -o /app/publish

FROM base AS final

WORKDIR /app

COPY --from=build /app/publish .

ENTRYPOINT [&quot;dotnet&quot;, &quot;OrderProcessing.Worker.dll&quot;]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Docker Image
      ↓
Azure Container Registry
      ↓
AKS
      ↓
Worker Pod&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;25. Worker Deployment in Kubernetes&lt;/h1&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: apps/v1
kind: Deployment

metadata:
  name: order-worker

spec:
  replicas: 3

  selector:
    matchLabels:
      app: order-worker

  template:
    metadata:
      labels:
        app: order-worker

    spec:
      containers:
        - name: order-worker

          image: myregistry/order-worker:1.0

          resources:
            requests:
              cpu: &quot;100m&quot;
              memory: &quot;128Mi&quot;

            limits:
              cpu: &quot;500m&quot;
              memory: &quot;512Mi&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now Kubernetes runs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Worker
   │
   ├── Pod 1
   ├── Pod 2
   └── Pod 3&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;26. Worker Service Failure Handling&lt;/h1&gt;&lt;p&gt;Production workers must handle failures.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker
   ↓
Process Order
   ↓
Payment API
   ↓
FAILED&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Don&#39;t simply crash the entire application.&lt;/p&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Retry
 ↓
Retry
 ↓
Retry
 ↓
Still Failed
 ↓
Dead Letter Queue&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Orders Queue
     │
     ▼
Worker
     │
     ├── Success → Complete
     │
     └── Failure
           │
           ▼
       Retry
           │
           ▼
      Max Retries
           │
           ▼
    Dead Letter Queue&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;27. Idempotency — Extremely Important&lt;/h1&gt;&lt;p&gt;Imagine the worker receives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderId = 1001&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It processes it.&lt;/p&gt;&lt;p&gt;But before acknowledgement:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker crashes&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The message may be delivered again.&lt;/p&gt;&lt;p&gt;Now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order 1001
     ↓
Processed
     ↓
Worker crashes
     ↓
Message delivered again
     ↓
Order 1001 processed again&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore your worker should be &lt;strong&gt;idempotent&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var alreadyProcessed =
    await _db.ProcessedMessages
        .AnyAsync(
            x =&amp;gt; x.MessageId == messageId,
            cancellationToken);

if (alreadyProcessed)
{
    return;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Message
  ↓
Check MessageId
  ↓
Already processed?
  │
  ├── Yes → Skip
  │
  └── No → Process&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is extremely important in distributed systems.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;28. Worker + Saga Pattern&lt;/h1&gt;&lt;p&gt;Workers are also commonly used with Saga-based microservices.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Created
     ↓
Order Worker
     ↓
Payment
     ↓
Inventory
     ↓
Shipping&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If inventory fails:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order
  ↓
Payment SUCCESS
  ↓
Inventory FAILED
  ↓
Compensation
  ↓
Refund Payment
  ↓
Cancel Order&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Workers can process these asynchronous commands/events.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;29. Worker Service vs API&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Web API&lt;/th&gt;&lt;th&gt;Worker Service&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;HTTP endpoint&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Long-running process&lt;/td&gt;&lt;td&gt;Not ideal&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Queue consumer&lt;/td&gt;&lt;td&gt;Possible&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Scheduled jobs&lt;/td&gt;&lt;td&gt;Possible&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Background processing&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Request/response&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Kubernetes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Docker&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Microservices&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;30. Alternatives to Worker Services&lt;/h1&gt;&lt;p&gt;Worker Services are not the only solution.&lt;/p&gt;&lt;p&gt;Depending on your requirement, you can use several alternatives.&lt;/p&gt;&lt;h2&gt;1. Hangfire&lt;/h2&gt;&lt;p&gt;Excellent for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Background Jobs
Scheduled Jobs
Retries
Recurring Jobs
Dashboard&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;API
 ↓
Hangfire
 ↓
Background Job
 ↓
Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Good when you need:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Run every day at 2 AM&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Run this job in background&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;31. Quartz.NET&lt;/h1&gt;&lt;p&gt;Quartz.NET is useful for sophisticated scheduling.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Daily
Hourly
Weekly
Cron
Complex schedules&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application
     ↓
Quartz Scheduler
     ↓
Job
     ↓
Business Logic&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Good for complex scheduling requirements.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;32. Azure Functions&lt;/h1&gt;&lt;p&gt;If you&#39;re already using Azure, Azure Functions can be an excellent alternative.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Service Bus
    ↓
Azure Function
    ↓
Process Order&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Or:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Timer
 ↓
Azure Function
 ↓
Generate Report&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Advantages:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Serverless&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automatic scaling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Event-driven&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Less infrastructure management&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;33. Azure Service Bus Trigger&lt;/h1&gt;&lt;p&gt;A common architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
     ↓
Azure Service Bus
     ↓
Azure Function
     ↓
Process Order&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead of maintaining a continuously running Worker Service, Azure manages the execution environment.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;34. Kubernetes CronJob&lt;/h1&gt;&lt;p&gt;For batch jobs that run at a specific time:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Every night 2 AM
       ↓
Kubernetes CronJob
       ↓
Create Pod
       ↓
Execute job
       ↓
Pod completes&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is better than keeping a Worker continuously running for a job that only needs to execute once per day.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;35. Azure Logic Apps&lt;/h1&gt;&lt;p&gt;For workflow/integration scenarios:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Trigger
  ↓
Logic App
  ↓
Service A
  ↓
Service B
  ↓
Email&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Useful for integration workflows rather than complex application business logic.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. Azure Data Factory&lt;/h1&gt;&lt;p&gt;For data movement/ETL:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL Server
     ↓
Azure Data Factory
     ↓
Transform
     ↓
Azure SQL&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If your requirement is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ETL
Data migration
Data integration
Scheduled data processing&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ADF may be better than a Worker.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;37. Azure WebJobs&lt;/h1&gt;&lt;p&gt;For applications already hosted in Azure App Service, WebJobs can be useful for background execution.&lt;/p&gt;&lt;p&gt;Architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure App Service
       │
       ├── Web API
       │
       └── WebJob&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;38. Which One Should You Choose?&lt;/h1&gt;&lt;p&gt;A simple decision matrix:&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Requirement&lt;/th&gt;&lt;th&gt;Recommended&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Long-running background process&lt;/td&gt;&lt;td&gt;Worker Service&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Queue consumer&lt;/td&gt;&lt;td&gt;Worker Service / Azure Functions&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Complex scheduled jobs&lt;/td&gt;&lt;td&gt;Quartz.NET&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Simple background jobs&lt;/td&gt;&lt;td&gt;Hangfire&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Serverless event processing&lt;/td&gt;&lt;td&gt;Azure Functions&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Kubernetes scheduled batch&lt;/td&gt;&lt;td&gt;CronJob&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ETL/Data movement&lt;/td&gt;&lt;td&gt;Azure Data Factory&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure App Service background task&lt;/td&gt;&lt;td&gt;WebJobs&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Complex integration workflow&lt;/td&gt;&lt;td&gt;Logic Apps&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;39. Worker Service vs Azure Function&lt;/h1&gt;&lt;p&gt;This is a common interview question.&lt;/p&gt;&lt;h3&gt;Worker Service&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;You manage:
    Application
    Container/VM
    Deployment
    Scaling&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Azure Function&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure manages:
    Infrastructure
    Scaling
    Runtime&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Worker:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Queue
 ↓
Worker
 ↓
Process&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Function:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Queue
 ↓
Azure Function Trigger
 ↓
Process&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;40. Worker Service vs Hangfire&lt;/h1&gt;&lt;h3&gt;Worker Service&lt;/h3&gt;&lt;p&gt;Better for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Continuous processing
Queue consumers
Long-running workloads
Microservice background processes&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Hangfire&lt;/h3&gt;&lt;p&gt;Better for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Scheduled jobs
Fire-and-forget jobs
Recurring jobs
Retry management
Job dashboard&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;41. Worker Service vs Kubernetes CronJob&lt;/h1&gt;&lt;p&gt;Use Worker:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Continuous
 ↓
Consume messages
 ↓
Process continuously&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use CronJob:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;2 AM
 ↓
Start
 ↓
Process
 ↓
Exit&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Order queue consumer:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Daily database cleanup:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Kubernetes CronJob&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;42. Recommended Microservice Architecture&lt;/h1&gt;&lt;p&gt;For a production e-commerce system, I&#39;d typically consider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                     ┌──────────────┐
                     │   Angular UI │
                     └──────┬───────┘
                            │
                            ▼
                    ┌───────────────┐
                    │ API Management│
                    └───────┬───────┘
                            │
            ┌───────────────┼────────────────┐
            ▼               ▼                ▼
       Order API       Payment API      Customer API
            │
            ▼
      Azure Service Bus
            │
     ┌──────┼─────────────┐
     ▼      ▼             ▼
 Order    Inventory    Notification
 Worker     Worker        Worker
     │        │             │
     ▼        ▼             ▼
 Azure     Azure          Email/
 SQL       SQL            SMS&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And deploy using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;.NET Worker
     ↓
Docker
     ↓
Azure Container Registry
     ↓
AKS
     ↓
Pods
     ↓
Horizontal Scaling&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;43. Production Best Practices&lt;/h1&gt;&lt;p&gt;When implementing Worker Services, remember these:&lt;/p&gt;&lt;h3&gt;1. Use CancellationToken&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await ProcessAsync(cancellationToken);&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;2. Use structured logging&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;_logger.LogInformation(
    &quot;Processing Order {OrderId}&quot;,
    orderId);&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;3. Don&#39;t inject scoped dependencies directly&lt;/h3&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;IServiceScopeFactory&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;4. Make processing idempotent&lt;/h3&gt;&lt;p&gt;Prevent duplicate processing.&lt;/p&gt;&lt;h3&gt;5. Implement retry&lt;/h3&gt;&lt;p&gt;Transient failures should be retried.&lt;/p&gt;&lt;h3&gt;6. Use Dead Letter Queue&lt;/h3&gt;&lt;p&gt;Don&#39;t retry permanently bad messages forever.&lt;/p&gt;&lt;h3&gt;7. Configure health monitoring&lt;/h3&gt;&lt;p&gt;Monitor:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker status
Message count
Processing latency
Failure count
Retry count
DLQ count&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;8. Use distributed tracing&lt;/h3&gt;&lt;p&gt;For microservices:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;API
 ↓
Service Bus
 ↓
Worker
 ↓
Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You should be able to trace the complete transaction/correlation flow.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;44. Most Important Concept&lt;/h1&gt;&lt;p&gt;The biggest idea to remember is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Worker Services are not simply &quot;another type of API.&quot; They are long-running background processes designed to execute work independently of incoming HTTP requests.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;In microservices, they are particularly valuable for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;          EVENT
            │
            ▼
      Message Broker
            │
            ▼
     Worker Service
            │
     ┌──────┼──────┐
     ▼      ▼      ▼
    DB     API    Events&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This allows your APIs to remain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Fast
Stateless
Scalable
Responsive&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;while the Worker handles:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Long-running
Asynchronous
Retryable
Queue-based
Scheduled
Background&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;processing.&lt;/p&gt;&lt;h3&gt;Recommended architecture for your .NET/Azure stack&lt;/h3&gt;&lt;p&gt;Given a typical &lt;strong&gt;.NET + Microservices + Azure + Docker + AKS&lt;/strong&gt; architecture, a strong production combination is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    CLIENT
                      │
                      ▼
                 API Management
                      │
                      ▼
                 .NET Web API
                      │
               Publish Event
                      │
                      ▼
              Azure Service Bus
                      │
          ┌───────────┼───────────┐
          ▼           ▼           ▼
     .NET Worker  .NET Worker  .NET Worker
       Order       Inventory    Notification
          │           │           │
          ▼           ▼           ▼
       Azure SQL   Azure SQL    External API&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;with:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Docker
  ↓
Azure Container Registry
  ↓
AKS
  ↓
Worker Pods
  ↓
Horizontal Scaling&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That gives you a clean &lt;strong&gt;event-driven microservice architecture&lt;/strong&gt; with independent scaling and asynchronous processing.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/3117194860262762199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/3117194860262762199' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/3117194860262762199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/3117194860262762199'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/worker-services-in-net-complete-guide.html' title='Worker Services in .NET — Complete Guide'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisVgstJYjBmH0NLGvM4Andb00I3Z4WVKaDmtIsvYaz7g4F2Qqkpw4xYPnvOpeNP1VnslrxaZ_5e___kGWTFsTM-o9MC-SJGoVDiytdKmOuXYap0HRyyHx7X8DgExGH_SPZdwFRVA2XVY3NVB8zhmRcmFmgm4vRyFSQ1D9PGv1CJ8tTGm-9ZfzXF3TAOrs/s72-w468-h311-c/workerservices.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-2432916582704150933</id><published>2026-08-31T12:40:41.695+05:30</published><updated>2026-08-31T12:40:41.696+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Working with Windows Services in .NET"/><title type='text'>Working with Windows Services in .NET — Complete Guide from Scratch to Production</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhL6WiYGrvME8K_u3WCRVNysZc7QjvvQe_f-N-5B4yawFFmCPk0IkteKQeXFBS2bi4n7QzJIyZ76GWdXAchc57qn7MXBI5WA3i9ZrK98aH683O5gMq3912CLlZy-sUUI524VyAzAk0Jh0O-0OfQsDgPOyn63wWo1LXMhZUKUqzthgNiyXMkfi-X6m1Wr1E/s1536/windowservice.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;261&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhL6WiYGrvME8K_u3WCRVNysZc7QjvvQe_f-N-5B4yawFFmCPk0IkteKQeXFBS2bi4n7QzJIyZ76GWdXAchc57qn7MXBI5WA3i9ZrK98aH683O5gMq3912CLlZy-sUUI524VyAzAk0Jh0O-0OfQsDgPOyn63wWo1LXMhZUKUqzthgNiyXMkfi-X6m1Wr1E/w550-h261/windowservice.png&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;A &lt;strong&gt;Windows Service&lt;/strong&gt; is a long-running application that runs in the background without requiring a user to keep a console window open. In modern .NET, the recommended approach is to build a &lt;strong&gt;Worker Service using &lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt;&lt;/strong&gt; and configure it to run under the Windows Service infrastructure. Microsoft documents this approach for .NET 8 and later. (&lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?utm_source=chatgpt.com&quot; title=&quot;Create Windows Service using BackgroundService - .NET | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;Below is a &lt;strong&gt;blog-ready article&lt;/strong&gt; with a real-time example, architecture, code, deployment, logging, configuration, error handling, recovery, and troubleshooting.&lt;/p&gt;&lt;h1&gt;Windows Services in .NET: Complete Guide with Real-Time Example&lt;/h1&gt;&lt;h2&gt;Introduction&lt;/h2&gt;&lt;p&gt;In enterprise applications, we often have requirements where some processing must happen continuously in the background without a user manually starting the application.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Process pending orders&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generate invoices&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Send notification emails&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Read files from a folder&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Synchronize data between systems&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Process messages from a queue&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generate reports&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitor application health&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Clean up temporary files&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Synchronize data with a third-party API&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;A normal console application is not ideal for these scenarios because someone has to manually start it.&lt;/p&gt;&lt;p&gt;A Windows Service solves this problem.&lt;/p&gt;&lt;p&gt;A Windows Service can start automatically when Windows starts and continue running in the background.&lt;/p&gt;&lt;p&gt;Modern .NET provides the &lt;strong&gt;Worker Service&lt;/strong&gt; template and &lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt; for implementing these applications.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. What is a Windows Service?&lt;/h1&gt;&lt;p&gt;A Windows Service is an application designed to run in the background under the control of the Windows Service Control Manager (SCM).&lt;/p&gt;&lt;p&gt;Unlike a normal desktop application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Normal Console Application

User
  |
  v
Start Application
  |
  v
Console Window
  |
  v
Application Running&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A Windows Service works more like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Windows Operating System
        |
        v
Service Control Manager
        |
        v
Order Processing Service
        |
        v
Background Worker
        |
        +----&amp;gt; Database
        |
        +----&amp;gt; APIs
        |
        +----&amp;gt; File System
        |
        +----&amp;gt; Message Queue&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Service Control Manager can start, stop and monitor the service.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. Why Do We Need Windows Services?&lt;/h1&gt;&lt;p&gt;Imagine an e-commerce application.&lt;/p&gt;&lt;p&gt;Customers place orders throughout the day.&lt;/p&gt;&lt;p&gt;The application stores orders in SQL Server.&lt;/p&gt;&lt;p&gt;Instead of processing everything inside the Web API request, we can have a background service that periodically checks for pending orders.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer
   |
   v
Angular Application
   |
   v
.NET Web API
   |
   v
SQL Server
   |
   | Pending Orders
   v
Windows Service
   |
   +---- Process Order
   |
   +---- Generate Invoice
   |
   +---- Update Status
   |
   +---- Send Notification&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is a common enterprise architecture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Real-Time Example&lt;/h1&gt;&lt;p&gt;Let&#39;s build a real-world application called:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Order Processing Windows Service&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Our requirement is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Every 30 seconds, the Windows Service should check SQL Server for pending orders and process them.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The workflow will be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL Server
    |
    | Pending Orders
    v
Windows Service
    |
    v
Read Order
    |
    v
Process Order
    |
    v
Generate Invoice
    |
    v
Update Order Status
    |
    v
Log Result&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;4. Worker Service vs Windows Service&lt;/h1&gt;&lt;p&gt;These two terms are often confused.&lt;/p&gt;&lt;h3&gt;Worker Service&lt;/h3&gt;&lt;p&gt;A Worker Service is a .NET application designed for long-running background processing.&lt;/p&gt;&lt;h3&gt;Windows Service&lt;/h3&gt;&lt;p&gt;A Windows Service is the way the operating system hosts and manages a background application.&lt;/p&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker Service
      +
UseWindowsService()
      |
      v
Windows Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The modern .NET approach is to create a Worker Service and configure it to run as a Windows Service.&lt;/p&gt;&lt;p&gt;Microsoft recommends using the Worker Service template with &lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt; for this scenario. (&lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?utm_source=chatgpt.com&quot; title=&quot;Create Windows Service using BackgroundService - .NET | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Prerequisites&lt;/h1&gt;&lt;p&gt;You need:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Windows OS&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;.NET SDK&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Visual Studio or VS Code&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL Server if using the database example&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Administrator privileges for installing the Windows Service&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Microsoft&#39;s current Windows Service documentation uses .NET 8 or later as the prerequisite baseline. (&lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?utm_source=chatgpt.com&quot; title=&quot;Create Windows Service using BackgroundService - .NET | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. Create the Worker Service&lt;/h1&gt;&lt;p&gt;Using the .NET CLI:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet new worker -n OrderProcessingService&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Move into the project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;cd OrderProcessingService&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Run the application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet run&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Worker Service template creates a background worker application.&lt;/p&gt;&lt;p&gt;The template can also be created from Visual Studio by selecting:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Create a new project
        |
        v
Worker Service&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. Project Structure&lt;/h1&gt;&lt;p&gt;Our project can look like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderProcessingService
│
├── Program.cs
├── Worker.cs
├── appsettings.json
│
├── Models
│   └── Order.cs
│
├── Services
│   ├── IOrderProcessor.cs
│   └── OrderProcessor.cs
│
└── Data
    └── OrderRepository.cs&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A good architecture separates:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker
  |
  v
Business Service
  |
  v
Repository
  |
  v
Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Worker should not contain all business logic.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. Install Windows Service Package&lt;/h1&gt;&lt;p&gt;Install:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.Extensions.Hosting.WindowsServices&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This package provides Windows Service integration for the .NET hosting infrastructure. (&lt;a href=&quot;https://www.nuget.org/packages/Microsoft.Extensions.Hosting.WindowsServices/9.0.0?utm_source=chatgpt.com&quot; title=&quot;NuGet Gallery | Microsoft.Extensions.Hosting.WindowsServices 9.0.0&quot;&gt;NuGet&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. Understanding BackgroundService&lt;/h1&gt;&lt;p&gt;The main class of our Worker Service will inherit from:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;BackgroundService&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Worker : BackgroundService
{
    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            // Background processing

            await Task.Delay(
                TimeSpan.FromSeconds(30),
                stoppingToken);
        }
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important method is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;ExecuteAsync()&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is where the background processing happens.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. Understanding CancellationToken&lt;/h1&gt;&lt;p&gt;A Windows Service must be able to stop gracefully.&lt;/p&gt;&lt;p&gt;Suppose Windows sends a stop command.&lt;/p&gt;&lt;p&gt;We don&#39;t want the application to suddenly terminate in the middle of an operation.&lt;/p&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;CancellationToken stoppingToken&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;is provided.&lt;/p&gt;&lt;p&gt;We can check:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;while (!stoppingToken.IsCancellationRequested)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This means:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Continue processing until Windows tells the service to stop.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;11. Program.cs&lt;/h1&gt;&lt;p&gt;Now configure our application.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddWindowsService(options =&amp;gt;
{
    options.ServiceName = &quot;Order Processing Service&quot;;
});

builder.Services.AddHostedService&amp;lt;Worker&amp;gt;();

var host = builder.Build();

host.Run();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important line is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddWindowsService();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This configures the application to work with Windows Service lifetime management. Microsoft&#39;s current documentation uses this approach with &lt;code inline=&quot;&quot;&gt;Host.CreateApplicationBuilder&lt;/code&gt;. (&lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?utm_source=chatgpt.com&quot; title=&quot;Create Windows Service using BackgroundService - .NET | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Worker.cs&lt;/h1&gt;&lt;p&gt;Create our worker:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Worker : BackgroundService
{
    private readonly ILogger&amp;lt;Worker&amp;gt; _logger;

    public Worker(ILogger&amp;lt;Worker&amp;gt; logger)
    {
        _logger = logger;
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        _logger.LogInformation(
            &quot;Order Processing Service started.&quot;);

        while (!stoppingToken.IsCancellationRequested)
        {
            try
            {
                _logger.LogInformation(
                    &quot;Checking for pending orders.&quot;);

                await ProcessOrders(stoppingToken);
            }
            catch (Exception ex)
            {
                _logger.LogError(
                    ex,
                    &quot;Error while processing orders.&quot;);
            }

            await Task.Delay(
                TimeSpan.FromSeconds(30),
                stoppingToken);
        }

        _logger.LogInformation(
            &quot;Order Processing Service stopped.&quot;);
    }

    private async Task ProcessOrders(
        CancellationToken cancellationToken)
    {
        // Order processing logic

        await Task.CompletedTask;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;13. Why Use Task.Delay?&lt;/h1&gt;&lt;p&gt;Suppose we want to execute our process every 30 seconds.&lt;/p&gt;&lt;p&gt;We can use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await Task.Delay(
    TimeSpan.FromSeconds(30),
    stoppingToken);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The flow becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Service Starts
      |
      v
Process Orders
      |
      v
Wait 30 Seconds
      |
      v
Process Orders
      |
      v
Wait 30 Seconds
      |
      v
Continue...&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;14. Don&#39;t Use Thread.Sleep&lt;/h1&gt;&lt;p&gt;Avoid:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Thread.Sleep(30000);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Prefer:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await Task.Delay(
    TimeSpan.FromSeconds(30),
    stoppingToken);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Why?&lt;/p&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;Thread.Sleep()&lt;/code&gt; blocks the thread.&lt;/p&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;Task.Delay()&lt;/code&gt; allows asynchronous waiting and can respond to cancellation.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;15. Create Order Model&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Models/Order.cs&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;namespace OrderProcessingService.Models;

public class Order
{
    public int Id { get; set; }

    public string OrderNumber { get; set; } = string.Empty;

    public decimal Amount { get; set; }

    public string Status { get; set; } = string.Empty;

    public DateTime CreatedDate { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;16. Database Table&lt;/h1&gt;&lt;p&gt;Suppose we have this SQL Server table:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE Orders
(
    Id INT IDENTITY PRIMARY KEY,

    OrderNumber VARCHAR(50) NOT NULL,

    Amount DECIMAL(18,2) NOT NULL,

    Status VARCHAR(20) NOT NULL,

    CreatedDate DATETIME2 NOT NULL
);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Insert sample records:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;INSERT INTO Orders
(
    OrderNumber,
    Amount,
    Status,
    CreatedDate
)
VALUES
(
    &#39;ORD1001&#39;,
    2500,
    &#39;Pending&#39;,
    GETDATE()
);

INSERT INTO Orders
(
    OrderNumber,
    Amount,
    Status,
    CreatedDate
)
VALUES
(
    &#39;ORD1002&#39;,
    3500,
    &#39;Pending&#39;,
    GETDATE()
);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;17. Create Repository&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Data/OrderRepository.cs&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For demonstration, we can use ADO.NET.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.Data.SqlClient;
using OrderProcessingService.Models;

public class OrderRepository
{
    private readonly string _connectionString;

    public OrderRepository(string connectionString)
    {
        _connectionString = connectionString;
    }

    public async Task&amp;lt;List&amp;lt;Order&amp;gt;&amp;gt; GetPendingOrdersAsync(
        CancellationToken cancellationToken)
    {
        var orders = new List&amp;lt;Order&amp;gt;();

        using var connection =
            new SqlConnection(_connectionString);

        await connection.OpenAsync(cancellationToken);

        var command = new SqlCommand(
            &quot;&quot;&quot;
            SELECT TOP 10
                   Id,
                   OrderNumber,
                   Amount,
                   Status,
                   CreatedDate
            FROM Orders
            WHERE Status = &#39;Pending&#39;
            ORDER BY Id
            &quot;&quot;&quot;,
            connection);

        using var reader =
            await command.ExecuteReaderAsync(
                cancellationToken);

        while (await reader.ReadAsync(cancellationToken))
        {
            orders.Add(new Order
            {
                Id = reader.GetInt32(0),
                OrderNumber = reader.GetString(1),
                Amount = reader.GetDecimal(2),
                Status = reader.GetString(3),
                CreatedDate = reader.GetDateTime(4)
            });
        }

        return orders;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;18. Register Repository Using Dependency Injection&lt;/h1&gt;&lt;p&gt;Instead of creating the repository manually inside the Worker, use Dependency Injection.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddSingleton&amp;lt;OrderRepository&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, for production applications, it is usually better to register database-related services according to their actual lifetime and dependency behavior.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddScoped&amp;lt;IOrderProcessor, OrderProcessor&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For scoped services inside a &lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt;, create an explicit scope using &lt;code inline=&quot;&quot;&gt;IServiceScopeFactory&lt;/code&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;19. Business Service&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Services/IOrderProcessor.cs&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IOrderProcessor
{
    Task ProcessAsync(
        CancellationToken cancellationToken);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Implementation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderProcessor : IOrderProcessor
{
    private readonly OrderRepository _repository;
    private readonly ILogger&amp;lt;OrderProcessor&amp;gt; _logger;

    public OrderProcessor(
        OrderRepository repository,
        ILogger&amp;lt;OrderProcessor&amp;gt; logger)
    {
        _repository = repository;
        _logger = logger;
    }

    public async Task ProcessAsync(
        CancellationToken cancellationToken)
    {
        var orders =
            await _repository.GetPendingOrdersAsync(
                cancellationToken);

        foreach (var order in orders)
        {
            _logger.LogInformation(
                &quot;Processing order {OrderNumber}&quot;,
                order.OrderNumber);

            // Business logic

            _logger.LogInformation(
                &quot;Order {OrderNumber} processed successfully.&quot;,
                order.OrderNumber);
        }
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Worker with Dependency Injection&lt;/h1&gt;&lt;p&gt;Now our Worker becomes cleaner.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Worker : BackgroundService
{
    private readonly IServiceScopeFactory _scopeFactory;
    private readonly ILogger&amp;lt;Worker&amp;gt; _logger;

    public Worker(
        IServiceScopeFactory scopeFactory,
        ILogger&amp;lt;Worker&amp;gt; logger)
    {
        _scopeFactory = scopeFactory;
        _logger = logger;
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        _logger.LogInformation(
            &quot;Order Processing Service started.&quot;);

        while (!stoppingToken.IsCancellationRequested)
        {
            try
            {
                using var scope =
                    _scopeFactory.CreateScope();

                var processor =
                    scope.ServiceProvider
                        .GetRequiredService&amp;lt;IOrderProcessor&amp;gt;();

                await processor.ProcessAsync(
                    stoppingToken);
            }
            catch (OperationCanceledException)
                when (stoppingToken.IsCancellationRequested)
            {
                break;
            }
            catch (Exception ex)
            {
                _logger.LogError(
                    ex,
                    &quot;Unexpected error.&quot;);
            }

            await Task.Delay(
                TimeSpan.FromSeconds(30),
                stoppingToken);
        }

        _logger.LogInformation(
            &quot;Order Processing Service stopped.&quot;);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This gives us a clean architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker
  |
  v
IOrderProcessor
  |
  v
OrderProcessor
  |
  v
OrderRepository
  |
  v
SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;21. appsettings.json&lt;/h1&gt;&lt;p&gt;Configuration should not be hard-coded.&lt;/p&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;ConnectionStrings&quot;: {
    &quot;DefaultConnection&quot;: &quot;Server=localhost;Database=OrderDb;Trusted_Connection=True;TrustServerCertificate=True&quot;
  },

  &quot;WorkerSettings&quot;: {
    &quot;IntervalSeconds&quot;: 30,
    &quot;BatchSize&quot;: 10
  },

  &quot;Logging&quot;: {
    &quot;LogLevel&quot;: {
      &quot;Default&quot;: &quot;Information&quot;,
      &quot;Microsoft.Hosting.Lifetime&quot;: &quot;Information&quot;
    }
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;22. Using Configuration&lt;/h1&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class WorkerSettings
{
    public int IntervalSeconds { get; set; }

    public int BatchSize { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Register it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.Configure&amp;lt;WorkerSettings&amp;gt;(
    builder.Configuration.GetSection(&quot;WorkerSettings&quot;));&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the interval can be changed without modifying the code.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;23. Complete Program.cs&lt;/h1&gt;&lt;p&gt;Our final Program.cs can look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddWindowsService(options =&amp;gt;
{
    options.ServiceName = &quot;Order Processing Service&quot;;
});

builder.Services.Configure&amp;lt;WorkerSettings&amp;gt;(
    builder.Configuration.GetSection(&quot;WorkerSettings&quot;));

var connectionString =
    builder.Configuration.GetConnectionString(
        &quot;DefaultConnection&quot;);

builder.Services.AddSingleton(
    new OrderRepository(connectionString!));

builder.Services.AddScoped&amp;lt;IOrderProcessor, OrderProcessor&amp;gt;();

builder.Services.AddHostedService&amp;lt;Worker&amp;gt;();

var host = builder.Build();

host.Run();&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;24. Logging&lt;/h1&gt;&lt;p&gt;Logging is extremely important for Windows Services because there is no console window when the service is running in production.&lt;/p&gt;&lt;p&gt;We can use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;_logger.LogInformation(
    &quot;Order {OrderNumber} processed.&quot;,
    order.OrderNumber);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Other levels include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;_logger.LogDebug(&quot;Debug information&quot;);

_logger.LogInformation(&quot;Information&quot;);

_logger.LogWarning(&quot;Warning&quot;);

_logger.LogError(&quot;Error&quot;);

_logger.LogCritical(&quot;Critical failure&quot;);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;25. Windows Event Viewer&lt;/h1&gt;&lt;p&gt;When running as a Windows Service, logs can be written to the Windows Event Log.&lt;/p&gt;&lt;p&gt;Microsoft&#39;s Windows Service hosting integration supports Event Log logging, and &lt;code inline=&quot;&quot;&gt;UseWindowsService&lt;/code&gt;/&lt;code inline=&quot;&quot;&gt;AddWindowsService&lt;/code&gt; configures Windows Service behavior and Event Log integration. (&lt;a href=&quot;https://learn.microsoft.com/ga-ie/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-7.0&amp;amp;utm_source=chatgpt.com&quot; title=&quot;Host ASP.NET Core in a Windows Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;You can open:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Start
  |
  v
Event Viewer
  |
  v
Windows Logs
  |
  v
Application&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then search for events generated by your application.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. Important Difference: Console vs Windows Service&lt;/h1&gt;&lt;p&gt;During development:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;dotnet run&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application runs as a console process.&lt;/p&gt;&lt;p&gt;After installation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Windows
   |
   v
Service Control Manager
   |
   v
Order Processing Service
   |
   v
Worker&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The same application can therefore be useful both locally and as a Windows Service.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. Publish the Application&lt;/h1&gt;&lt;p&gt;Before installing the service, publish the application.&lt;/p&gt;&lt;p&gt;For a Windows x64 deployment:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet publish -c Release -r win-x64 --self-contained true&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can also publish as a single executable.&lt;/p&gt;&lt;p&gt;Microsoft recommends publishing a Worker Service as a single-file executable for Windows Service deployment because it reduces deployment-file complexity. (&lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?utm_source=chatgpt.com&quot; title=&quot;Create Windows Service using BackgroundService - .NET | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet publish -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The published application will be under a path similar to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;bin\Release\net9.0\win-x64\publish\&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The exact target framework depends on the .NET version used by your project.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;28. Installing the Windows Service&lt;/h1&gt;&lt;p&gt;Open:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PowerShell&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Command Prompt&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;as Administrator.&lt;/p&gt;&lt;p&gt;Navigate to the published executable.&lt;/p&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe create &quot;Order Processing Service&quot; binPath= &quot;C:\Services\OrderProcessingService\OrderProcessingService.exe&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If successful, Windows reports:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[SC] CreateService SUCCESS&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft documents &lt;code inline=&quot;&quot;&gt;sc.exe create&lt;/code&gt; as the native Service Control Manager approach for creating the service. (&lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?utm_source=chatgpt.com&quot; title=&quot;Create Windows Service using BackgroundService - .NET | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;29. Start the Service&lt;/h1&gt;&lt;p&gt;Run:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe start &quot;Order Processing Service&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Or open:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Services&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Find:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Processing Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Right Click
    |
    v
Start&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;30. Service Lifecycle&lt;/h1&gt;&lt;p&gt;The complete lifecycle looks like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Windows Boot
     |
     v
Service Control Manager
     |
     v
Start Service
     |
     v
.NET Host
     |
     v
BackgroundService
     |
     v
ExecuteAsync()
     |
     v
Process Orders
     |
     v
Wait
     |
     +--------+
              |
              v
        Process Again&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When Windows stops the service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Windows
   |
   v
Stop Request
   |
   v
CancellationToken
   |
   v
ExecuteAsync exits
   |
   v
Host shuts down
   |
   v
Service stopped&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;31. Stop the Service&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe stop &quot;Order Processing Service&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Or use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Services
  |
  v
Order Processing Service
  |
  v
Stop&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;32. Delete the Service&lt;/h1&gt;&lt;p&gt;If you want to completely remove it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe stop &quot;Order Processing Service&quot;

sc.exe delete &quot;Order Processing Service&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft notes that a service should be stopped before deleting it. (&lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?utm_source=chatgpt.com&quot; title=&quot;Create Windows Service using BackgroundService - .NET | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;33. Configure Automatic Startup&lt;/h1&gt;&lt;p&gt;A production service normally should start automatically.&lt;/p&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe config &quot;Order Processing Service&quot; start= auto&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now Windows can start the service automatically during system startup.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;34. Configure Service Recovery&lt;/h1&gt;&lt;p&gt;One of the biggest advantages of Windows Services is recovery configuration.&lt;/p&gt;&lt;p&gt;Imagine:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Processing Service
        |
        v
Unexpected Error
        |
        v
Process Terminates&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We want:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Service Failure
      |
      v
Windows Service Manager
      |
      v
Restart Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft provides &lt;code inline=&quot;&quot;&gt;sc.exe failure&lt;/code&gt; for configuring service recovery actions. (&lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?utm_source=chatgpt.com&quot; title=&quot;Create Windows Service using BackgroundService - .NET | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe failure &quot;Order Processing Service&quot; reset= 86400 actions= restart/60000/restart/60000/run/1000&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can configure restart actions after failures.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;35. Why Recovery Is Important&lt;/h1&gt;&lt;p&gt;Consider a production server:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;2:00 AM
   |
   v
Service crashes
   |
   v
Windows detects failure
   |
   v
Service automatically restarts
   |
   v
Processing continues&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Without recovery:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Service crashes
     |
     v
Processing stops
     |
     v
Manual intervention required&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With recovery:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Service crashes
     |
     v
Automatic restart
     |
     v
Processing continues&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;36. Handling Exceptions&lt;/h1&gt;&lt;p&gt;Never allow an unexpected exception to bring down the entire worker loop unnecessarily.&lt;/p&gt;&lt;p&gt;Bad:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;while (true)
{
    await ProcessOrders();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Better:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;while (!stoppingToken.IsCancellationRequested)
{
    try
    {
        await ProcessOrders(stoppingToken);
    }
    catch (Exception ex)
    {
        _logger.LogError(
            ex,
            &quot;Error processing orders.&quot;);
    }

    await Task.Delay(
        TimeSpan.FromSeconds(30),
        stoppingToken);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, exception handling should be designed carefully. Some failures indicate that the application should stop rather than endlessly retry.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;37. Graceful Shutdown&lt;/h1&gt;&lt;p&gt;Suppose an order is currently being processed:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Processing Order 1001
        |
        |
Windows Stop Request
        |
        v
CancellationToken&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The service should stop accepting new work and allow the current operation to finish when appropriate.&lt;/p&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;CancellationToken&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;throughout the call chain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker
  |
  v
Processor
  |
  v
Repository
  |
  v
Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await connection.OpenAsync(
    cancellationToken);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await command.ExecuteReaderAsync(
    cancellationToken);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;38. Avoid Long Blocking Operations&lt;/h1&gt;&lt;p&gt;Avoid:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Thread.Sleep(...)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Avoid synchronous network calls when asynchronous APIs are available.&lt;/p&gt;&lt;p&gt;Prefer:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await httpClient.GetAsync(
    url,
    cancellationToken);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Prefer asynchronous database operations:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await command.ExecuteNonQueryAsync(
    cancellationToken);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This makes the service more responsive and easier to shut down gracefully.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;39. Calling a Third-Party API&lt;/h1&gt;&lt;p&gt;Suppose after processing an order we need to notify an external payment service.&lt;/p&gt;&lt;p&gt;Use &lt;code inline=&quot;&quot;&gt;HttpClient&lt;/code&gt; through Dependency Injection.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddHttpClient(
    &quot;PaymentApi&quot;,
    client =&amp;gt;
    {
        client.BaseAddress =
            new Uri(&quot;https://api.example.com/&quot;);
    });&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class PaymentService
{
    private readonly IHttpClientFactory _httpClientFactory;

    public PaymentService(
        IHttpClientFactory httpClientFactory)
    {
        _httpClientFactory = httpClientFactory;
    }

    public async Task NotifyPaymentAsync(
        int orderId,
        CancellationToken cancellationToken)
    {
        var client =
            _httpClientFactory.CreateClient(&quot;PaymentApi&quot;);

        await client.PostAsJsonAsync(
            &quot;payments/process&quot;,
            new
            {
                OrderId = orderId
            },
            cancellationToken);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;40. Real Production Architecture&lt;/h1&gt;&lt;p&gt;A production implementation could look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 ┌─────────────────────┐
                 │      SQL Server     │
                 │                     │
                 │ Pending Orders      │
                 └──────────┬──────────┘
                            │
                            ▼
                 ┌─────────────────────┐
                 │  Windows Service    │
                 │                     │
                 │ BackgroundService   │
                 └──────────┬──────────┘
                            │
                            ▼
                 ┌─────────────────────┐
                 │ Order Processor     │
                 │                     │
                 │ Business Logic      │
                 └──────────┬──────────┘
                            │
             ┌──────────────┼──────────────┐
             ▼              ▼              ▼
       SQL Server       Payment API    Notification API
             │              │              │
             └──────────────┼──────────────┘
                            ▼
                       Logging
                            │
                            ▼
                     Event Viewer&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;41. Windows Service vs Web API&lt;/h1&gt;&lt;p&gt;These applications solve different problems.&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Web API&lt;/th&gt;&lt;th&gt;Windows Service&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;User request&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;HTTP endpoint&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Not required&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Long-running background work&lt;/td&gt;&lt;td&gt;Not ideal&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Runs continuously&lt;/td&gt;&lt;td&gt;Usually hosted continuously&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Trigger&lt;/td&gt;&lt;td&gt;HTTP request&lt;/td&gt;&lt;td&gt;Timer/event/message&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;UI required&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Windows Service support&lt;/td&gt;&lt;td&gt;Possible&lt;/td&gt;&lt;td&gt;Native scenario&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Background processing&lt;/td&gt;&lt;td&gt;Limited/specialized&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;A Web API is usually request-driven.&lt;/p&gt;&lt;p&gt;A Windows Service is usually background-driven.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;42. Windows Service vs BackgroundService&lt;/h1&gt;&lt;p&gt;They are not exactly the same thing.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BackgroundService
       |
       +---- Console Application
       |
       +---- Windows Service
       |
       +---- Container
       |
       +---- Other Host&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt; is an abstraction for implementing long-running hosted background work.&lt;/p&gt;&lt;p&gt;Windows Service hosting is one way to host that worker.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;43. Timer-Based Processing&lt;/h1&gt;&lt;p&gt;For periodic work, another pattern is using &lt;code inline=&quot;&quot;&gt;PeriodicTimer&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;protected override async Task ExecuteAsync(
    CancellationToken stoppingToken)
{
    using var timer =
        new PeriodicTimer(
            TimeSpan.FromSeconds(30));

    while (await timer.WaitForNextTickAsync(
        stoppingToken))
    {
        await ProcessOrders(
            stoppingToken);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can make periodic processing easier to read.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;44. Important Production Consideration: Duplicate Processing&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker
   |
   v
Gets Order 1001
   |
   v
Starts Processing&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Before updating the status, the service crashes.&lt;/p&gt;&lt;p&gt;After restart:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker
   |
   v
Gets Order 1001 again&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the same order could be processed twice.&lt;/p&gt;&lt;p&gt;This is a major production concern.&lt;/p&gt;&lt;p&gt;We need an idempotent processing strategy.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;45. Use Status Transitions&lt;/h1&gt;&lt;p&gt;Instead of:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pending
  |
  v
Processed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pending
   |
   v
Processing
   |
   v
Completed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If something fails:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Processing
     |
     v
Failed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pending
   |
   v
Processing
   |
   +------&amp;gt; Failed
   |
   v
Completed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This allows us to understand exactly where the order is.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;46. Database Transaction&lt;/h1&gt;&lt;p&gt;Critical operations can use transactions.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BEGIN TRANSACTION

Get Pending Order

Change Status = Processing

Perform Database Operations

Change Status = Completed

COMMIT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If an operation fails:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ROLLBACK&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, transactions should not normally be held open across slow external API calls. For distributed workflows, patterns such as idempotency, outbox/inbox, queues, and Saga may be more appropriate.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;47. Windows Service + Message Queue&lt;/h1&gt;&lt;p&gt;In a larger architecture, instead of polling SQL Server:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL Server
   |
   v
Windows Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;we might use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Web API
   |
   v
Azure Service Bus / RabbitMQ
   |
   v
Windows Service
   |
   v
Order Processor&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Worker waits for messages.&lt;/p&gt;&lt;p&gt;This is often better when work should be processed asynchronously and reliably.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;48. Windows Service + Azure Service Bus&lt;/h1&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer
   |
   v
Web API
   |
   v
Azure Service Bus
   |
   v
Windows Service
   |
   v
Order Processing&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The service can consume messages continuously.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;while (!stoppingToken.IsCancellationRequested)
{
    var message =
        await ReceiveMessageAsync(
            stoppingToken);

    await ProcessMessageAsync(
        message,
        stoppingToken);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For enterprise systems, this approach can provide better decoupling than repeatedly querying the database.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;49. Health Monitoring&lt;/h1&gt;&lt;p&gt;Production Windows Services should be monitored.&lt;/p&gt;&lt;p&gt;Useful information includes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Service Status
Last Successful Processing
Last Failure
Number of Records Processed
Processing Duration
Database Connectivity
External API Availability&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Processing Service

Status: Running

Orders Processed: 15,230

Last Successful Run:
2026-08-31 12:15:00

Last Error:
None

Average Processing Time:
1.8 seconds&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;50. Configuration by Environment&lt;/h1&gt;&lt;p&gt;Avoid hard-coding production settings.&lt;/p&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;appsettings.json
appsettings.Development.json
appsettings.Production.json&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;WorkerSettings&quot;: {
    &quot;IntervalSeconds&quot;: 30
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Development:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;WorkerSettings&quot;: {
    &quot;IntervalSeconds&quot;: 10
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Production:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;WorkerSettings&quot;: {
    &quot;IntervalSeconds&quot;: 60
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;51. Security&lt;/h1&gt;&lt;p&gt;Do not store passwords directly inside source code.&lt;/p&gt;&lt;p&gt;Bad:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var connectionString =
    &quot;Server=...;User Id=admin;Password=12345&quot;;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Better approaches include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Windows authentication where appropriate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Environment-specific configuration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secret management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault for Azure-hosted workloads&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Restricted service accounts&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The service should run with only the permissions it actually needs.&lt;/p&gt;&lt;p&gt;Avoid giving unnecessary administrator privileges.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;52. Service Account&lt;/h1&gt;&lt;p&gt;A Windows Service runs under an account.&lt;/p&gt;&lt;p&gt;Common options include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Local System
Local Service
Network Service
Custom Service Account&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For production applications, use an appropriately restricted service identity rather than automatically granting broad privileges.&lt;/p&gt;&lt;p&gt;The identity should have only the permissions required for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Database
File System
Network
APIs
Certificates
Logs&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;53. File Access&lt;/h1&gt;&lt;p&gt;If your service processes files:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;C:\Input
C:\Output
C:\Archive&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;make sure the Windows Service account has appropriate permissions.&lt;/p&gt;&lt;p&gt;A common mistake is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Console Application
     |
     v
Works perfectly&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;but:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Windows Service
     |
     v
Access Denied&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Why?&lt;/p&gt;&lt;p&gt;Because the console application and Windows Service may be running under different user accounts.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;54. Current Directory Problem&lt;/h1&gt;&lt;p&gt;When running interactively, developers sometimes use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Directory.GetCurrentDirectory()&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But Windows Services may have a different working directory.&lt;/p&gt;&lt;p&gt;Prefer application-relative paths based on:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;AppContext.BaseDirectory&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft&#39;s Windows Service hosting integration sets the content root appropriately when running as a Windows Service. (&lt;a href=&quot;https://learn.microsoft.com/ga-ie/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-7.0&amp;amp;utm_source=chatgpt.com&quot; title=&quot;Host ASP.NET Core in a Windows Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;55. Deployment Process&lt;/h1&gt;&lt;p&gt;A typical deployment process is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer
   |
   v
Git Repository
   |
   v
CI/CD Pipeline
   |
   v
dotnet build
   |
   v
dotnet test
   |
   v
dotnet publish
   |
   v
Deployment Server
   |
   v
Stop Service
   |
   v
Copy New Version
   |
   v
Start Service
   |
   v
Verify Logs&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For enterprise applications, this process can be automated using Azure DevOps or another CI/CD platform.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;56. Updating the Service&lt;/h1&gt;&lt;p&gt;Suppose version 1 is installed:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderProcessingService v1&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You release:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderProcessingService v2&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Typical deployment:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe stop &quot;Order Processing Service&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Deploy the new files.&lt;/p&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe start &quot;Order Processing Service&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Always plan deployment carefully if the service is processing critical work.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;57. Troubleshooting&lt;/h1&gt;&lt;h3&gt;Problem 1: Service doesn&#39;t start&lt;/h3&gt;&lt;p&gt;Check:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Event Viewer&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Also verify:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Executable path
Service account permissions
Configuration
Connection strings
Required files
.NET runtime&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Problem 2: Service starts and immediately stops&lt;/h3&gt;&lt;p&gt;Possible causes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Unhandled exception
Invalid configuration
Missing dependency
Database connection failure
Invalid executable
Startup exception&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Check Event Viewer and application logs.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Problem 3: Works with dotnet run but not as a service&lt;/h3&gt;&lt;p&gt;Common reasons:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Different service account
File permission issue
Different working directory
Environment configuration
Missing configuration file
Database authentication
Network permissions&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Problem 4: Database connection fails&lt;/h3&gt;&lt;p&gt;Check:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL Server availability
Connection string
Authentication
Firewall
Service account permissions
Database permissions&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Problem 5: Service keeps restarting&lt;/h3&gt;&lt;p&gt;Check:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Event Viewer
Application logs
Service recovery configuration
Unhandled exceptions
Memory/CPU issues
External dependency failures&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;58. Complete Architecture&lt;/h1&gt;&lt;p&gt;A mature implementation might look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                  ┌─────────────────────┐
                  │ Windows Server      │
                  │                     │
                  │ Service Control     │
                  │ Manager             │
                  └──────────┬──────────┘
                             │
                             ▼
                  ┌─────────────────────┐
                  │ Order Worker        │
                  │                     │
                  │ BackgroundService   │
                  └──────────┬──────────┘
                             │
                             ▼
                  ┌─────────────────────┐
                  │ Order Processor      │
                  │                     │
                  │ Business Rules      │
                  └───────┬───────┬─────┘
                          │       │
                ┌─────────┘       └─────────┐
                ▼                           ▼
        ┌──────────────┐             ┌──────────────┐
        │ SQL Server   │             │ External API │
        └──────────────┘             └──────────────┘
                          │
                          ▼
                    ┌───────────┐
                    │ Event Log │
                    └───────────┘&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;59. End-to-End Flow&lt;/h1&gt;&lt;p&gt;Let&#39;s summarize the entire application.&lt;/p&gt;&lt;h3&gt;Step 1 — Windows starts&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Windows Server&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 2 — Service Control Manager starts the service&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SCM
 |
 v
Order Processing Service&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 3 — .NET Host starts&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Host
 |
 v
Dependency Injection
 |
 v
BackgroundService&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 4 — Worker starts&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker.ExecuteAsync()&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 5 — Worker retrieves orders&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL Server
 |
 v
Pending Orders&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 6 — Business logic executes&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderProcessor&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 7 — Database gets updated&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pending
   |
   v
Processing
   |
   v
Completed&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 8 — Logging occurs&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Event Log&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 9 — Worker waits&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;30 seconds&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 10 — Processing starts again&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Process
  |
  v
Wait
  |
  v
Process
  |
  v
Wait&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 11 — Windows sends stop signal&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CancellationToken&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 12 — Worker exits gracefully&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ExecuteAsync()
     |
     v
Host Shutdown
     |
     v
Service Stopped&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;60. Complete Worker Example&lt;/h1&gt;&lt;p&gt;Here is a simplified final version:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.Extensions.Hosting;

public class Worker : BackgroundService
{
    private readonly IServiceScopeFactory _scopeFactory;
    private readonly ILogger&amp;lt;Worker&amp;gt; _logger;

    public Worker(
        IServiceScopeFactory scopeFactory,
        ILogger&amp;lt;Worker&amp;gt; logger)
    {
        _scopeFactory = scopeFactory;
        _logger = logger;
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        _logger.LogInformation(
            &quot;Order Processing Service started.&quot;);

        using var timer =
            new PeriodicTimer(
                TimeSpan.FromSeconds(30));

        try
        {
            while (await timer.WaitForNextTickAsync(
                stoppingToken))
            {
                try
                {
                    using var scope =
                        _scopeFactory.CreateScope();

                    var processor =
                        scope.ServiceProvider
                            .GetRequiredService&amp;lt;IOrderProcessor&amp;gt;();

                    await processor.ProcessAsync(
                        stoppingToken);
                }
                catch (OperationCanceledException)
                    when (stoppingToken.IsCancellationRequested)
                {
                    break;
                }
                catch (Exception ex)
                {
                    _logger.LogError(
                        ex,
                        &quot;Error occurred while processing orders.&quot;);
                }
            }
        }
        catch (OperationCanceledException)
            when (stoppingToken.IsCancellationRequested)
        {
            // Expected during shutdown.
        }

        _logger.LogInformation(
            &quot;Order Processing Service stopped.&quot;);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;61. Complete Program Example&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddWindowsService(options =&amp;gt;
{
    options.ServiceName = &quot;Order Processing Service&quot;;
});

builder.Services.Configure&amp;lt;WorkerSettings&amp;gt;(
    builder.Configuration.GetSection(&quot;WorkerSettings&quot;));

var connectionString =
    builder.Configuration.GetConnectionString(
        &quot;DefaultConnection&quot;);

builder.Services.AddSingleton(
    new OrderRepository(connectionString!));

builder.Services.AddScoped&amp;lt;IOrderProcessor, OrderProcessor&amp;gt;();

builder.Services.AddHostedService&amp;lt;Worker&amp;gt;();

var host = builder.Build();

host.Run();&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;62. Commands Cheat Sheet&lt;/h1&gt;&lt;h3&gt;Create project&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet new worker -n OrderProcessingService&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Add Windows Service support&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.Extensions.Hosting.WindowsServices&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Build&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet build&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Run locally&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet run&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Publish&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet publish -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Create service&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe create &quot;Order Processing Service&quot; binPath= &quot;C:\Services\OrderProcessingService\OrderProcessingService.exe&quot;&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Configure automatic startup&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe config &quot;Order Processing Service&quot; start= auto&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Start&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe start &quot;Order Processing Service&quot;&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Stop&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe stop &quot;Order Processing Service&quot;&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Delete&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe delete &quot;Order Processing Service&quot;&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Check failure configuration&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe qfailure &quot;Order Processing Service&quot;&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;63. Best Practices&lt;/h1&gt;&lt;p&gt;For production Windows Services, follow these practices:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Use &lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use Dependency Injection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use asynchronous APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pass &lt;code inline=&quot;&quot;&gt;CancellationToken&lt;/code&gt; throughout the processing pipeline.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use structured logging.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Don&#39;t hard-code connection strings.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use secure secret management.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Run using a least-privilege service account.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configure service recovery.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Make processing idempotent.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use database transactions where appropriate.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid processing the same record twice.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitor service health.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitor CPU and memory.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Keep the Worker class thin.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Put business logic into separate services.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use configuration for intervals and batch sizes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Test the application as both a console application and Windows Service.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automate deployment through CI/CD where practical.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use a message broker when continuous database polling is no longer appropriate.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr /&gt;&lt;h1&gt;64. When Should You Use a Windows Service?&lt;/h1&gt;&lt;p&gt;Windows Services are particularly useful when:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Continuous Background Processing
          +
Windows Server Environment
          +
No User Interaction Required&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;h3&gt;File Processing&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Input Folder
     |
     v
Windows Service
     |
     v
Validate File
     |
     v
Process File
     |
     v
Archive File&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Order Processing&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Database
   |
   v
Windows Service
   |
   v
Process Orders&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Data Synchronization&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;System A
   |
   v
Windows Service
   |
   v
System B&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Scheduled Reports&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Windows Service
      |
      v
Generate Report
      |
      v
Save PDF
      |
      v
Send Notification&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;65. When Should You NOT Use a Windows Service?&lt;/h1&gt;&lt;p&gt;A Windows Service may not be the best choice when:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The workload is already event-driven through a managed cloud messaging platform.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You need massive horizontal scaling.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The workload is better suited to serverless functions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The application must expose HTTP endpoints as its primary responsibility.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The environment is Linux-only.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A managed cloud service can perform the same task more reliably.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For cloud-native systems, alternatives can include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Functions
Azure Container Apps
AKS
Azure Service Bus
Cloud-hosted Worker Services&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The right choice depends on the workload and operational requirements.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;66. Interview Questions&lt;/h1&gt;&lt;h3&gt;Q1. What is a Windows Service?&lt;/h3&gt;&lt;p&gt;A Windows Service is a background application managed by the Windows Service Control Manager.&lt;/p&gt;&lt;h3&gt;Q2. What is BackgroundService?&lt;/h3&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt; is a .NET base class used to implement long-running background tasks.&lt;/p&gt;&lt;h3&gt;Q3. How do you convert a Worker Service into a Windows Service?&lt;/h3&gt;&lt;p&gt;Install:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Microsoft.Extensions.Hosting.WindowsServices&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and configure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddWindowsService();&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Q4. What is ExecuteAsync?&lt;/h3&gt;&lt;p&gt;It is the main asynchronous method where the background work is implemented.&lt;/p&gt;&lt;h3&gt;Q5. Why use CancellationToken?&lt;/h3&gt;&lt;p&gt;It allows the worker to respond to shutdown requests gracefully.&lt;/p&gt;&lt;h3&gt;Q6. How do you install a Windows Service?&lt;/h3&gt;&lt;p&gt;Using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe create&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Q7. How do you start it?&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe start&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Q8. How do you stop it?&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe stop&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Q9. How do you remove it?&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;sc.exe delete&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Q10. Where can you check Windows Service errors?&lt;/h3&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Event Viewer
→ Windows Logs
→ Application&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Q11. How do you automatically restart a failed service?&lt;/h3&gt;&lt;p&gt;Configure Windows Service recovery actions using Service Control Manager settings or &lt;code inline=&quot;&quot;&gt;sc.exe failure&lt;/code&gt;.&lt;/p&gt;&lt;h3&gt;Q12. How do you avoid duplicate processing?&lt;/h3&gt;&lt;p&gt;Use techniques such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Idempotency
Status transitions
Database constraints
Transactions
Outbox/Inbox patterns
Message deduplication&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;depending on the architecture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;67. Final Takeaway&lt;/h1&gt;&lt;p&gt;A modern .NET Windows Service is not simply a program containing an infinite loop.&lt;/p&gt;&lt;p&gt;A production-quality implementation should have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 Windows Service
                       |
                       v
                BackgroundService
                       |
                       v
                Dependency Injection
                       |
                       v
                 Business Service
                       |
             +---------+---------+
             |                   |
             v                   v
         Database            External API
             |                   |
             +---------+---------+
                       |
                       v
                    Logging
                       |
                       v
                 Monitoring&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The most important concepts to remember are:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Worker Service
      ↓
BackgroundService
      ↓
ExecuteAsync()
      ↓
CancellationToken
      ↓
Dependency Injection
      ↓
Business Processing
      ↓
Logging
      ↓
Publish
      ↓
Windows Service
      ↓
Service Control Manager
      ↓
Recovery + Monitoring&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This architecture provides a clean foundation for building background processing applications such as order processors, file processors, synchronization services, scheduled jobs, notification services, and enterprise integration services.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Windows Services continue to be useful for long-running background workloads on Windows servers.&lt;/p&gt;&lt;p&gt;With modern .NET, the preferred approach is to build the application using the Worker Service/&lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt; model and then integrate it with Windows Service hosting.&lt;/p&gt;&lt;p&gt;The important distinction is:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt; implements the background work, while Windows Service hosting allows Windows to manage the application&#39;s lifecycle.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Once this foundation is understood, the same Worker Service concepts can be extended to SQL Server processing, REST APIs, Azure Service Bus, RabbitMQ, file processing, scheduled jobs, monitoring, and other enterprise workloads.&lt;/p&gt;&lt;h3&gt;Official Microsoft references&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?utm_source=chatgpt.com&quot;&gt;Create a Windows Service using BackgroundService — Microsoft Learn&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/ga-ie/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-7.0&amp;amp;utm_source=chatgpt.com&quot;&gt;Host ASP.NET Core in a Windows Service — Microsoft Learn&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.nuget.org/packages/Microsoft.Extensions.Hosting.WindowsServices/9.0.17?utm_source=chatgpt.com&quot;&gt;Microsoft.Extensions.Hosting.WindowsServices — NuGet&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you want, I can next turn this into a &lt;strong&gt;professional blog thumbnail + architecture diagram&lt;/strong&gt;, or convert the complete article into &lt;strong&gt;Telugu&lt;/strong&gt;.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/2432916582704150933/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/2432916582704150933' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/2432916582704150933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/2432916582704150933'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/working-with-windows-services-in-net.html' title='Working with Windows Services in .NET — Complete Guide from Scratch to Production'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhL6WiYGrvME8K_u3WCRVNysZc7QjvvQe_f-N-5B4yawFFmCPk0IkteKQeXFBS2bi4n7QzJIyZ76GWdXAchc57qn7MXBI5WA3i9ZrK98aH683O5gMq3912CLlZy-sUUI524VyAzAk0Jh0O-0OfQsDgPOyn63wWo1LXMhZUKUqzthgNiyXMkfi-X6m1Wr1E/s72-w550-h261-c/windowservice.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-1682666373464231463</id><published>2026-08-21T09:49:56.147+05:30</published><updated>2026-08-21T09:49:56.147+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Service Life Cycle in .NET Core Application"/><title type='text'>Service Life Cycle in .NET Core Application</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghp3gnxz9m0gCjwgQhG5BLdihrTef_IVhSJboEWUV5k8PPTOqhqbWQuXvc4pHzUWZfV6OFWPvWdvTmqapao-ffy55itL7NYXvDXAOH5mB1Bgv1DfViOSnl1aOmvPs_e5Lb5ieAGiEk_J9oI2efLsG6J51CjDsFfKRAMSp_RXdx0wYQ28BVRtLWN2c_bI/s1536/ServiceLifeCyclw.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;306&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghp3gnxz9m0gCjwgQhG5BLdihrTef_IVhSJboEWUV5k8PPTOqhqbWQuXvc4pHzUWZfV6OFWPvWdvTmqapao-ffy55itL7NYXvDXAOH5mB1Bgv1DfViOSnl1aOmvPs_e5Lb5ieAGiEk_J9oI2efLsG6J51CjDsFfKRAMSp_RXdx0wYQ28BVRtLWN2c_bI/w563-h306/ServiceLifeCyclw.png&quot; width=&quot;563&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Transient vs Scoped vs Singleton with Real-Time E-Commerce Example&lt;/h2&gt;&lt;p&gt;Dependency Injection (DI) is one of the most important concepts in ASP.NET Core. It helps us create loosely coupled, maintainable, testable, and scalable applications.&lt;/p&gt;&lt;p&gt;One of the most frequently asked .NET interview questions is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;What is Service Lifetime in .NET Core? Explain Transient, Scoped, and Singleton with a real-time example.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;To understand this properly, we need to understand what happens to a service from the moment it is requested until the moment it is destroyed.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. What is Service Life Cycle?&lt;/h1&gt;&lt;p&gt;A &lt;strong&gt;Service Life Cycle&lt;/strong&gt; defines:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;When an object is created&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How long that object lives&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Whether the same object is reused&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;When the object is destroyed&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In ASP.NET Core, the built-in Dependency Injection container provides three primary service lifetimes:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Transient&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scoped&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Singleton&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The basic idea is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application Starts
       |
       v
DI Container Created
       |
       v
Request Comes
       |
       v
Controller / Service Requests Dependency
       |
       v
DI Container Checks Service Lifetime
       |
       +-------------------+
       |                   |
   Transient           Scoped
       |                   |
New instance          One per Request
       |                   |
       +---------+---------+
                 |
              Singleton
                 |
          One per Application&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;2. Dependency Injection in ASP.NET Core&lt;/h1&gt;&lt;p&gt;Suppose we have an e-commerce application.&lt;/p&gt;&lt;p&gt;A request comes to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders/1001&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The request reaches the controller:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrdersController : ControllerBase
{
    private readonly IOrderService _orderService;

    public OrdersController(IOrderService orderService)
    {
        _orderService = orderService;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ASP.NET Core needs to create &lt;code inline=&quot;&quot;&gt;IOrderService&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;It looks into the DI container and asks:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;How is IOrderService registered?
What is its lifetime?
Should I create a new instance?
Can I reuse an existing instance?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddScoped&amp;lt;IOrderService, OrderService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This tells ASP.NET Core:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Create one &lt;code inline=&quot;&quot;&gt;OrderService&lt;/code&gt; instance for each HTTP request and reuse it throughout that request.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;3. The Three Service Lifetimes&lt;/h1&gt;&lt;p&gt;The three important registrations are:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;services.AddTransient&amp;lt;IService, Service&amp;gt;();

services.AddScoped&amp;lt;IService, Service&amp;gt;();

services.AddSingleton&amp;lt;IService, Service&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Their behavior is different.&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Lifetime&lt;/th&gt;&lt;th&gt;Instance Creation&lt;/th&gt;&lt;th&gt;Lifetime&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Transient&lt;/td&gt;&lt;td&gt;New instance every time requested&lt;/td&gt;&lt;td&gt;Very short&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Scoped&lt;/td&gt;&lt;td&gt;One instance per HTTP request&lt;/td&gt;&lt;td&gt;Request lifetime&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Singleton&lt;/td&gt;&lt;td&gt;One instance for application&lt;/td&gt;&lt;td&gt;Application lifetime&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Let&#39;s understand each one with a real-time example.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;4. Transient Lifetime&lt;/h1&gt;&lt;p&gt;Transient means:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;A new object is created every time the service is requested from the DI container.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Registration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddTransient&amp;lt;IEmailService, EmailService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IEmailService
{
    void SendEmail();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Implementation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class EmailService : IEmailService
{
    public EmailService()
    {
        Console.WriteLine(&quot;EmailService Created&quot;);
    }

    public void SendEmail()
    {
        Console.WriteLine(&quot;Email Sent&quot;);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now imagine:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderService
{
    private readonly IEmailService _emailService;

    public OrderService(IEmailService emailService)
    {
        _emailService = emailService;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Another service also requests:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class NotificationService
{
    private readonly IEmailService _emailService;

    public NotificationService(IEmailService emailService)
    {
        _emailService = emailService;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Because &lt;code inline=&quot;&quot;&gt;EmailService&lt;/code&gt; is transient:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderService
     |
     +---- EmailService Instance #1

NotificationService
     |
     +---- EmailService Instance #2&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Two different objects are created.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Real-Time Use Cases for Transient&lt;/h1&gt;&lt;p&gt;Transient is suitable for lightweight, stateless services.&lt;/p&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Email Formatter
Message Formatter
DTO Mapper
Validation Service
Small Calculation Service
Data Transformation Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddTransient&amp;lt;IPriceCalculator, PriceCalculator&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Every time &lt;code inline=&quot;&quot;&gt;IPriceCalculator&lt;/code&gt; is requested, a new instance can be created.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. Scoped Lifetime&lt;/h1&gt;&lt;p&gt;Scoped is probably the most commonly used lifetime in ASP.NET Core Web API applications.&lt;/p&gt;&lt;p&gt;Registration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddScoped&amp;lt;IOrderService, OrderService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Scoped means:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;One instance is created for a particular scope. In ASP.NET Core Web API, the scope normally corresponds to one HTTP request.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Consider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The request enters ASP.NET Core.&lt;/p&gt;&lt;p&gt;ASP.NET Core creates a request scope.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HTTP Request
     |
     v
Request Scope Created
     |
     +---- OrderService
     |
     +---- CustomerService
     |
     +---- Repository
     |
     +---- DbContext
     |
     v
Request Completed
     |
     v
Request Scope Destroyed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;All scoped services requested during that request can share their scoped instance.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;7. Real-Time Example – E-Commerce Order&lt;/h1&gt;&lt;p&gt;Consider an e-commerce application.&lt;/p&gt;&lt;p&gt;The request:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;requires:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrdersController
       |
       v
OrderService
       |
       v
OrderRepository
       |
       v
ApplicationDbContext&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Registration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddScoped&amp;lt;IOrderService, OrderService&amp;gt;();
builder.Services.AddScoped&amp;lt;IOrderRepository, OrderRepository&amp;gt;();
builder.Services.AddScoped&amp;lt;ApplicationDbContext&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;During Request #1:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request #1

OrderService       ---&amp;gt; Instance A
OrderRepository    ---&amp;gt; Instance A
DbContext          ---&amp;gt; Instance A&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Another request arrives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Request #2 gets different scoped objects:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request #2

OrderService       ---&amp;gt; Instance B
OrderRepository    ---&amp;gt; Instance B
DbContext           ---&amp;gt; Instance B&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request #1
   |
   +-- OrderService A
   +-- Repository A
   +-- DbContext A


Request #2
   |
   +-- OrderService B
   +-- Repository B
   +-- DbContext B&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This isolation is one of the major reasons why &lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt; is normally registered as &lt;strong&gt;Scoped&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. Why DbContext is Usually Scoped&lt;/h1&gt;&lt;p&gt;Consider an order transaction:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Create Order
     |
     +-- Insert Order
     |
     +-- Insert Order Items
     |
     +-- Update Inventory
     |
     +-- SaveChanges()&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The same &lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt; can track entities involved in that request.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderService
{
    private readonly ApplicationDbContext _context;

    public OrderService(ApplicationDbContext context)
    {
        _context = context;
    }

    public async Task CreateOrder(Order order)
    {
        _context.Orders.Add(order);

        await _context.SaveChangesAsync();
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using a scoped context helps keep the database unit of work associated with the request.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. Singleton Lifetime&lt;/h1&gt;&lt;p&gt;Singleton means:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Only one instance of the service is created for the application&#39;s DI container lifetime, and that instance is reused wherever the service is requested.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Registration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddSingleton&amp;lt;IApplicationConfiguration, ApplicationConfiguration&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application Starts
       |
       v
Singleton Instance Created
       |
       +-----------------------+
       |                       |
Request 1                  Request 2
       |                       |
       +----------+------------+
                  |
          Same Singleton&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The same object can be reused across requests.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. Real-Time Singleton Example&lt;/h1&gt;&lt;p&gt;Suppose our application has application-wide configuration.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IApplicationConfiguration
{
    string ApplicationName { get; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Implementation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class ApplicationConfiguration : IApplicationConfiguration
{
    public string ApplicationName =&amp;gt; &quot;E-Commerce API&quot;;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Registration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddSingleton&amp;lt;
    IApplicationConfiguration,
    ApplicationConfiguration&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now multiple requests can use the same instance.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request 1 ----+
              |
Request 2 ----+----&amp;gt; ApplicationConfiguration
              |
Request 3 ----+&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Real-Time Example – Product Cache&lt;/h1&gt;&lt;p&gt;Suppose an application frequently reads product categories.&lt;/p&gt;&lt;p&gt;Instead of querying the database repeatedly, we may maintain an application-level cache.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class ProductCache
{
    private readonly Dictionary&amp;lt;int, string&amp;gt; _products
        = new();

    public void Add(int id, string name)
    {
        _products[id] = name;
    }

    public string? Get(int id)
    {
        return _products.TryGetValue(id, out var name)
            ? name
            : null;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Registration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddSingleton&amp;lt;ProductCache&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The same cache object can be shared by requests.&lt;/p&gt;&lt;p&gt;However, when using mutable shared state, thread safety must be considered carefully. A singleton should not simply contain an ordinary mutable collection and assume concurrent requests are safe.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Complete E-Commerce Example&lt;/h1&gt;&lt;p&gt;Let&#39;s build a simplified dependency chain.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrdersController
       |
       v
OrderService
       |
       +---- OrderRepository
       |
       +---- PaymentService
       |
       +---- EmailService
       |
       +---- ApplicationCache
       |
       v
ApplicationDbContext&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Possible registrations:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddControllers();

builder.Services.AddScoped&amp;lt;IOrderService, OrderService&amp;gt;();

builder.Services.AddScoped&amp;lt;IOrderRepository, OrderRepository&amp;gt;();

builder.Services.AddScoped&amp;lt;IPaymentService, PaymentService&amp;gt;();

builder.Services.AddTransient&amp;lt;IEmailService, EmailService&amp;gt;();

builder.Services.AddSingleton&amp;lt;ProductCache&amp;gt;();

builder.Services.AddDbContext&amp;lt;ApplicationDbContext&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now each service has an appropriate lifetime based on its responsibilities.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. What Happens During an HTTP Request?&lt;/h1&gt;&lt;p&gt;Let&#39;s follow a request step-by-step.&lt;/p&gt;&lt;p&gt;Request:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;Step 1 – Request Arrives&lt;/h2&gt;&lt;p&gt;The client sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;POST /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ASP.NET Core receives the request.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Step 2 – Request Scope Is Created&lt;/h2&gt;&lt;p&gt;ASP.NET Core creates a scope for the HTTP request.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request Scope
     |
     +-------------------------+
     |                         |
     v                         v
Scoped Services          Other Dependencies&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 3 – Controller Is Created&lt;/h2&gt;&lt;p&gt;ASP.NET Core needs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;OrdersController&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Its constructor requires:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;IOrderService&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The DI container resolves it.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Step 4 – Scoped OrderService Is Created&lt;/h2&gt;&lt;p&gt;Because it is registered as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;AddScoped&amp;lt;IOrderService, OrderService&amp;gt;()&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ASP.NET Core creates one instance for this request.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Step 5 – Dependencies Are Resolved&lt;/h2&gt;&lt;p&gt;Suppose &lt;code inline=&quot;&quot;&gt;OrderService&lt;/code&gt; requires:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;IOrderRepository
IPaymentService
IEmailService&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The DI container resolves them.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderService
     |
     +-- OrderRepository    Scoped
     |
     +-- PaymentService     Scoped
     |
     +-- EmailService       Transient&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 6 – DbContext Is Resolved&lt;/h2&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;OrderRepository&lt;/code&gt; requires:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;ApplicationDbContext&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Because &lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt; is scoped, the request receives its scoped instance.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderService
      |
      v
OrderRepository
      |
      v
ApplicationDbContext&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 7 – Singleton Is Resolved&lt;/h2&gt;&lt;p&gt;Suppose &lt;code inline=&quot;&quot;&gt;ProductCache&lt;/code&gt; is needed.&lt;/p&gt;&lt;p&gt;The DI container checks:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Is ProductCache already created?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If yes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Use existing instance&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If no:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Create singleton instance&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 8 – Request Executes&lt;/h2&gt;&lt;p&gt;The order is processed.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Validate Order
      |
      v
Check Product
      |
      v
Create Order
      |
      v
Process Payment
      |
      v
Save Database Changes
      |
      v
Send Notification&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 9 – Request Completes&lt;/h2&gt;&lt;p&gt;The HTTP request ends.&lt;/p&gt;&lt;p&gt;ASP.NET Core disposes the request scope.&lt;/p&gt;&lt;p&gt;Scoped and transient disposable services associated with that scope are disposed according to the DI container&#39;s lifetime management.&lt;/p&gt;&lt;p&gt;The singleton remains alive while its container remains alive.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. Visualizing All Three Lifetimes&lt;/h1&gt;&lt;p&gt;Imagine three HTTP requests.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                  APPLICATION
                      |
             Singleton Instance
                      |
          +-----------+-----------+
          |           |           |
       Request 1   Request 2   Request 3
          |           |           |
       Scoped A    Scoped B    Scoped C
          |           |           |
       Transient   Transient   Transient
          A           B           C&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important point is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Singleton
   |
   +-- Same instance across requests

Scoped
   |
   +-- Same instance within one request
   +-- Different instance for another request

Transient
   |
   +-- New instance whenever resolved&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. Important Difference: Scoped vs Transient&lt;/h1&gt;&lt;p&gt;This is a common interview question.&lt;/p&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddScoped&amp;lt;IService, MyService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and the same service is requested twice within one scope.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request
  |
  +-- Resolve IService ---&amp;gt; Instance A
  |
  +-- Resolve IService ---&amp;gt; Instance A&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Same instance.&lt;/p&gt;&lt;p&gt;With:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddTransient&amp;lt;IService, MyService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;you can get:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request
  |
  +-- Resolve IService ---&amp;gt; Instance A
  |
  +-- Resolve IService ---&amp;gt; Instance B&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Different instances.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. Important Difference: Scoped vs Singleton&lt;/h1&gt;&lt;p&gt;Scoped:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request 1 ---&amp;gt; Instance A
Request 2 ---&amp;gt; Instance B
Request 3 ---&amp;gt; Instance C&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Singleton:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request 1 ---+
Request 2 ---+---&amp;gt; Same Instance A
Request 3 ---+&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore, singleton services should be designed very carefully because multiple requests can access the same instance concurrently.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. Can Singleton Depend on Scoped Service?&lt;/h1&gt;&lt;p&gt;This is an important interview question.&lt;/p&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddSingleton&amp;lt;MySingleton&amp;gt;();
builder.Services.AddScoped&amp;lt;MyScoped&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class MySingleton
{
    private readonly MyScoped _scoped;

    public MySingleton(MyScoped scoped)
    {
        _scoped = scoped;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This creates a lifetime mismatch.&lt;/p&gt;&lt;p&gt;A singleton lives much longer than a scoped service.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Singleton
     |
     v
Scoped Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The scoped service cannot naturally live for the entire lifetime of the singleton.&lt;/p&gt;&lt;p&gt;ASP.NET Core&#39;s DI validation can detect such captive dependency problems in appropriate environments/configurations.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;General rule:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Singleton
   ↓
Should not directly depend on
   ↓
Scoped&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;18. Can Scoped Depend on Singleton?&lt;/h1&gt;&lt;p&gt;Yes.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Scoped OrderService
        |
        v
Singleton ApplicationConfiguration&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is generally valid because the singleton has a lifetime longer than the scoped service.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;19. Can Transient Depend on Scoped?&lt;/h1&gt;&lt;p&gt;Within a valid request scope, yes.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Scoped OrderService
        |
        v
Transient EmailFormatter&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The transient object is created for the resolution and can use dependencies available in that scope.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;20. Can Singleton Depend on Transient?&lt;/h1&gt;&lt;p&gt;This requires careful consideration.&lt;/p&gt;&lt;p&gt;Technically, a singleton can resolve a transient dependency during its construction, but that transient instance then effectively becomes held by the singleton for as long as the singleton holds it.&lt;/p&gt;&lt;p&gt;Therefore, the dependency&#39;s effective lifetime can become much longer than intended.&lt;/p&gt;&lt;p&gt;This is sometimes called a &lt;strong&gt;captive dependency&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;So don&#39;t choose lifetimes merely because the DI container allows the registration.&lt;/p&gt;&lt;p&gt;Choose them based on the object&#39;s state and responsibilities.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;21. Service Lifetime and Thread Safety&lt;/h1&gt;&lt;p&gt;This is especially important for Singleton services.&lt;/p&gt;&lt;p&gt;Imagine:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class CounterService
{
    private int _count;

    public void Increment()
    {
        _count++;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If registered as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddSingleton&amp;lt;CounterService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;multiple requests may access the same object concurrently.&lt;/p&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request A ----+
              |
Request B ----+----&amp;gt; Same Singleton
              |
Request C ----+&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The implementation must be safe for concurrent access.&lt;/p&gt;&lt;p&gt;For shared mutable state, use appropriate thread-safe techniques or concurrency-safe collections where necessary.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Service Lifetime in Microservices&lt;/h1&gt;&lt;p&gt;In a microservices architecture, each microservice normally has its own DI container and process/application lifetime.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
     |
     +-- Singleton
     +-- Scoped
     +-- Transient

Payment Service
     |
     +-- Singleton
     +-- Scoped
     +-- Transient

Inventory Service
     |
     +-- Singleton
     +-- Scoped
     +-- Transient&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A singleton in the Order Service is &lt;strong&gt;not automatically shared with the Payment Service&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Each application has its own process/container and its own DI registrations.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;23. Service Lifetime vs Database Lifetime&lt;/h1&gt;&lt;p&gt;Don&#39;t confuse these concepts.&lt;/p&gt;&lt;p&gt;Service lifetime:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Transient
Scoped
Singleton&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Database connection lifetime is a separate concern.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Web API
   |
   v
DbContext
   |
   v
Database Provider
   |
   v
Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt; is normally scoped, while the underlying database connection management is handled by the database provider and connection pooling mechanisms.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;24. Common Real-Time Registration&lt;/h1&gt;&lt;p&gt;A typical ASP.NET Core application might contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddControllers();

builder.Services.AddDbContext&amp;lt;ApplicationDbContext&amp;gt;();

builder.Services.AddScoped&amp;lt;IOrderService, OrderService&amp;gt;();
builder.Services.AddScoped&amp;lt;IOrderRepository, OrderRepository&amp;gt;();

builder.Services.AddScoped&amp;lt;IPaymentService, PaymentService&amp;gt;();

builder.Services.AddTransient&amp;lt;IEmailTemplateService, EmailTemplateService&amp;gt;();

builder.Services.AddSingleton&amp;lt;IApplicationSettings, ApplicationSettings&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A reasonable conceptual mapping is:&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Service&lt;/th&gt;&lt;th&gt;Typical Lifetime&lt;/th&gt;&lt;th&gt;Reason&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;DbContext&lt;/td&gt;&lt;td&gt;Scoped&lt;/td&gt;&lt;td&gt;Request/unit-of-work oriented&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Repository&lt;/td&gt;&lt;td&gt;Scoped&lt;/td&gt;&lt;td&gt;Works with DbContext&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Business Service&lt;/td&gt;&lt;td&gt;Scoped&lt;/td&gt;&lt;td&gt;Request-level operation&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Stateless Formatter&lt;/td&gt;&lt;td&gt;Transient&lt;/td&gt;&lt;td&gt;Lightweight/stateless&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Application Configuration&lt;/td&gt;&lt;td&gt;Singleton&lt;/td&gt;&lt;td&gt;Shared application-level data&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;In-memory Cache&lt;/td&gt;&lt;td&gt;Singleton&lt;/td&gt;&lt;td&gt;Shared cache, if designed safely&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;These are common patterns, not absolute rules.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;25. Service Life Cycle and IDisposable&lt;/h1&gt;&lt;p&gt;Another important concept is disposal.&lt;/p&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class FileService : IDisposable
{
    public void Dispose()
    {
        Console.WriteLine(&quot;Disposed&quot;);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If the DI container creates and owns a disposable service, it generally manages its disposal according to the service lifetime and scope.&lt;/p&gt;&lt;p&gt;For example, a scoped disposable service is normally disposed when its request scope ends.&lt;/p&gt;&lt;p&gt;A singleton disposable service is normally disposed when the application&#39;s DI container is disposed.&lt;/p&gt;&lt;p&gt;This is one reason you should generally let the DI container manage dependencies that it creates rather than manually disposing injected dependencies.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. Service Lifetime and Background Services&lt;/h1&gt;&lt;p&gt;A common mistake is trying to inject a scoped service directly into a long-running &lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderBackgroundService : BackgroundService
{
    private readonly ApplicationDbContext _context;

    public OrderBackgroundService(ApplicationDbContext context)
    {
        _context = context;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is problematic because &lt;code inline=&quot;&quot;&gt;BackgroundService&lt;/code&gt; is effectively long-lived, while &lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt; is scoped.&lt;/p&gt;&lt;p&gt;A better approach is to create a scope when processing each unit of work:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderBackgroundService : BackgroundService
{
    private readonly IServiceScopeFactory _scopeFactory;

    public OrderBackgroundService(IServiceScopeFactory scopeFactory)
    {
        _scopeFactory = scopeFactory;
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        using var scope = _scopeFactory.CreateScope();

        var dbContext =
            scope.ServiceProvider
                 .GetRequiredService&amp;lt;ApplicationDbContext&amp;gt;();

        // Process work
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For repeated background work, create and dispose an appropriate scope for each unit of work rather than keeping one scoped dependency forever.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. How DI Container Resolves a Service&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddScoped&amp;lt;IOrderService, OrderService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderService : IOrderService
{
    private readonly IOrderRepository _repository;

    public OrderService(IOrderRepository repository)
    {
        _repository = repository;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When the controller requests &lt;code inline=&quot;&quot;&gt;IOrderService&lt;/code&gt;, the DI container performs roughly this process:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1. Controller requests IOrderService
             |
             v
2. DI Container checks registration
             |
             v
3. Finds OrderService
             |
             v
4. Checks OrderService lifetime
             |
             v
5. Scoped
             |
             v
6. Checks current scope
             |
             v
7. Creates OrderService if not already created
             |
             v
8. Sees IOrderRepository dependency
             |
             v
9. Resolves IOrderRepository
             |
             v
10. Creates OrderService
             |
             v
11. Injects dependencies
             |
             v
12. Controller receives OrderService&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is the essence of Dependency Injection.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;28. Real-Time Request Example&lt;/h1&gt;&lt;p&gt;Let&#39;s assume:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer places an order&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Request:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Flow:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Client
  |
  | HTTP Request
  v
ASP.NET Core
  |
  v
Middleware Pipeline
  |
  v
Request Scope
  |
  v
OrdersController
  |
  v
OrderService
  |
  +---- OrderRepository
  |          |
  |          v
  |      DbContext
  |
  +---- PaymentService
  |
  +---- EmailService
  |
  +---- ProductCache
  |
  v
Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Lifetimes might be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderService        -&amp;gt; Scoped
OrderRepository     -&amp;gt; Scoped
DbContext           -&amp;gt; Scoped
PaymentService      -&amp;gt; Scoped
EmailService        -&amp;gt; Transient
ProductCache        -&amp;gt; Singleton&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;At the end:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HTTP Request Ends
       |
       v
Request Scope Disposed
       |
       +-- Scoped services disposed
       +-- Request-owned transient disposables disposed
       |
       v
Singleton remains available&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;29. Common Interview Questions&lt;/h1&gt;&lt;h2&gt;Q1. What are the three service lifetimes?&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Transient
Scoped
Singleton&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Q2. What is Transient?&lt;/h2&gt;&lt;p&gt;A new service instance is created each time the service is requested from the DI container.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;services.AddTransient&amp;lt;IEmailService, EmailService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Q3. What is Scoped?&lt;/h2&gt;&lt;p&gt;One service instance is generally created per scope. In ASP.NET Core Web API, this normally means one instance per HTTP request.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;services.AddScoped&amp;lt;IOrderService, OrderService&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Q4. What is Singleton?&lt;/h2&gt;&lt;p&gt;One service instance is reused for the lifetime of the DI container/application.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;services.AddSingleton&amp;lt;ICache, Cache&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Q5. Which lifetime is normally used for DbContext?&lt;/h2&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt; is normally registered as &lt;strong&gt;Scoped&lt;/strong&gt; in ASP.NET Core applications.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Q6. Why shouldn&#39;t DbContext normally be Singleton?&lt;/h2&gt;&lt;p&gt;Because &lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt; is designed around a unit-of-work pattern and is not intended to be shared concurrently across unrelated requests.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Q7. Which lifetime is best for stateless lightweight services?&lt;/h2&gt;&lt;p&gt;Often &lt;strong&gt;Transient&lt;/strong&gt;, although Scoped can also be appropriate depending on the service&#39;s dependencies and design.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Q8. Which lifetime is best for shared application-wide state?&lt;/h2&gt;&lt;p&gt;A &lt;strong&gt;Singleton&lt;/strong&gt; can be appropriate, but shared mutable state must be designed for concurrent access and application lifetime.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Q9. Can Singleton depend on Scoped?&lt;/h2&gt;&lt;p&gt;Generally, &lt;strong&gt;no direct dependency should be created&lt;/strong&gt;, because it creates a lifetime mismatch/captive dependency.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Q10. Can Scoped depend on Singleton?&lt;/h2&gt;&lt;p&gt;Yes. This is generally valid.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;30. Common Mistakes&lt;/h1&gt;&lt;h3&gt;Mistake 1 – Making Everything Singleton&lt;/h3&gt;&lt;p&gt;Avoid:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;services.AddSingleton&amp;lt;OrderService&amp;gt;();
services.AddSingleton&amp;lt;OrderRepository&amp;gt;();
services.AddSingleton&amp;lt;ApplicationDbContext&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can create serious lifetime and concurrency problems.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Mistake 2 – Making Everything Transient&lt;/h3&gt;&lt;p&gt;Using transient everywhere can cause unnecessary object creation and can undermine intentional request-level sharing.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Mistake 3 – Ignoring Thread Safety&lt;/h3&gt;&lt;p&gt;Singleton services may be accessed concurrently.&lt;/p&gt;&lt;p&gt;Never assume:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Singleton = Automatically Thread Safe&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It is not.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Mistake 4 – Injecting Scoped Services into Long-Lived Services&lt;/h3&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BackgroundService
       |
       v
DbContext&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead, create a scope when processing the background operation.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;31. Easy Way to Remember&lt;/h1&gt;&lt;p&gt;Remember this formula:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Transient = Every Time

Scoped = Every Request

Singleton = Entire Application&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Or:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Transient
    ↓
New Object

Scoped
    ↓
One Object Per Scope

Singleton
    ↓
One Object Per Container Lifetime&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;32. Final Comparison&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Transient&lt;/th&gt;&lt;th&gt;Scoped&lt;/th&gt;&lt;th&gt;Singleton&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;New instance frequently?&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Same instance within request?&lt;/td&gt;&lt;td&gt;Not necessarily&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Same instance across requests?&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Typical lifetime&lt;/td&gt;&lt;td&gt;Resolution&lt;/td&gt;&lt;td&gt;Scope/request&lt;/td&gt;&lt;td&gt;Application/container&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Thread safety concern&lt;/td&gt;&lt;td&gt;Usually less shared state&lt;/td&gt;&lt;td&gt;Usually less shared across requests&lt;/td&gt;&lt;td&gt;High if mutable&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;DbContext&lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;td&gt;✅&lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Repository&lt;/td&gt;&lt;td&gt;Usually Scoped&lt;/td&gt;&lt;td&gt;✅&lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Stateless lightweight service&lt;/td&gt;&lt;td&gt;✅&lt;/td&gt;&lt;td&gt;Sometimes&lt;/td&gt;&lt;td&gt;Sometimes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Application-wide cache&lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;td&gt;✅, if designed safely&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Configuration service&lt;/td&gt;&lt;td&gt;Sometimes&lt;/td&gt;&lt;td&gt;Sometimes&lt;/td&gt;&lt;td&gt;Often&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;33. Complete Mental Model&lt;/h1&gt;&lt;p&gt;When you see:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddTransient&amp;lt;A&amp;gt;();
builder.Services.AddScoped&amp;lt;B&amp;gt;();
builder.Services.AddSingleton&amp;lt;C&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;think:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    DI CONTAINER
                         |
        +----------------+----------------+
        |                |                |
        v                v                v
    TRANSIENT         SCOPED          SINGLETON
        |                |                |
     New Object       One per Scope    One per Container
        |                |                |
        |           HTTP Request       Application
        |                |                |
        v                v                v
     A1, A2...          B1              C1
                       B2              C1
                       B3              C1&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The key idea is that &lt;strong&gt;service lifetime is not merely about object creation—it determines how long the object can retain state and who can share that state.&lt;/strong&gt;&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Service Lifetime is a fundamental part of Dependency Injection in ASP.NET Core.&lt;/p&gt;&lt;p&gt;The three primary lifetimes are:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Transient → New instance when resolved

Scoped → One instance per scope/request

Singleton → One instance for the DI container lifetime&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a real-world e-commerce Web API, a common design is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Controller
    |
    v
OrderService        → Scoped
    |
    +---- Repository → Scoped
    |
    +---- DbContext  → Scoped
    |
    +---- Payment    → Scoped
    |
    +---- Email      → Transient
    |
    +---- Cache      → Singleton&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Choosing the correct lifetime is important for:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Performance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Memory management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Thread safety&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Database consistency&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Resource management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Scalability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Application stability&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The most important interview rule to remember is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Transient = new instance, Scoped = one instance per scope/request, Singleton = one instance for the container lifetime.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Once you understand this concept, Dependency Injection, &lt;code inline=&quot;&quot;&gt;DbContext&lt;/code&gt;, middleware, background services, repositories, caching, and ASP.NET Core application architecture become much easier to understand.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/1682666373464231463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/1682666373464231463' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1682666373464231463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1682666373464231463'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/service-life-cycle-in-net-core.html' title='Service Life Cycle in .NET Core Application'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghp3gnxz9m0gCjwgQhG5BLdihrTef_IVhSJboEWUV5k8PPTOqhqbWQuXvc4pHzUWZfV6OFWPvWdvTmqapao-ffy55itL7NYXvDXAOH5mB1Bgv1DfViOSnl1aOmvPs_e5Lb5ieAGiEk_J9oI2efLsG6J51CjDsFfKRAMSp_RXdx0wYQ28BVRtLWN2c_bI/s72-w563-h306-c/ServiceLifeCyclw.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-5298848814330002196</id><published>2026-08-21T09:21:49.404+05:30</published><updated>2026-08-21T09:21:49.405+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JWT Authentication &amp; Authorization — Complete Flow"/><title type='text'>JWT Authentication &amp; Authorization — Complete Flow</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbOKYlFDvkkB-O__qvWeAzyIWtHDwBK6qwe_GLt0M2MaQl-7ZdJX1g0PQzxrwCCyIeb9TIuHq5UDsUclJNboQJPSw9Nb5qhb9zOVlt45h8sZsrHyKCfss-NNR0Jr_p9IwCxC7Flb5k7R70dlvJNYDf6WIPus1A7Ofk1-35pvfEOYbRgKqQzX5pTSqUYoA/s1536/JWT.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;325&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbOKYlFDvkkB-O__qvWeAzyIWtHDwBK6qwe_GLt0M2MaQl-7ZdJX1g0PQzxrwCCyIeb9TIuHq5UDsUclJNboQJPSw9Nb5qhb9zOVlt45h8sZsrHyKCfss-NNR0Jr_p9IwCxC7Flb5k7R70dlvJNYDf6WIPus1A7Ofk1-35pvfEOYbRgKqQzX5pTSqUYoA/w564-h325/JWT.png&quot; width=&quot;564&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;h1&gt;Imagine the application has:&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Angular / React frontend&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ASP.NET Core Web API&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL Server database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JWT-based authentication&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The overall flow is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User
  |
  | 1. Login: username + password
  v
Frontend
  |
  | 2. POST /api/auth/login
  v
Web API
  |
  | 3. Validate credentials
  v
Database
  |
  | 4. User is valid
  v
Web API
  |
  | 5. Create JWT
  v
Frontend
  |
  | 6. Store JWT
  |
  | 7. Send JWT in Authorization Header
  v
Web API
  |
  | 8. Validate JWT
  |
  | 9. Authentication
  |
  | 10. Authorization
  v
Controller
  |
  v
Response&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now let&#39;s understand every step.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. What problem does JWT solve?&lt;/h1&gt;&lt;p&gt;Suppose a user logs into your application.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Username: mahesh
Password: ********&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The API verifies the username and password.&lt;/p&gt;&lt;p&gt;But after login, the API needs to know:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Who is making this next request?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The API needs to know:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Which user?
Is the user authenticated?
What roles does the user have?
Is the user allowed to access orders?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;JWT provides a way for the client to prove its identity on subsequent requests.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. Where does the JWT flow start?&lt;/h1&gt;&lt;p&gt;The JWT authentication flow starts when the user performs &lt;strong&gt;login&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/auth/login&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Request:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &quot;username&quot;: &quot;mahesh&quot;,
    &quot;password&quot;: &quot;Password123&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The request reaches the Authentication API.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Step 1 — User sends credentials&lt;/h1&gt;&lt;p&gt;The frontend sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Username
Password&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;POST /api/auth/login&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular Application
       |
       | username + password
       v
ASP.NET Core Web API&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The password should be transmitted over &lt;strong&gt;HTTPS&lt;/strong&gt;, not plain HTTP.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;4. Step 2 — API validates the user&lt;/h1&gt;&lt;p&gt;The API receives the credentials.&lt;/p&gt;&lt;p&gt;It queries the database:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT Id, UserName, PasswordHash, Role
FROM Users
WHERE UserName = &#39;mahesh&#39;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application should compare the supplied password against the stored &lt;strong&gt;password hash&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;It should &lt;strong&gt;not&lt;/strong&gt; store plain-text passwords.&lt;/p&gt;&lt;p&gt;If authentication fails:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;401 Unauthorized&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If authentication succeeds:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;UserId       = 101
Username     = mahesh
Role         = Customer&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the API can create a JWT.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Step 3 — JWT is created&lt;/h1&gt;&lt;p&gt;A JWT normally looks like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;xxxxx.yyyyy.zzzzz&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There are &lt;strong&gt;three parts&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HEADER.PAYLOAD.SIGNATURE&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
.
eyJzdWIiOiIxMDEiLCJyb2xlIjoiQ3VzdG9tZXIifQ
.
abc123xyz...&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;These three parts have different responsibilities.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. JWT Header&lt;/h1&gt;&lt;p&gt;The header contains information about the token.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;alg&quot;: &quot;HS256&quot;,
  &quot;typ&quot;: &quot;JWT&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;&lt;code inline=&quot;&quot;&gt;alg&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;This tells the receiver which signing algorithm is being used.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HS256&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;RS256&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;&lt;code inline=&quot;&quot;&gt;typ&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;This tells us the token type:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;JWT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HEADER
   |
   +-- Algorithm
   |
   +-- Token Type&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. JWT Payload&lt;/h1&gt;&lt;p&gt;The payload contains &lt;strong&gt;claims&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;sub&quot;: &quot;101&quot;,
  &quot;name&quot;: &quot;Mahesh&quot;,
  &quot;role&quot;: &quot;Customer&quot;,
  &quot;email&quot;: &quot;mahesh@example.com&quot;,
  &quot;exp&quot;: 1787220000
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;These are called &lt;strong&gt;claims&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Common claims include:&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Claim&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;sub&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Subject/User ID&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;User name&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;email&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Email&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;role&lt;/code&gt;&lt;/td&gt;&lt;td&gt;User role&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;iss&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Token issuer&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;aud&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Intended audience&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;iat&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Issued-at time&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;exp&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Expiration time&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
   &quot;sub&quot;: &quot;101&quot;,
   &quot;role&quot;: &quot;Admin&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;means:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User ID = 101
Role = Admin&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Important security point&lt;/h3&gt;&lt;p&gt;The JWT payload is &lt;strong&gt;encoded, not encrypted&lt;/strong&gt;, in a normal JWT.&lt;/p&gt;&lt;p&gt;Therefore, don&#39;t put sensitive information such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Password
Credit card number
Secret keys&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;inside the payload.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. JWT Signature&lt;/h1&gt;&lt;p&gt;This is the most important part for understanding JWT security.&lt;/p&gt;&lt;p&gt;Conceptually, the server takes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Base64Url(Header)
+
&quot;.&quot;
+
Base64Url(Payload)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and signs that data using a secret/private key.&lt;/p&gt;&lt;p&gt;For example, conceptually with HMAC:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Signature =
HMACSHA256(
    Base64Url(Header) + &quot;.&quot; +
    Base64Url(Payload),
    SecretKey
)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The result becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HEADER.PAYLOAD.SIGNATURE&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;9. Why do we need the Signature?&lt;/h1&gt;&lt;p&gt;Imagine the original payload is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &quot;userId&quot;: 101,
    &quot;role&quot;: &quot;Customer&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;An attacker might try to change it to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &quot;userId&quot;: 101,
    &quot;role&quot;: &quot;Admin&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But the attacker doesn&#39;t have the signing secret/private key.&lt;/p&gt;&lt;p&gt;Therefore, they cannot generate a valid signature for the modified payload.&lt;/p&gt;&lt;p&gt;When the API receives the token, it validates the signature.&lt;/p&gt;&lt;p&gt;If the token was modified:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Payload changed
      ↓
Signature no longer matches
      ↓
JWT validation fails
      ↓
401 Unauthorized&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So the signature provides &lt;strong&gt;integrity/authenticity of the token&lt;/strong&gt;, assuming the signing key is properly protected.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. JWT is returned to the client&lt;/h1&gt;&lt;p&gt;After successful login:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Web API
   |
   | JWT
   v
Frontend&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &quot;accessToken&quot;: &quot;eyJhbGciOiJIUzI1NiIs...&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the frontend has the access token.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;11. What happens on the next API request?&lt;/h1&gt;&lt;p&gt;Suppose the user wants to see orders.&lt;/p&gt;&lt;p&gt;Frontend sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But how does the API know who the user is?&lt;/p&gt;&lt;p&gt;The frontend sends the JWT using the HTTP &lt;strong&gt;Authorization header&lt;/strong&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;Authorization: Bearer eyJhbGciOiJIUzI1NiIs...&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is extremely important.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. What is the Authorization Header?&lt;/h1&gt;&lt;p&gt;The HTTP request looks like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There are two important pieces:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Authorization
      |
      +-- Bearer
      |
      +-- JWT Token&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;Bearer&lt;/code&gt; essentially means:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;The caller is presenting this access token as its credential.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;13. Complete request flow&lt;/h1&gt;&lt;p&gt;Now we can visualize the entire process:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    LOGIN
                      |
                      v
              +---------------+
              |    Frontend   |
              +---------------+
                      |
                      | username/password
                      v
              +---------------+
              |   Auth API    |
              +---------------+
                      |
                      | Validate credentials
                      v
              +---------------+
              |   Database    |
              +---------------+
                      |
                      | User valid
                      v
              +---------------+
              |   Auth API    |
              +---------------+
                      |
                      | Create JWT
                      v
          +-------------------------+
          | HEADER.PAYLOAD.SIGNATURE|
          +-------------------------+
                      |
                      | JWT
                      v
              +---------------+
              |    Frontend   |
              +---------------+&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                API REQUEST
                     |
                     v
              +-------------+
              |  Frontend   |
              +-------------+
                     |
                     | Authorization:
                     | Bearer JWT
                     v
              +-------------+
              |  Web API    |
              +-------------+
                     |
                     v
              JWT Middleware
                     |
             +-------+-------+
             |               |
          Invalid           Valid
             |               |
             v               v
           401          User.Identity
                           created
                              |
                              v
                       Authorization
                              |
                    +---------+---------+
                    |                   |
                 Allowed              Denied
                    |                   |
                    v                   v
                Controller             403&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;14. What happens inside ASP.NET Core?&lt;/h1&gt;&lt;p&gt;Suppose we have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[Authorize]
[HttpGet(&quot;orders&quot;)]
public IActionResult GetOrders()
{
    return Ok();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The request arrives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders
Authorization: Bearer &amp;lt;JWT&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ASP.NET Core&#39;s JWT authentication middleware processes the token &lt;strong&gt;before the controller action executes&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HTTP Request
     |
     v
ASP.NET Core Middleware
     |
     v
JWT Authentication Handler
     |
     v
Read Authorization Header
     |
     v
Extract Bearer Token
     |
     v
Validate JWT
     |
     v
Create ClaimsPrincipal
     |
     v
Authorization
     |
     v
Controller&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. JWT Validation&lt;/h1&gt;&lt;p&gt;The API validates several things depending on its configuration.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;h3&gt;Signature&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Is the signature valid?&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Issuer&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Who issued this token?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;https://my-auth-server&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Audience&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Is this token intended for my API?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;my-ecommerce-api&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Expiration&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Has the token expired?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &quot;exp&quot;: 1787220000
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If the current time is beyond the expiration time, the token is rejected.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. Authentication vs Authorization&lt;/h1&gt;&lt;p&gt;This is one of the most important interview questions.&lt;/p&gt;&lt;h2&gt;Authentication&lt;/h2&gt;&lt;p&gt;Authentication answers:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Who are you?&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User logs in
     ↓
Username/password validated
     ↓
JWT issued
     ↓
JWT presented to API
     ↓
API validates JWT
     ↓
User is authenticated&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Authentication establishes the user&#39;s identity.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. Authorization&lt;/h1&gt;&lt;p&gt;Authorization answers:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;What are you allowed to do?&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Suppose we have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Admin
Customer
Manager&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;JWT:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &quot;sub&quot;: &quot;101&quot;,
    &quot;role&quot;: &quot;Customer&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[Authorize]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;means:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;An authenticated user can access this endpoint.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;But:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[Authorize(Roles = &quot;Admin&quot;)]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;means:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Only authenticated users with the Admin role can access this endpoint.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;If a Customer calls it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Authenticated? YES

Authorized? NO

Result:
403 Forbidden&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;18. 401 vs 403&lt;/h1&gt;&lt;p&gt;This is another important interview question.&lt;/p&gt;&lt;h3&gt;401 Unauthorized&lt;/h3&gt;&lt;p&gt;Usually means:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Authentication failed / no valid authentication&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;No token
Invalid token
Expired token
Invalid signature&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Who are you?
→ I can&#39;t authenticate you.&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;403 Forbidden&lt;/h3&gt;&lt;p&gt;Means:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;You are authenticated,
but you don&#39;t have permission.&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User = Customer

Endpoint requires = Admin&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Result:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;403 Forbidden&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Think:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;401 = I don&#39;t know who you are.

403 = I know who you are,
      but you&#39;re not allowed.&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;19. Authentication + Authorization Example&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[Authorize]
[HttpGet(&quot;profile&quot;)]
public IActionResult Profile()
{
    return Ok();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Any authenticated user can access it.&lt;/p&gt;&lt;p&gt;But:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[Authorize(Roles = &quot;Admin&quot;)]
[HttpDelete(&quot;users/{id}&quot;)]
public IActionResult DeleteUser(int id)
{
    return Ok();
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Only Admin users can access it.&lt;/p&gt;&lt;p&gt;The flow becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;JWT
 |
 v
Signature validation
 |
 v
Token valid?
 |
 +---- NO ----&amp;gt; 401
 |
 YES
 |
 v
Authentication successful
 |
 v
Read Claims
 |
 v
Role = Customer?
 |
 v
Endpoint requires Admin
 |
 v
Authorization fails
 |
 v
403 Forbidden&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Where does the Role come from?&lt;/h1&gt;&lt;p&gt;The role can be included as a JWT claim.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &quot;sub&quot;: &quot;101&quot;,
    &quot;name&quot;: &quot;Mahesh&quot;,
    &quot;role&quot;: &quot;Admin&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ASP.NET Core converts JWT claims into a &lt;code inline=&quot;&quot;&gt;ClaimsPrincipal&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;You can then access claims:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var userId = User.FindFirst(&quot;sub&quot;)?.Value;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var role = User.FindFirst(&quot;role&quot;)?.Value;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Depending on configuration, role claims can also be accessed through:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;User.IsInRole(&quot;Admin&quot;)&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;21. How does ASP.NET Core know which JWT to validate?&lt;/h1&gt;&lt;p&gt;You configure JWT authentication in the application.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services
    .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =&amp;gt;
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidateAudience = true,
            ValidateLifetime = true,
            ValidateIssuerSigningKey = true,

            ValidIssuer = &quot;...&quot;,
            ValidAudience = &quot;...&quot;,
            IssuerSigningKey = ...
        };
    });&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;app.UseAuthentication();
app.UseAuthorization();&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The order is important:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;UseAuthentication()
        ↓
UseAuthorization()
        ↓
MapControllers()&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Authentication must establish the user&#39;s identity before authorization makes the access decision.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Why is the Header important?&lt;/h1&gt;&lt;p&gt;There are actually two places where &quot;header&quot; can mean different things.&lt;/p&gt;&lt;h2&gt;JWT Header&lt;/h2&gt;&lt;p&gt;Inside the JWT:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
   &quot;alg&quot;: &quot;HS256&quot;,
   &quot;typ&quot;: &quot;JWT&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This describes the token.&lt;/p&gt;&lt;h2&gt;HTTP Authorization Header&lt;/h2&gt;&lt;p&gt;Outside the JWT:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;Authorization: Bearer &amp;lt;token&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This transports the JWT from the client to the API.&lt;/p&gt;&lt;p&gt;So:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;JWT Header
     ↓
Describes JWT

HTTP Authorization Header
     ↓
Carries JWT to API&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Don&#39;t confuse these two.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;23. Complete E-Commerce Example&lt;/h1&gt;&lt;p&gt;Let&#39;s imagine an e-commerce application.&lt;/p&gt;&lt;p&gt;User:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Mahesh
UserId = 101
Role = Customer&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 1 — Login&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/auth/login&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
   &quot;username&quot;: &quot;mahesh&quot;,
   &quot;password&quot;: &quot;********&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 2 — Database validation&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Username exists?
        ↓
Password valid?
        ↓
Role = Customer
        ↓
YES&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 3 — JWT creation&lt;/h3&gt;&lt;p&gt;Payload:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
   &quot;sub&quot;: &quot;101&quot;,
   &quot;name&quot;: &quot;Mahesh&quot;,
   &quot;role&quot;: &quot;Customer&quot;,
   &quot;exp&quot;: &quot;...&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;JWT:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HEADER.PAYLOAD.SIGNATURE&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 4 — JWT returned&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Authentication API
       ↓
      JWT
       ↓
    Frontend&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 5 — Get orders&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders
Authorization: Bearer &amp;lt;JWT&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 6 — API validates JWT&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Token exists?
     ↓
Signature valid?
     ↓
Issuer valid?
     ↓
Audience valid?
     ↓
Token expired?
     ↓
All valid&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 7 — Authentication&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User = Mahesh
UserId = 101
Role = Customer&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 8 — Authorization&lt;/h3&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[Authorize]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Customer is allowed.&lt;/p&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Controller executes&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;24. What if the JWT is modified?&lt;/h1&gt;&lt;p&gt;Original:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
   &quot;userId&quot;: 101,
   &quot;role&quot;: &quot;Customer&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Attacker changes it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
   &quot;userId&quot;: 101,
   &quot;role&quot;: &quot;Admin&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The attacker doesn&#39;t have the signing key.&lt;/p&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Modified Payload
       ↓
Signature doesn&#39;t match
       ↓
JWT validation fails
       ↓
Authentication fails
       ↓
401&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is why the signature is critical.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;25. What if the JWT is expired?&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
   &quot;sub&quot;: &quot;101&quot;,
   &quot;exp&quot;: 1787220000
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The API checks:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Current time &amp;gt; exp?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If yes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Token expired
     ↓
Authentication fails
     ↓
401 Unauthorized&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The frontend can then obtain a new access token using an appropriate token renewal mechanism, such as a refresh-token flow, depending on the authentication architecture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. Does every API call query the User table?&lt;/h1&gt;&lt;p&gt;Not necessarily.&lt;/p&gt;&lt;p&gt;That&#39;s one of the major benefits of JWT.&lt;/p&gt;&lt;p&gt;For a properly configured self-contained JWT, the API can validate:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Signature
Issuer
Audience
Expiration
Claims&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;without querying the user database on every request.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request
   ↓
JWT
   ↓
Signature validation
   ↓
Claims
   ↓
Authorization
   ↓
Controller&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, applications sometimes still consult a database/cache for things such as account status, revocation, permissions that must change immediately, or other business rules.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. Where is the JWT stored?&lt;/h1&gt;&lt;p&gt;This depends on the frontend architecture and security requirements.&lt;/p&gt;&lt;p&gt;A common browser approach is to use secure cookie-based mechanisms, especially when designed to mitigate token theft/XSS risks.&lt;/p&gt;&lt;p&gt;Another approach is storing an access token in browser storage, but storing long-lived authentication tokens in &lt;code inline=&quot;&quot;&gt;localStorage&lt;/code&gt; has important security trade-offs because JavaScript can access it.&lt;/p&gt;&lt;p&gt;For a production system, token storage should be designed together with:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HTTPS
XSS protection
CSRF protection
Token lifetime
Refresh-token strategy
Cookie settings&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;28. JWT Flow — Start to End&lt;/h1&gt;&lt;p&gt;Here&#39;s the complete flow you can remember for interviews:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 ┌──────────────┐
                 │     USER     │
                 └──────┬───────┘
                        │
                        │ Login
                        ▼
                 ┌──────────────┐
                 │   FRONTEND   │
                 └──────┬───────┘
                        │
                        │ username/password
                        ▼
                 ┌──────────────┐
                 │  AUTH API    │
                 └──────┬───────┘
                        │
                        │ Validate
                        ▼
                 ┌──────────────┐
                 │   DATABASE   │
                 └──────┬───────┘
                        │
                        │ Valid
                        ▼
                 ┌──────────────┐
                 │  JWT CREATE  │
                 └──────┬───────┘
                        │
                        │
                HEADER.PAYLOAD
                  .SIGNATURE
                        │
                        ▼
                 ┌──────────────┐
                 │   FRONTEND   │
                 └──────┬───────┘
                        │
                        │ Authorization:
                        │ Bearer JWT
                        ▼
                 ┌──────────────┐
                 │   WEB API    │
                 └──────┬───────┘
                        │
                        ▼
                JWT VALIDATION
                        │
             ┌──────────┴──────────┐
             │                     │
          Invalid                 Valid
             │                     │
             ▼                     ▼
            401              Authentication
                                  │
                                  ▼
                            Authorization
                                  │
                    ┌─────────────┴────────────┐
                    │                          │
                 Allowed                    Denied
                    │                          │
                    ▼                          ▼
               Controller                    403
                    │
                    ▼
                 Response&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;29. The most important distinction&lt;/h1&gt;&lt;p&gt;Remember these three concepts:&lt;/p&gt;&lt;h3&gt;Header&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;What algorithm/type is this JWT using?&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Payload&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Who is the user?
What claims/attributes are associated with the token?&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Signature&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Has the token been altered,
and can it be validated using the expected signing key?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And remember:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HTTP Authorization Header
        ↓
Carries JWT

JWT Header
        ↓
Describes JWT

JWT Payload
        ↓
Contains Claims

JWT Signature
        ↓
Protects token integrity/authenticity&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;30. One-line interview answer&lt;/h1&gt;&lt;p&gt;If an interviewer asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;Explain JWT authentication flow.&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;A strong answer is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;When a user logs in, the authentication service validates the credentials and creates a signed JWT containing claims such as user ID, issuer, audience, role and expiration. The client then sends that token with subsequent API requests in the HTTP Authorization header using the Bearer scheme. ASP.NET Core&#39;s JWT authentication middleware extracts and validates the token&#39;s signature, issuer, audience and lifetime and creates the authenticated ClaimsPrincipal. The authorization middleware then evaluates policies or roles, such as &lt;code inline=&quot;&quot;&gt;[Authorize(Roles = &quot;Admin&quot;)]&lt;/code&gt;. If authentication fails, the API returns 401; if authentication succeeds but authorization fails, it returns 403. If both succeed, the request reaches the controller.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;That is the &lt;strong&gt;complete JWT authentication → authorization flow&lt;/strong&gt; from login to API response.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/5298848814330002196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/5298848814330002196' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/5298848814330002196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/5298848814330002196'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/jwt-authentication-authorization.html' title='JWT Authentication &amp; Authorization — Complete Flow'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbOKYlFDvkkB-O__qvWeAzyIWtHDwBK6qwe_GLt0M2MaQl-7ZdJX1g0PQzxrwCCyIeb9TIuHq5UDsUclJNboQJPSw9Nb5qhb9zOVlt45h8sZsrHyKCfss-NNR0Jr_p9IwCxC7Flb5k7R70dlvJNYDf6WIPus1A7Ofk1-35pvfEOYbRgKqQzX5pTSqUYoA/s72-w564-h325-c/JWT.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-3498420700945121447</id><published>2026-08-20T19:58:24.958+05:30</published><updated>2026-08-20T19:58:24.959+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Saga Design Pattern – Complete Guide with E-Commerce Example"/><title type='text'>Saga Design Pattern – Complete Guide with E-Commerce Example</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrEhbRiBkPwiRSIog-nveYZAY7HtySrXfRybeQq-CmXO6fDW0REjzk14XKz6hg19WXR2mJQ_Dal5FDH3jpllnAGe6NjiKFbI4dePYv4P6U9lvU3oiynBMsYAv7qVcjOk3Zu24uNVSbTZt7ZHmBh62TVJRfUMjg-Kw6KvfrL1fC8W4ks0wz1L2PiLOdIUk/s1536/SagaECommerce.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;334&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrEhbRiBkPwiRSIog-nveYZAY7HtySrXfRybeQq-CmXO6fDW0REjzk14XKz6hg19WXR2mJQ_Dal5FDH3jpllnAGe6NjiKFbI4dePYv4P6U9lvU3oiynBMsYAv7qVcjOk3Zu24uNVSbTZt7ZHmBh62TVJRfUMjg-Kw6KvfrL1fC8W4ks0wz1L2PiLOdIUk/w502-h334/SagaECommerce.png&quot; width=&quot;502&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h1&gt;1. What Problem Does Saga Solve?&lt;/h1&gt;&lt;p&gt;Imagine an e-commerce application with these microservices:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    E-Commerce Application
                            |
        +-------------------+-------------------+
        |                   |                   |
   Order Service       Payment Service     Inventory Service
        |                   |                   |
        +-------------------+-------------------+
                            |
                    Shipping Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A customer places an order.&lt;/p&gt;&lt;p&gt;The business process might be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Create Order
    ↓
Reserve Inventory
    ↓
Process Payment
    ↓
Create Shipment
    ↓
Order Completed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The problem is that each operation belongs to a &lt;strong&gt;different database&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service       → OrderDB
Inventory Service   → InventoryDB
Payment Service     → PaymentDB
Shipping Service    → ShippingDB&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We cannot normally use a single SQL transaction such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BEGIN TRANSACTION

OrderDB
InventoryDB
PaymentDB
ShippingDB

COMMIT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;because these are independent microservices.&lt;/p&gt;&lt;p&gt;This is where &lt;strong&gt;Saga Pattern&lt;/strong&gt; comes in.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. What Is Saga Design Pattern?&lt;/h1&gt;&lt;p&gt;A &lt;strong&gt;Saga&lt;/strong&gt; is a sequence of &lt;strong&gt;local transactions&lt;/strong&gt; where each microservice performs its own transaction.&lt;/p&gt;&lt;p&gt;If one transaction fails, previously completed transactions are &lt;strong&gt;compensated&lt;/strong&gt; by executing corresponding compensating transactions.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Transaction 1
     ↓
Transaction 2
     ↓
Transaction 3
     ↓
Transaction 4&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If Transaction 3 fails:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Transaction 1 ✓
Transaction 2 ✓
Transaction 3 ✗

        ↓

Compensation 2
        ↓
Compensation 1&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So instead of a traditional distributed ACID transaction, Saga provides &lt;strong&gt;eventual consistency&lt;/strong&gt; using local transactions + compensation.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. E-Commerce Example&lt;/h1&gt;&lt;p&gt;Suppose customer places an order:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order #1001

Product: Laptop
Quantity: 1
Price: ₹80,000&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The workflow is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer
   |
   ↓
Order Service
   |
   ↓
Inventory Service
   |
   ↓
Payment Service
   |
   ↓
Shipping Service
   |
   ↓
Order Completed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let&#39;s define the transactions.&lt;/p&gt;&lt;h3&gt;T1 – Create Order&lt;/h3&gt;&lt;p&gt;Order Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Status = Pending&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;T2 – Reserve Inventory&lt;/h3&gt;&lt;p&gt;Inventory Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Laptop Stock
100 → 99&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;T3 – Process Payment&lt;/h3&gt;&lt;p&gt;Payment Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;₹80,000 charged&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;T4 – Create Shipment&lt;/h3&gt;&lt;p&gt;Shipping Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Shipment Created&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Finally:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Status = Confirmed&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;4. What Happens If Payment Fails?&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;T1 Create Order        ✓
T2 Reserve Inventory   ✓
T3 Payment             ✗&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We cannot simply rollback T1 and T2 using a normal database rollback because they happened in different databases.&lt;/p&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Payment Failed
      ↓
Release Inventory
      ↓
Cancel Order&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;T1 Create Order ✓
       ↓
T2 Reserve Stock ✓
       ↓
T3 Payment ✗
       ↓
C2 Release Stock ✓
       ↓
C1 Cancel Order ✓&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is the core concept of Saga.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Saga Has Two Main Approaches&lt;/h1&gt;&lt;p&gt;There are two major implementations.&lt;/p&gt;&lt;h2&gt;Approach 1 – Choreography&lt;/h2&gt;&lt;p&gt;Services communicate through events.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
     |
 OrderCreated
     ↓
Inventory Service
     |
InventoryReserved
     ↓
Payment Service
     |
PaymentCompleted
     ↓
Shipping Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There is no central coordinator.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Approach 2 – Orchestration&lt;/h2&gt;&lt;p&gt;A central &lt;strong&gt;Saga Orchestrator&lt;/strong&gt; controls the workflow.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 Saga Orchestrator
                        |
          +-------------+-------------+
          |             |             |
          ↓             ↓             ↓
      Order          Inventory      Payment
      Service         Service       Service
                                      |
                                      ↓
                                  Shipping&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The orchestrator says:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Reserve inventory&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Process payment&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Create shipment&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If something fails:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Release inventory
Cancel order&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For an enterprise e-commerce application, &lt;strong&gt;orchestration is often easier to understand and manage&lt;/strong&gt;, especially when the workflow becomes complex.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. Which One Should We Use?&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Choreography&lt;/th&gt;&lt;th&gt;Orchestration&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Central controller&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Simple workflows&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Complex workflows&lt;/td&gt;&lt;td&gt;Difficult&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Debugging&lt;/td&gt;&lt;td&gt;Difficult&lt;/td&gt;&lt;td&gt;Easier&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Business workflow visibility&lt;/td&gt;&lt;td&gt;Lower&lt;/td&gt;&lt;td&gt;Higher&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Coupling&lt;/td&gt;&lt;td&gt;Event-based&lt;/td&gt;&lt;td&gt;Orchestrator-based&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Failure handling&lt;/td&gt;&lt;td&gt;Distributed&lt;/td&gt;&lt;td&gt;Centralized&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Large enterprise workflows&lt;/td&gt;&lt;td&gt;Can become complicated&lt;/td&gt;&lt;td&gt;Often preferable&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;For the example below, I&#39;ll use &lt;strong&gt;Saga Orchestration&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;7. Overall Architecture&lt;/h1&gt;&lt;p&gt;Let&#39;s design the system.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Client
                           |
                           ↓
                    API Gateway
                           |
                           ↓
                    Order Service
                           |
                           ↓
                  Saga Orchestrator
                           |
          +----------------+----------------+
          |                |                |
          ↓                ↓                ↓
     Inventory          Payment          Shipping
      Service           Service           Service
          |                |                |
      InventoryDB       PaymentDB       ShippingDB&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Communication could use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Service Bus
Kafka
RabbitMQ&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For an Azure-based .NET system, &lt;strong&gt;Azure Service Bus&lt;/strong&gt; is a natural choice.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. Database Design&lt;/h1&gt;&lt;p&gt;An important Saga principle is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Each microservice owns its own database.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Don&#39;t do this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
       |
       ↓
Shared Database
       ↑
       |
Inventory Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
     ↓
OrderDB

Inventory Service
     ↓
InventoryDB

Payment Service
     ↓
PaymentDB

Shipping Service
     ↓
ShippingDB&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;9. Order Model&lt;/h1&gt;&lt;p&gt;Order Service might have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Order
{
    public Guid Id { get; set; }

    public Guid CustomerId { get; set; }

    public decimal TotalAmount { get; set; }

    public OrderStatus Status { get; set; }

    public DateTime CreatedAt { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Status:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public enum OrderStatus
{
    Pending,
    InventoryReserved,
    PaymentProcessing,
    Confirmed,
    Failed,
    Cancelled
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;10. Order Items&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderItem
{
    public Guid Id { get; set; }

    public Guid OrderId { get; set; }

    public Guid ProductId { get; set; }

    public int Quantity { get; set; }

    public decimal Price { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Inventory Model&lt;/h1&gt;&lt;p&gt;Inventory Service owns:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Inventory
{
    public Guid ProductId { get; set; }

    public int AvailableQuantity { get; set; }

    public int ReservedQuantity { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Product       Available     Reserved

Laptop          100            0&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After reservation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Laptop           99            1&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;12. Inventory Reservation Model&lt;/h1&gt;&lt;p&gt;We should maintain a separate reservation record.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class InventoryReservation
{
    public Guid Id { get; set; }

    public Guid OrderId { get; set; }

    public Guid ProductId { get; set; }

    public int Quantity { get; set; }

    public ReservationStatus Status { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Status:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public enum ReservationStatus
{
    Reserved,
    Released
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Why?&lt;/p&gt;&lt;p&gt;Because Saga requires us to know:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;What exactly should I compensate?&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;13. Payment Model&lt;/h1&gt;&lt;p&gt;Payment Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Payment
{
    public Guid Id { get; set; }

    public Guid OrderId { get; set; }

    public decimal Amount { get; set; }

    public PaymentStatus Status { get; set; }

    public string TransactionReference { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Status:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public enum PaymentStatus
{
    Pending,
    Completed,
    Failed,
    Refunded
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;14. Shipment Model&lt;/h1&gt;&lt;p&gt;Shipping Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Shipment
{
    public Guid Id { get; set; }

    public Guid OrderId { get; set; }

    public string Address { get; set; }

    public ShipmentStatus Status { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. Saga State Model&lt;/h1&gt;&lt;p&gt;The orchestrator should maintain Saga state.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderSaga
{
    public Guid SagaId { get; set; }

    public Guid OrderId { get; set; }

    public SagaStatus Status { get; set; }

    public bool OrderCreated { get; set; }

    public bool InventoryReserved { get; set; }

    public bool PaymentCompleted { get; set; }

    public bool ShipmentCreated { get; set; }

    public DateTime CreatedAt { get; set; }

    public DateTime UpdatedAt { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This becomes very useful for:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;retries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;recovery&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;debugging&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;compensation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;16. Complete Saga Flow&lt;/h1&gt;&lt;p&gt;Let&#39;s look at the complete process.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer
   |
   | Place Order
   ↓
Order Service
   |
   | Order Created
   ↓
Saga Orchestrator
   |
   | Reserve Inventory
   ↓
Inventory Service
   |
   | Inventory Reserved
   ↓
Saga Orchestrator
   |
   | Process Payment
   ↓
Payment Service
   |
   | Payment Completed
   ↓
Saga Orchestrator
   |
   | Create Shipment
   ↓
Shipping Service
   |
   | Shipment Created
   ↓
Saga Orchestrator
   |
   ↓
Order Confirmed&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;17. Step 1 – Customer Creates Order&lt;/h1&gt;&lt;p&gt;Client:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Request:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;customerId&quot;: &quot;C001&quot;,
  &quot;items&quot;: [
    {
      &quot;productId&quot;: &quot;P100&quot;,
      &quot;quantity&quot;: 1
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Order Service creates:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderId = 1001
Status = Pending&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Database:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Orders

1001 | C001 | 80000 | Pending&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then publish:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreated&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Event:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public record OrderCreatedEvent(
    Guid OrderId,
    Guid CustomerId,
    decimal Amount);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;18. Step 2 – Saga Starts&lt;/h1&gt;&lt;p&gt;The orchestrator receives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreated&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It creates:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SagaId = S1001
OrderId = 1001
Status = Started&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ReserveInventory&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;19. Step 3 – Inventory Reservation&lt;/h1&gt;&lt;p&gt;Inventory Service receives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;sagaId&quot;: &quot;S1001&quot;,
  &quot;orderId&quot;: &quot;1001&quot;,
  &quot;productId&quot;: &quot;P100&quot;,
  &quot;quantity&quot;: 1
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It executes a &lt;strong&gt;local database transaction&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BEGIN TRANSACTION

Check available stock

Available = Available - 1

Create Reservation

COMMIT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Database becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Available = 99
Reserved = 1&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then publish:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;InventoryReserved&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Step 4 – Payment&lt;/h1&gt;&lt;p&gt;Saga orchestrator receives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;InventoryReserved&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ProcessPayment&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Payment Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BEGIN TRANSACTION

Create Payment
Status = Processing

Call payment provider

Payment successful

Status = Completed

COMMIT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PaymentCompleted&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;21. Step 5 – Shipping&lt;/h1&gt;&lt;p&gt;Saga receives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PaymentCompleted&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CreateShipment&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Shipping Service creates:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ShipmentId = SH1001
OrderId = 1001
Status = Created&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then publishes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ShipmentCreated&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;22. Step 6 – Complete Saga&lt;/h1&gt;&lt;p&gt;Saga Orchestrator receives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ShipmentCreated&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreated       ✓
InventoryReserved  ✓
PaymentCompleted   ✓
ShipmentCreated    ✓&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Saga Status = Completed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And Order Service is instructed:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ConfirmOrder&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Order:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1001 | Confirmed&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;23. What Happens When Payment Fails?&lt;/h1&gt;&lt;p&gt;This is where Saga becomes interesting.&lt;/p&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Created       ✓
Inventory Reserved  ✓
Payment             ✗&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The orchestrator receives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PaymentFailed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It knows:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;InventoryReserved = true
PaymentCompleted = false&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore compensation is required.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;24. Compensation Flow&lt;/h1&gt;&lt;p&gt;The orchestrator sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ReleaseInventory&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Inventory Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BEGIN TRANSACTION

Available = Available + 1

Reservation.Status = Released

COMMIT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Available = 100
Reserved = 0&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then orchestrator sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CancelOrder&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Order Service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order.Status = Cancelled&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Final state:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order       = Cancelled
Inventory   = Released
Payment     = Failed
Saga        = Compensated&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;25. Important Point – Compensation Is NOT Rollback&lt;/h1&gt;&lt;p&gt;This is one of the most important interview concepts.&lt;/p&gt;&lt;p&gt;Traditional transaction:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BEGIN

Operation A
Operation B
Operation C

ROLLBACK&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Saga:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Operation A
Operation B
Operation C → FAILED

Compensation B
Compensation A&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There is no global database rollback.&lt;/p&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A compensating transaction semantically reverses the business effect of a previous transaction.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;26. Example: Payment Succeeds but Shipping Fails&lt;/h1&gt;&lt;p&gt;Consider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order        ✓
Inventory    ✓
Payment      ✓
Shipping     ✗&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we need to compensate.&lt;/p&gt;&lt;p&gt;Possible sequence:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Shipping Failed
       ↓
Refund Payment
       ↓
Release Inventory
       ↓
Cancel Order&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;T1 Create Order       ✓
T2 Reserve Inventory  ✓
T3 Payment            ✓
T4 Shipping           ✗

C3 Refund Payment     ✓
C2 Release Inventory  ✓
C1 Cancel Order       ✓&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Final:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order = Cancelled
Inventory = Released
Payment = Refunded
Shipping = Failed&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;27. What If Compensation Also Fails?&lt;/h1&gt;&lt;p&gt;This is a very important real-world scenario.&lt;/p&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Payment Failed
      ↓
Release Inventory
      ↓
Inventory Service FAILED&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order = Pending
Inventory = Reserved
Payment = Failed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We cannot simply give up.&lt;/p&gt;&lt;p&gt;The Saga must retry the compensation.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ReleaseInventory
      ↓
FAILED
      ↓
Retry
      ↓
FAILED
      ↓
Retry
      ↓
SUCCESS&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore Saga implementations need:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Retry&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dead-letter queue&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Idempotency&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Timeout&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Manual recovery&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;28. Retry Strategy&lt;/h1&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Attempt 1
   ↓
5 seconds
   ↓
Attempt 2
   ↓
30 seconds
   ↓
Attempt 3
   ↓
5 minutes&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is called &lt;strong&gt;exponential backoff&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For Azure Service Bus, failed messages can eventually be moved to a &lt;strong&gt;dead-letter queue&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;29. Idempotency Is Extremely Important&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ReserveInventory&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;message is delivered twice.&lt;/p&gt;&lt;p&gt;Without idempotency:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Message 1 → Reserve 1 item
Message 2 → Reserve another item&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Incorrect:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Stock: 100 → 98&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But we wanted:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Stock: 100 → 99&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore every command should have a unique identifier.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class ProcessedMessage
{
    public Guid MessageId { get; set; }

    public DateTime ProcessedAt { get; set; }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Before processing:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Has MessageId already been processed?&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If yes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Ignore&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Otherwise:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Process
Save MessageId&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;30. Better Idempotency Model&lt;/h1&gt;&lt;p&gt;Instead of only MessageId, use a business operation ID.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SagaId = S1001
OrderId = 1001
Operation = ReserveInventory&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create unique constraint:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;(SagaId, Operation)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then duplicate commands cannot create duplicate reservations.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;31. Transactional Outbox Pattern&lt;/h1&gt;&lt;p&gt;There is another major problem.&lt;/p&gt;&lt;p&gt;Suppose Order Service does:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BEGIN TRANSACTION

Insert Order

COMMIT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Publish OrderCreated&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;What if the application crashes between these operations?&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Database Insert ✓
Publish Event ✗&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the order exists but Saga never receives the event.&lt;/p&gt;&lt;p&gt;This is where &lt;strong&gt;Transactional Outbox Pattern&lt;/strong&gt; is commonly combined with Saga.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;32. Outbox Table&lt;/h1&gt;&lt;p&gt;Order Service database:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Orders
OutboxMessages&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When creating the order:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BEGIN TRANSACTION

INSERT INTO Orders

INSERT INTO OutboxMessages

COMMIT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Both happen in the same local database transaction.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Orders

OrderId = 1001
Status = Pending&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OutboxMessages

MessageId = M1001
Type = OrderCreated
Payload = {...}
Published = false&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A background publisher then reads:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Published = false&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and sends the message.&lt;/p&gt;&lt;p&gt;After successful publishing:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Published = true&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This greatly improves reliability.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;33. Saga + Outbox Architecture&lt;/h1&gt;&lt;p&gt;A robust architecture becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Saga Orchestrator
                                |
                         Message Broker
                                |
          +---------------------+---------------------+
          |                     |                     |
          ↓                     ↓                     ↓
      Order Service        Inventory Service      Payment
          |                     |                     |
       OrderDB              InventoryDB           PaymentDB
          |                     |                     |
       Outbox                 Outbox                Outbox
          |                     |                     |
          +---------------------+---------------------+
                                |
                         Azure Service Bus&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;34. Commands vs Events&lt;/h1&gt;&lt;p&gt;This distinction is important.&lt;/p&gt;&lt;h3&gt;Command&lt;/h3&gt;&lt;p&gt;A command tells another service:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Do something.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CreateOrder
ReserveInventory
ProcessPayment
CreateShipment
RefundPayment
ReleaseInventory
CancelOrder&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Event&lt;/h3&gt;&lt;p&gt;An event says:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Something happened.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreated
InventoryReserved
InventoryReservationFailed
PaymentCompleted
PaymentFailed
ShipmentCreated
ShipmentFailed&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;35. Example Command&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public record ReserveInventoryCommand(
    Guid MessageId,
    Guid SagaId,
    Guid OrderId,
    Guid ProductId,
    int Quantity);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;36. Example Event&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public record InventoryReservedEvent(
    Guid MessageId,
    Guid SagaId,
    Guid OrderId);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Failure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public record InventoryReservationFailedEvent(
    Guid MessageId,
    Guid SagaId,
    Guid OrderId,
    string Reason);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;37. Saga State Machine&lt;/h1&gt;&lt;p&gt;The orchestrator can be modeled as a state machine.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             OrderCreated
                  |
                  ↓
          InventoryPending
                  |
        +---------+---------+
        |                   |
     Success              Failure
        |                   |
        ↓                   ↓
 PaymentPending        CancelOrder
        |
   +----+----+
   |         |
Success     Failure
   |         |
   ↓         ↓
Shipping   ReleaseInventory
Pending       |
   |          ↓
Success    CancelOrder
   |
   ↓
Completed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is a very good way to explain Saga in an interview.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;38. Orchestrator Pseudocode&lt;/h1&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task Handle(OrderCreatedEvent message)
{
    await ReserveInventory(message);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When inventory succeeds:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task Handle(InventoryReservedEvent message)
{
    await ProcessPayment(message);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Payment succeeds:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task Handle(PaymentCompletedEvent message)
{
    await CreateShipment(message);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Shipment succeeds:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task Handle(ShipmentCreatedEvent message)
{
    await ConfirmOrder(message);
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Payment fails:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task Handle(PaymentFailedEvent message)
{
    await ReleaseInventory(message);
    await CancelOrder(message);
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;39. Compensation Table&lt;/h1&gt;&lt;p&gt;A useful way to design a Saga is to create a compensation matrix.&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Forward Transaction&lt;/th&gt;&lt;th&gt;Compensation&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Create Order&lt;/td&gt;&lt;td&gt;Cancel Order&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Reserve Inventory&lt;/td&gt;&lt;td&gt;Release Inventory&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Process Payment&lt;/td&gt;&lt;td&gt;Refund Payment&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Create Shipment&lt;/td&gt;&lt;td&gt;Cancel Shipment&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Apply Coupon&lt;/td&gt;&lt;td&gt;Restore Coupon&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Allocate Loyalty Points&lt;/td&gt;&lt;td&gt;Return Loyalty Points&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;For every business transaction, ask:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If this succeeds and something later fails, how do I undo its business effect?&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;If you cannot answer that, your Saga design isn&#39;t complete.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;40. Data Consistency&lt;/h1&gt;&lt;p&gt;A common question is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;How does Saga maintain data consistency?&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;It does &lt;strong&gt;not&lt;/strong&gt; provide immediate strong consistency across all databases like a single ACID transaction.&lt;/p&gt;&lt;p&gt;Instead it provides:&lt;/p&gt;&lt;h2&gt;Eventual Consistency&lt;/h2&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;p&gt;Initially:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order = Pending
Inventory = Reserved
Payment = Processing&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After processing:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order = Confirmed
Inventory = Reserved
Payment = Completed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Or if failure occurs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order = Cancelled
Inventory = Released
Payment = Failed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The system may temporarily have intermediate states, but eventually it reaches a valid business state.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;41. Important: Don&#39;t Compensate Everything Blindly&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Inventory reserved
Payment completed
Shipping failed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You shouldn&#39;t simply execute compensation commands without knowing the actual state.&lt;/p&gt;&lt;p&gt;Maintain Saga state:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;InventoryReserved = true
PaymentCompleted = true
ShipmentCreated = false&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then compensation is based on completed steps.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;if PaymentCompleted
    RefundPayment()

if InventoryReserved
    ReleaseInventory()

if OrderCreated
    CancelOrder()&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;42. Timeout Handling&lt;/h1&gt;&lt;p&gt;Suppose Payment Service doesn&#39;t respond.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Payment Request
      ↓
Waiting...
      ↓
Waiting...
      ↓
Timeout&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The orchestrator should not wait forever.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Payment timeout = 5 minutes&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Payment Timeout
      ↓
Check payment status
      ↓
If unknown → retry/query provider
      ↓
If definitely failed → compensate&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is especially important with external payment gateways.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;43. Why Payment Status Needs Special Care&lt;/h1&gt;&lt;p&gt;Imagine:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Payment Service → Payment Gateway&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Payment request is sent.&lt;/p&gt;&lt;p&gt;Gateway processes it.&lt;/p&gt;&lt;p&gt;But response is lost.&lt;/p&gt;&lt;p&gt;Your service sees:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Timeout&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You &lt;strong&gt;must not automatically refund or retry blindly&lt;/strong&gt; because the first payment might actually have succeeded.&lt;/p&gt;&lt;p&gt;You may accidentally charge the customer twice.&lt;/p&gt;&lt;p&gt;Instead use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Idempotency Key&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderId = 1001
PaymentAttempt = 1
IdempotencyKey = ORDER-1001-PAYMENT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The payment provider should treat repeated requests with the same key as the same logical operation where its API supports idempotency.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;44. Handling Concurrent Orders&lt;/h1&gt;&lt;p&gt;Suppose only one laptop remains.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Stock = 1&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Two customers simultaneously order.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer A → Reserve
Customer B → Reserve&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Inventory Service must use appropriate concurrency control.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;UPDATE Inventory
SET AvailableQuantity = AvailableQuantity - 1
WHERE ProductId = @ProductId
AND AvailableQuantity &amp;gt;= 1;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then check:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Rows affected = 1&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Reservation succeeds.&lt;/p&gt;&lt;p&gt;If:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Rows affected = 0&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;reservation fails.&lt;/p&gt;&lt;p&gt;This prevents overselling.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;45. Saga Failure Scenarios&lt;/h1&gt;&lt;h3&gt;Scenario 1&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order ✓
Inventory ✓
Payment ✓
Shipping ✓&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Result:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Completed&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Scenario 2&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order ✓
Inventory ✗&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Compensation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Cancel Order&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Scenario 3&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order ✓
Inventory ✓
Payment ✗&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Compensation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Release Inventory
Cancel Order&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Scenario 4&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order ✓
Inventory ✓
Payment ✓
Shipping ✗&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Compensation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Refund Payment
Release Inventory
Cancel Order&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Scenario 5&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Compensation fails&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Solution:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Retry
 ↓
Retry
 ↓
Dead Letter Queue
 ↓
Operational Alert
 ↓
Manual Recovery&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;46. Azure Implementation&lt;/h1&gt;&lt;p&gt;Since you&#39;re working with Azure/.NET, one possible architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core
      |
      ↓
Order Service
      |
      ↓
Azure Service Bus
      |
      ↓
Saga Orchestrator
      |
      +----------------+
      |                |
      ↓                ↓
Inventory          Payment
Service            Service
      |                |
      ↓                ↓
 Azure SQL          Azure SQL&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Shipping Service
       |
       ↓
   Azure SQL&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For monitoring:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application Insights
Azure Monitor&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For secrets:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Key Vault&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;47. Azure Service Bus Structure&lt;/h1&gt;&lt;p&gt;You might design:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Topic: ecommerce-events&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Subscriptions:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;order
inventory
payment
shipping
saga&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Or use separate command queues:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;inventory-commands
payment-commands
shipping-commands
order-commands&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For orchestration, a command queue per service plus an event topic is often a clean conceptual model.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;48. Message Flow&lt;/h1&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
     |
     | OrderCreated
     ↓
Service Bus
     |
     ↓
Saga Orchestrator
     |
     | ReserveInventory
     ↓
Inventory Queue
     |
     ↓
Inventory Service
     |
     | InventoryReserved
     ↓
Service Bus
     |
     ↓
Saga
     |
     | ProcessPayment
     ↓
Payment Queue&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And so on.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;49. Database Transactions Are Still Used&lt;/h1&gt;&lt;p&gt;This is another important point.&lt;/p&gt;&lt;p&gt;Saga does &lt;strong&gt;not&lt;/strong&gt; mean:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Don&#39;t use database transactions.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Each microservice should still use normal local transactions.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Inventory Service

BEGIN TRANSACTION

UPDATE Inventory

INSERT Reservation

INSERT OutboxMessage

COMMIT&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is a local ACID transaction.&lt;/p&gt;&lt;p&gt;Saga coordinates these local transactions.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;50. The Golden Rule&lt;/h1&gt;&lt;p&gt;Think about Saga like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Saga
 =
Multiple Local Transactions
 +
Messages
 +
State Machine
 +
Compensating Transactions
 +
Retry
 +
Idempotency
 +
Timeout Handling
 +
Observability&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That is a much more accurate real-world definition than simply saying:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Saga is rollback for microservices.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;It is &lt;strong&gt;not&lt;/strong&gt; a distributed rollback mechanism.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;51. Complete E-Commerce Flow&lt;/h1&gt;&lt;p&gt;Here&#39;s the complete picture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         CUSTOMER
                            |
                            ↓
                       API Gateway
                            |
                            ↓
                     ORDER SERVICE
                            |
                       Create Order
                            |
                            ↓
                      OrderCreated
                            |
                            ↓
                   SAGA ORCHESTRATOR
                            |
                    Reserve Inventory
                            |
                            ↓
                   INVENTORY SERVICE
                            |
                   Inventory Reserved
                            |
                            ↓
                   SAGA ORCHESTRATOR
                            |
                     Process Payment
                            |
                            ↓
                    PAYMENT SERVICE
                            |
                     Payment Success
                            |
                            ↓
                   SAGA ORCHESTRATOR
                            |
                     Create Shipment
                            |
                            ↓
                   SHIPPING SERVICE
                            |
                    Shipment Created
                            |
                            ↓
                   SAGA ORCHESTRATOR
                            |
                            ↓
                     Confirm Order&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Failure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Payment Failed
      |
      ↓
Saga Orchestrator
      |
      +------→ Release Inventory
      |
      +------→ Cancel Order
      |
      ↓
Saga Compensated&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;52. Production-Grade Saga Checklist&lt;/h1&gt;&lt;p&gt;When implementing Saga in a real application, consider all of these:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Saga ID&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Correlation ID&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Message ID&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Idempotency&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Saga state persistence&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Local database transactions&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Transactional Outbox&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reliable messaging&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Retries&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Exponential backoff&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Timeouts&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dead-letter queues&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Compensating transactions&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Concurrency control&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Optimistic/pessimistic locking where appropriate&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Observability&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Distributed tracing&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Audit logging&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manual recovery&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Poison message handling&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;53. Saga vs Two-Phase Commit&lt;/h1&gt;&lt;p&gt;A common interview question is:&lt;/p&gt;&lt;h3&gt;2PC&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Coordinator
    |
    +--- DB1
    +--- DB2
    +--- DB3

Prepare
Prepare
Prepare

Commit
Commit
Commit&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It attempts to provide distributed transactional atomicity, but can introduce blocking, coordination overhead, and operational complexity.&lt;/p&gt;&lt;p&gt;Saga:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Local Transaction
      ↓
Message
      ↓
Local Transaction
      ↓
Message&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Failure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Compensating Transaction&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Saga is generally better suited to independently deployable microservices where business operations can be compensated.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;54. Interview Answer&lt;/h1&gt;&lt;p&gt;If an interviewer asks:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&quot;Explain Saga Design Pattern with an e-commerce example.&quot;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;A strong answer would be:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Saga is a distributed transaction pattern used in microservices where a business transaction is divided into a sequence of local transactions. Each service commits its own transaction independently. If a later transaction fails, the Saga executes compensating transactions for the previously completed operations.&lt;/p&gt;&lt;p&gt;For example, in an e-commerce system, placing an order may involve creating the order, reserving inventory, processing payment, and creating a shipment. If payment fails after inventory has been reserved, the Saga doesn&#39;t perform a database rollback across services. Instead, it executes a compensating transaction to release the inventory and then cancels the order.&lt;/p&gt;&lt;p&gt;Saga can be implemented using choreography, where services communicate through events, or orchestration, where a central Saga orchestrator manages the workflow. In a production system, I would also use an outbox pattern, idempotent message processing, retries, timeouts, dead-letter queues, correlation IDs, and persistent Saga state to achieve reliable eventual consistency.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;55. Recommended .NET Architecture&lt;/h1&gt;&lt;p&gt;For a production .NET implementation, I would structure it approximately like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;src
│
├── OrderService
│   ├── Controllers
│   ├── Domain
│   ├── Application
│   ├── Infrastructure
│   └── Messaging
│
├── InventoryService
│   ├── Domain
│   ├── Application
│   ├── Infrastructure
│   └── Messaging
│
├── PaymentService
│   ├── Domain
│   ├── Application
│   ├── Infrastructure
│   └── Messaging
│
├── ShippingService
│   ├── Domain
│   ├── Application
│   ├── Infrastructure
│   └── Messaging
│
└── OrderSaga
    ├── StateMachine
    ├── Commands
    ├── Events
    ├── Consumers
    └── Persistence&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A particularly robust combination is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Microservices
     +
Saga Orchestration
     +
Azure Service Bus
     +
Transactional Outbox
     +
Idempotent Consumers
     +
Retry/Timeout
     +
Dead Letter Queue
     +
Azure SQL
     +
Application Insights&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The key idea to remember is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Saga does not make multiple databases behave like one database. It coordinates independent local transactions and uses compensating actions to bring the overall business process to a consistent state.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/3498420700945121447/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/3498420700945121447' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/3498420700945121447'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/3498420700945121447'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/saga-design-pattern-complete-guide-with.html' title='Saga Design Pattern – Complete Guide with E-Commerce Example'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrEhbRiBkPwiRSIog-nveYZAY7HtySrXfRybeQq-CmXO6fDW0REjzk14XKz6hg19WXR2mJQ_Dal5FDH3jpllnAGe6NjiKFbI4dePYv4P6U9lvU3oiynBMsYAv7qVcjOk3Zu24uNVSbTZt7ZHmBh62TVJRfUMjg-Kw6KvfrL1fC8W4ks0wz1L2PiLOdIUk/s72-w502-h334-c/SagaECommerce.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-3672127788042161530</id><published>2026-08-20T12:26:51.854+05:30</published><updated>2026-08-20T12:26:51.854+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure AI Search"/><title type='text'>Azure AI Search: Complete Guide with a Real-Time .NET Example</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvd47uIaAGxMX6neUu364E3EDz30iD5IlEjBPN8G79CYytmj7l8xccuU2GNGlWvBjI2LDAILASamPauPJ-pHFRWe65r2_kPR9mxqCKC2Dnp0K8k1e6fOZbe6TWDLmwKV-rB1biG8QkEhW3hv0i-ix6hAoOR76Ct2k8TAf1ADeLREmtaXjv2_xj8QwjFNQ/s1536/AzureSearch.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;319&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvd47uIaAGxMX6neUu364E3EDz30iD5IlEjBPN8G79CYytmj7l8xccuU2GNGlWvBjI2LDAILASamPauPJ-pHFRWe65r2_kPR9mxqCKC2Dnp0K8k1e6fOZbe6TWDLmwKV-rB1biG8QkEhW3hv0i-ix6hAoOR76Ct2k8TAf1ADeLREmtaXjv2_xj8QwjFNQ/w563-h319/AzureSearch.png&quot; width=&quot;563&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Introduction&lt;/h2&gt;&lt;p&gt;Modern applications generate and consume enormous amounts of information—PDFs, Word documents, web pages, product catalogs, support tickets, database records, manuals, and knowledge-base articles.&lt;/p&gt;&lt;p&gt;Traditional database queries work well when users know the exact keywords they are looking for. But modern applications increasingly need to understand &lt;strong&gt;meaning and intent&lt;/strong&gt;, not just exact words.&lt;/p&gt;&lt;p&gt;This is where &lt;strong&gt;Azure AI Search&lt;/strong&gt; becomes extremely useful.&lt;/p&gt;&lt;p&gt;Azure AI Search is a managed search and retrieval service from Microsoft Azure that supports traditional full-text search, vector search, hybrid search, semantic ranking, and generative-AI/RAG scenarios. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/?utm_source=chatgpt.com&quot; title=&quot;Azure AI Search documentation - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;A typical modern architecture looks like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                User
                  |
                  v
        Angular / Web / Mobile
                  |
                  v
          ASP.NET Core API
                  |
        +---------+---------+
        |                   |
        v                   v
 Azure AI Search       Azure OpenAI
        |                   |
        |&amp;lt;--- Context ------|
        |
        v
   Search Results
        |
        +--------&amp;gt; LLM
                    |
                    v
              Final Answer&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This article explains Azure AI Search from the fundamentals through an end-to-end &lt;strong&gt;ASP.NET Core + Azure AI Search + Azure OpenAI RAG application&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. What Is Azure AI Search?&lt;/h1&gt;&lt;p&gt;Azure AI Search is Microsoft&#39;s cloud-based search-as-a-service platform.&lt;/p&gt;&lt;p&gt;It allows applications to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Store searchable documents&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Search text&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Search using keywords&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Search by semantic meaning&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Perform vector similarity searches&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Perform hybrid searches&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Apply filters&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sort and facet results&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Re-rank search results using semantic ranking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Retrieve grounding information for RAG applications&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Microsoft documentation currently describes Azure AI Search as supporting &lt;strong&gt;text, vector, and multimodal content&lt;/strong&gt; for traditional and generative search scenarios. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/?utm_source=chatgpt.com&quot; title=&quot;Azure AI Search documentation - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;Think of it as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Traditional Database
        |
        | Exact data retrieval
        v
     SQL Query

Azure AI Search
        |
        | Intelligent information retrieval
        v
 Keyword + Semantic + Vector + Hybrid Search&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;2. Why Do We Need Azure AI Search?&lt;/h1&gt;&lt;p&gt;Suppose a company has:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;100,000 PDF documents
50,000 Word documents
1 million support tickets
500,000 product descriptions&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A user asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;How can I reset my corporate VPN password?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;A traditional SQL query might search for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WHERE Description LIKE &#39;%VPN%&#39;
AND Description LIKE &#39;%password%&#39;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But the user could ask:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;I forgot the credentials needed to connect remotely.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The words are completely different.&lt;/p&gt;&lt;p&gt;A semantic/vector search engine can recognize that:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;forgot credentials&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;is related to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;reset VPN password&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is one of the major advantages of vector and semantic search.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Azure AI Search vs SQL Server&lt;/h1&gt;&lt;p&gt;Azure AI Search does &lt;strong&gt;not replace SQL Server&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;They solve different problems.&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;SQL Server&lt;/th&gt;&lt;th&gt;Azure AI Search&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Transactional data&lt;/td&gt;&lt;td&gt;Search/retrieval&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;INSERT/UPDATE/DELETE&lt;/td&gt;&lt;td&gt;Indexing/search&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Relationships&lt;/td&gt;&lt;td&gt;Search indexes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Joins&lt;/td&gt;&lt;td&gt;Search queries&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ACID transactions&lt;/td&gt;&lt;td&gt;Relevance ranking&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Structured data&lt;/td&gt;&lt;td&gt;Text/vector content&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Business transactions&lt;/td&gt;&lt;td&gt;Information retrieval&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;A common architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL Server
   |
   | Product / Customer / Order data
   |
   v
ASP.NET Core
   |
   +------&amp;gt; SQL Server
   |
   +------&amp;gt; Azure AI Search&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;4. Important Azure AI Search Concepts&lt;/h1&gt;&lt;p&gt;Before implementing Azure AI Search, understand these concepts.&lt;/p&gt;&lt;h2&gt;4.1 Search Service&lt;/h2&gt;&lt;p&gt;The Azure AI Search service is the Azure resource that provides the search engine.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;my-company-search.search.windows.net&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Applications communicate with this service through:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;REST API&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure SDK&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;.NET SDK&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Python SDK&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JavaScript/TypeScript SDK&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Java SDK&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Microsoft provides official SDKs and samples for these languages. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/?utm_source=chatgpt.com&quot; title=&quot;Azure AI Search documentation - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Search Index&lt;/h1&gt;&lt;p&gt;A search index is similar conceptually to a database table, but it is designed specifically for search.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ProductIndex&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;could contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ProductId
ProductName
Description
Category
Price
Availability
DescriptionVector&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;ProductId&quot;: &quot;P1001&quot;,
  &quot;ProductName&quot;: &quot;Laptop&quot;,
  &quot;Description&quot;: &quot;Business laptop with 16GB RAM&quot;,
  &quot;Category&quot;: &quot;Computer&quot;,
  &quot;Price&quot;: 75000
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;6. Search Fields&lt;/h1&gt;&lt;p&gt;Each index contains fields.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ProductId
ProductName
Description
Category
Price
DescriptionVector&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Different fields can have different capabilities.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ProductName
    searchable

Description
    searchable

Category
    filterable

Price
    filterable
    sortable

DescriptionVector
    vector searchable&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. Documents&lt;/h1&gt;&lt;p&gt;A document represents one searchable item inside an index.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &quot;id&quot;: &quot;101&quot;,
    &quot;title&quot;: &quot;Azure AI Search&quot;,
    &quot;content&quot;: &quot;Azure AI Search provides intelligent search capabilities.&quot;,
    &quot;category&quot;: &quot;Azure&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Another document might represent:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PDF chunk
Product
Customer FAQ
Support ticket
Knowledge-base article
Web page&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;8. Full-Text Search&lt;/h1&gt;&lt;p&gt;Traditional full-text search searches words contained in documents.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Search:
Azure Service Bus&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Azure AI Search looks for matching terms in searchable fields.&lt;/p&gt;&lt;p&gt;This approach is particularly useful for:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Product codes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Names&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Exact terminology&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;IDs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dates&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Specialized technical terms&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Microsoft notes that keyword search can be particularly useful where exact matching matters. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/hybrid-search-overview?utm_source=chatgpt.com&quot; title=&quot;Hybrid Search Overview - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. Vector Search&lt;/h1&gt;&lt;p&gt;Vector search is one of the most important capabilities for modern AI applications.&lt;/p&gt;&lt;p&gt;An embedding model converts text into a numerical representation called a &lt;strong&gt;vector&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;How do I reset my password?&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;might become conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[0.021, -0.192, 0.442, ...]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The vector represents semantic information rather than simply storing individual keywords.&lt;/p&gt;&lt;p&gt;The user&#39;s question is also converted into a vector.&lt;/p&gt;&lt;p&gt;Then Azure AI Search finds documents whose vectors are mathematically similar.&lt;/p&gt;&lt;p&gt;Microsoft describes vector search as useful for conceptual similarity and multilingual or multimodal scenarios. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/vector-search-overview?utm_source=chatgpt.com&quot; title=&quot;Vector Search Overview - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. Why Vector Search Is Powerful&lt;/h1&gt;&lt;p&gt;Consider these two sentences:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Document:
&quot;Employees can change their credentials from the security portal.&quot;

User:
&quot;Where can I update my password?&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There may be no exact keyword match for every word.&lt;/p&gt;&lt;p&gt;But semantically:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;change credentials
        ≈
update password&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Vector search can identify that relationship.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;11. What Is an Embedding?&lt;/h1&gt;&lt;p&gt;An embedding is a numerical representation of content.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Text
 |
 v
Embedding Model
 |
 v
Vector&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;Azure Functions&quot;
        |
        v
[0.12, -0.44, 0.72, ...]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The actual vector has many dimensions.&lt;/p&gt;&lt;p&gt;The application stores this vector in a vector field in Azure AI Search.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Hybrid Search&lt;/h1&gt;&lt;p&gt;Hybrid search combines:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Keyword Search
       +
Vector Search&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;in a single request.&lt;/p&gt;&lt;p&gt;Azure AI Search executes the text and vector searches and merges their results using &lt;strong&gt;Reciprocal Rank Fusion (RRF)&lt;/strong&gt;. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/hybrid-search-overview?utm_source=chatgpt.com&quot; title=&quot;Hybrid Search Overview - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                User Query
                    |
          +---------+---------+
          |                   |
          v                   v
     Keyword Search      Vector Search
          |                   |
          v                   v
      Results A           Results B
          |                   |
          +---------+---------+
                    |
                    v
                   RRF
                    |
                    v
             Combined Results&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is often a strong choice for enterprise search.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. Semantic Ranking&lt;/h1&gt;&lt;p&gt;Semantic ranking provides another relevance layer.&lt;/p&gt;&lt;p&gt;The initial results can be reranked using Microsoft&#39;s language-understanding models.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Query:
&quot;How can I work remotely?&quot;

Result A:
&quot;Remote working policy...&quot;

Result B:
&quot;Office parking policy...&quot;

Result C:
&quot;VPN remote access instructions...&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Semantic ranking can identify which results are most relevant to the meaning of the query.&lt;/p&gt;&lt;p&gt;Microsoft describes semantic ranker as a secondary ranking stage over an initial BM25 or RRF result set. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/semantic-search-overview?utm_source=chatgpt.com&quot; title=&quot;Semantic Ranking Overview - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. Search Architecture&lt;/h1&gt;&lt;p&gt;A modern Azure AI Search application can look like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                  Documents
                     |
       +-------------+-------------+
       |             |             |
       v             v             v
     PDF          Database       Website
       |             |             |
       +-------------+-------------+
                     |
                     v
              Data Processing
                     |
                     v
              Chunking / Cleaning
                     |
                     v
               Embeddings
                     |
                     v
             Azure AI Search
                     |
              Search Index
                     |
                     v
                 User Query
                     |
          +----------+----------+
          |                     |
          v                     v
       Keyword               Vector
       Search                Search
          |                     |
          +----------+----------+
                     |
                     v
                    RRF
                     |
                     v
              Semantic Ranker
                     |
                     v
                Top Results
                     |
                     v
                Azure OpenAI
                     |
                     v
               Final Response&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. What Is RAG?&lt;/h1&gt;&lt;p&gt;RAG means:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Retrieval-Augmented Generation&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Instead of asking an LLM to answer only from its trained knowledge, we first retrieve relevant information from our own data.&lt;/p&gt;&lt;p&gt;The process is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User Question
      |
      v
Azure AI Search
      |
      v
Relevant Documents
      |
      v
Prompt + Retrieved Context
      |
      v
Azure OpenAI
      |
      v
Final Answer&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft describes RAG as a pattern that grounds LLM responses in proprietary content. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/retrieval-augmented-generation-overview?utm_source=chatgpt.com&quot; title=&quot;RAG and Generative AI - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. Real-Time Example: Employee Knowledge Assistant&lt;/h1&gt;&lt;p&gt;Let&#39;s build a realistic enterprise application.&lt;/p&gt;&lt;p&gt;Imagine a company has:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HR Policies
IT Policies
Leave Policies
Travel Policies
Insurance Documents
Employee Handbook
Security Guidelines&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Employees can ask:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;How many days of annual leave can I take?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;or:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;What is the process for claiming travel expenses?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;or:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;How do I reset my VPN password?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Instead of manually searching hundreds of documents, the application retrieves the relevant information automatically.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. Complete Architecture&lt;/h1&gt;&lt;p&gt;Our solution will use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
   v
ASP.NET Core Web API
   |
   +--------------------+
   |                    |
   v                    v
Azure AI Search      Azure OpenAI
   |
   v
Search Index&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Documents:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Blob Storage
       |
       v
Document Processing
       |
       v
Chunking
       |
       v
Embeddings
       |
       v
Azure AI Search&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;18. Step 1 – Create Azure AI Search&lt;/h1&gt;&lt;p&gt;In Azure Portal:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Portal
     |
     v
Create a resource
     |
     v
Search service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Subscription
Resource Group
Service Name
Region
Pricing Tier&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After deployment, you will have an Azure AI Search service.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;19. Step 2 – Create Azure OpenAI&lt;/h1&gt;&lt;p&gt;Create an Azure OpenAI resource and deploy appropriate models for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Chat / generation
+
Embeddings&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The embedding model is used to convert content and queries into vectors.&lt;/p&gt;&lt;p&gt;The chat model generates the final response.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;20. Step 3 – Store Documents&lt;/h1&gt;&lt;p&gt;Suppose we have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;EmployeeHandbook.pdf
LeavePolicy.pdf
TravelPolicy.pdf
SecurityPolicy.pdf&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A common architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Blob Storage
        |
        v
Document Processing
        |
        v
Azure AI Search&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft&#39;s .NET RAG tutorial similarly demonstrates a solution using Azure OpenAI, Azure AI Search, storage, and an application layer. (&lt;a href=&quot;https://learn.microsoft.com/th-th/azure/app-service/tutorial-ai-openai-search-dotnet?utm_source=chatgpt.com&quot; title=&quot;RAG application with Azure OpenAI and Azure AI Search (.NET) - Azure App Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;21. Step 4 – Chunk Documents&lt;/h1&gt;&lt;p&gt;Large documents should normally be divided into smaller pieces.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LeavePolicy.pdf

        |
        v

Chunk 1
Introduction

Chunk 2
Annual Leave

Chunk 3
Sick Leave

Chunk 4
Approval Process

Chunk 5
Carry Forward Policy&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Why?&lt;/p&gt;&lt;p&gt;Because sending an entire 100-page document to an LLM for every question is inefficient.&lt;/p&gt;&lt;p&gt;Instead, retrieve only the relevant chunks.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Example Search Document&lt;/h1&gt;&lt;p&gt;Our index could contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;id&quot;: &quot;leave-001&quot;,
  &quot;title&quot;: &quot;Annual Leave Policy&quot;,
  &quot;content&quot;: &quot;Employees are entitled to annual leave according to company policy...&quot;,
  &quot;category&quot;: &quot;HR&quot;,
  &quot;documentName&quot;: &quot;LeavePolicy.pdf&quot;,
  &quot;contentVector&quot;: [ ... ]
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important fields are:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;id
title
content
category
documentName
contentVector&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;23. Create a .NET Project&lt;/h1&gt;&lt;p&gt;Create an ASP.NET Core Web API:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet new webapi -n EnterpriseSearch.Api&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Install the Azure AI Search SDK:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Azure.Search.Documents&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The official .NET SDK package is &lt;code inline=&quot;&quot;&gt;Azure.Search.Documents&lt;/code&gt;. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/hybrid-search-how-to-query?view=form-recog-3.0.0&amp;amp;utm_source=chatgpt.com&quot; title=&quot;Create a Hybrid Query - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;24. Configuration&lt;/h1&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;appsettings.json&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;AzureSearch&quot;: {
    &quot;Endpoint&quot;: &quot;https://YOUR-SEARCH-SERVICE.search.windows.net&quot;,
    &quot;IndexName&quot;: &quot;employee-knowledge&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For production, avoid storing secrets directly in configuration files.&lt;/p&gt;&lt;p&gt;Prefer:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Managed Identity
+
Microsoft Entra ID
+
Azure Key Vault&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft&#39;s current .NET RAG tutorial demonstrates managed identities for passwordless service-to-service authentication. (&lt;a href=&quot;https://learn.microsoft.com/th-th/azure/app-service/tutorial-ai-openai-search-dotnet?utm_source=chatgpt.com&quot; title=&quot;RAG application with Azure OpenAI and Azure AI Search (.NET) - Azure App Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;25. Create Search Service Class&lt;/h1&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Models;

public class SearchService
{
    private readonly SearchClient _searchClient;

    public SearchService(
        IConfiguration configuration)
    {
        var endpoint =
            configuration[&quot;AzureSearch:Endpoint&quot;];

        var indexName =
            configuration[&quot;AzureSearch:IndexName&quot;];

        var credential =
            new Azure.Identity.DefaultAzureCredential();

        _searchClient =
            new SearchClient(
                new Uri(endpoint!),
                indexName,
                credential);
    }

    public async Task&amp;lt;List&amp;lt;SearchDocument&amp;gt;&amp;gt; SearchAsync(
        string query)
    {
        var options = new SearchOptions
        {
            Size = 5
        };

        options.Select.Add(&quot;id&quot;);
        options.Select.Add(&quot;title&quot;);
        options.Select.Add(&quot;content&quot;);
        options.Select.Add(&quot;documentName&quot;);

        var response =
            await _searchClient.SearchAsync&amp;lt;SearchDocument&amp;gt;(
                query,
                options);

        var results = new List&amp;lt;SearchDocument&amp;gt;();

        await foreach (var result in response.Value.GetResultsAsync())
        {
            results.Add(result.Document);
        }

        return results;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;26. Create the API Controller&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[ApiController]
[Route(&quot;api/search&quot;)]
public class SearchController : ControllerBase
{
    private readonly SearchService _searchService;

    public SearchController(SearchService searchService)
    {
        _searchService = searchService;
    }

    [HttpGet]
    public async Task&amp;lt;IActionResult&amp;gt; Search(
        string query)
    {
        var results =
            await _searchService.SearchAsync(query);

        return Ok(results);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the API can be called like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;GET /api/search?query=annual leave&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;27. Example Response&lt;/h1&gt;&lt;p&gt;The API could return:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;[
  {
    &quot;title&quot;: &quot;Annual Leave Policy&quot;,
    &quot;content&quot;: &quot;Employees are entitled to annual leave...&quot;,
    &quot;documentName&quot;: &quot;LeavePolicy.pdf&quot;
  },
  {
    &quot;title&quot;: &quot;Employee Handbook&quot;,
    &quot;content&quot;: &quot;Leave requests must be submitted...&quot;,
    &quot;documentName&quot;: &quot;EmployeeHandbook.pdf&quot;
  }
]&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;28. Adding Vector Search&lt;/h1&gt;&lt;p&gt;For vector search, the index contains a vector field.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;content
contentVector&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The process is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User Query
     |
     v
Embedding Model
     |
     v
Query Vector
     |
     v
Azure AI Search
     |
     v
Similar Document Vectors&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;29. Hybrid Search Query&lt;/h1&gt;&lt;p&gt;A hybrid query contains both:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;search
+
vectorQueries&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;search&quot;: &quot;How do I apply for annual leave?&quot;,
  &quot;vectorQueries&quot;: [
    {
      &quot;kind&quot;: &quot;vector&quot;,
      &quot;vector&quot;: [ ... ],
      &quot;fields&quot;: &quot;contentVector&quot;,
      &quot;k&quot;: 5
    }
  ],
  &quot;top&quot;: 5
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Azure AI Search executes both searches and combines their results using RRF. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/hybrid-search-overview?utm_source=chatgpt.com&quot; title=&quot;Hybrid Search Overview - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;30. Semantic Hybrid Search&lt;/h1&gt;&lt;p&gt;For high-quality retrieval, you can combine:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Keyword
+
Vector
+
Semantic Ranking&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User Query
    |
    +----&amp;gt; Keyword Search
    |
    +----&amp;gt; Vector Search
              |
              v
             RRF
              |
              v
       Semantic Ranker
              |
              v
       Best Documents&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is an especially useful architecture for RAG applications. Microsoft documentation highlights hybrid search with semantic ranking as a strong relevance strategy. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/search-relevance-overview?utm_source=chatgpt.com&quot; title=&quot;Relevance and Ranking Overview - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;31. Complete RAG Flow&lt;/h1&gt;&lt;p&gt;Let&#39;s walk through an actual question.&lt;/p&gt;&lt;p&gt;User asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;How many days of annual leave can I take?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Step 1&lt;/h3&gt;&lt;p&gt;Angular sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/chat&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Request:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;question&quot;: &quot;How many days of annual leave can I take?&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 2&lt;/h3&gt;&lt;p&gt;ASP.NET Core receives the question.&lt;/p&gt;&lt;h3&gt;Step 3&lt;/h3&gt;&lt;p&gt;The application sends the question to the retrieval layer.&lt;/p&gt;&lt;h3&gt;Step 4&lt;/h3&gt;&lt;p&gt;The query is converted into a vector.&lt;/p&gt;&lt;h3&gt;Step 5&lt;/h3&gt;&lt;p&gt;Azure AI Search performs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Keyword Search
+
Vector Search&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 6&lt;/h3&gt;&lt;p&gt;Results are merged using RRF.&lt;/p&gt;&lt;h3&gt;Step 7&lt;/h3&gt;&lt;p&gt;Semantic ranking can further improve ordering.&lt;/p&gt;&lt;h3&gt;Step 8&lt;/h3&gt;&lt;p&gt;Top relevant chunks are returned.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Annual Leave Policy
-------------------

Employees are entitled to 20 days
of annual leave per calendar year.&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 9&lt;/h3&gt;&lt;p&gt;The application builds a prompt:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Answer the user&#39;s question using
only the following company policy.

Context:
Employees are entitled to 20 days
of annual leave per calendar year.

Question:
How many days of annual leave can I take?&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 10&lt;/h3&gt;&lt;p&gt;Azure OpenAI generates:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;According to the Annual Leave Policy,
employees are entitled to 20 days of
annual leave per calendar year.&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;32. Why RAG Is Better Than Sending Everything to the LLM&lt;/h1&gt;&lt;p&gt;Without RAG:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User
 |
 v
LLM
 |
 v
Possible hallucination&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With RAG:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User
 |
 v
Azure AI Search
 |
 v
Company Documents
 |
 v
Relevant Context
 |
 v
LLM
 |
 v
Grounded Answer&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;RAG doesn&#39;t automatically guarantee that every answer is correct, but it gives the model relevant source material from your organization&#39;s data.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;33. Adding Citations&lt;/h1&gt;&lt;p&gt;A production enterprise application should ideally tell users where an answer came from.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;According to the Annual Leave Policy,
employees are entitled to 20 days of annual leave.

Source:
LeavePolicy.pdf
Page 4&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Your index can store metadata such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;documentName
pageNumber
chunkId
sourceUrl
department&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then your API can return:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;answer&quot;: &quot;Employees are entitled to 20 days of annual leave.&quot;,
  &quot;sources&quot;: [
    {
      &quot;document&quot;: &quot;LeavePolicy.pdf&quot;,
      &quot;page&quot;: 4
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This greatly improves trust and auditability.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;34. Security in Azure AI Search&lt;/h1&gt;&lt;p&gt;Enterprise search must consider authorization.&lt;/p&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HR Documents
Finance Documents
Engineering Documents&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;An Engineering employee should not automatically retrieve confidential HR documents.&lt;/p&gt;&lt;p&gt;A production architecture should therefore consider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User Identity
     |
     v
Authorization
     |
     v
Security Filter
     |
     v
Azure AI Search&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Metadata can include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;department
userId
role
securityGroup
accessLevel&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then search filters can restrict what users are allowed to retrieve.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;35. Azure AI Search and Managed Identity&lt;/h1&gt;&lt;p&gt;For production applications, avoid this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;API Key stored in appsettings.json&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Prefer:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core
     |
     v
Managed Identity
     |
     v
Microsoft Entra ID
     |
     v
Azure AI Search&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This eliminates the need to distribute long-lived secrets between Azure services.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. Common Real-Time Use Cases&lt;/h1&gt;&lt;p&gt;Azure AI Search can be used for:&lt;/p&gt;&lt;h3&gt;Enterprise Knowledge Search&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Company Documents
       |
       v
AI Search
       |
       v
Employee Assistant&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;E-Commerce&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Products
   |
   v
AI Search
   |
   +--&amp;gt; Keyword
   +--&amp;gt; Semantic
   +--&amp;gt; Vector&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Find lightweight laptops for programming.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Customer Support&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Support Tickets
Knowledge Base
Product Manuals
       |
       v
Azure AI Search
       |
       v
Support Copilot&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Legal Document Search&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Contracts
Policies
Agreements
       |
       v
Search + RAG&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Healthcare Knowledge Systems&lt;/h3&gt;&lt;p&gt;For appropriate authorized environments:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Clinical documents
Research documents
Policies
       |
       v
Search&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Sensitive applications require strong access control, privacy, compliance, and human oversight.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;37. Azure AI Search in Microservices Architecture&lt;/h1&gt;&lt;p&gt;For a microservices application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    API Gateway
                         |
          +--------------+--------------+
          |              |              |
          v              v              v
     Product Service  Order Service  Customer Service
          |              |              |
          +--------------+--------------+
                         |
                         v
                  Search Service
                         |
                         v
                 Azure AI Search&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I recommend keeping search concerns separate from transactional services.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Product Service
      |
      v
Product Database

Search Indexing Service
      |
      v
Azure AI Search&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When product data changes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Product Updated
      |
      v
Event / Message
      |
      v
Search Indexing Service
      |
      v
Azure AI Search&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This avoids tightly coupling every service to the search engine.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;38. Event-Driven Indexing&lt;/h1&gt;&lt;p&gt;For large systems:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Product Service
      |
      v
Azure Service Bus
      |
      v
Search Index Worker
      |
      v
Azure AI Search&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ProductUpdatedEvent&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;could contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;productId&quot;: &quot;P1001&quot;,
  &quot;operation&quot;: &quot;Updated&quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The indexing worker then updates the corresponding Azure AI Search document.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;39. Azure AI Search vs Elasticsearch&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Azure AI Search&lt;/th&gt;&lt;th&gt;Elasticsearch&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Azure integration&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Microsoft ecosystem&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Vector search&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Hybrid search&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Semantic ranking&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Different approach&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure OpenAI integration&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Possible&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Managed Azure service&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Depends on offering&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;.NET integration&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;If your application is already heavily invested in Azure, Azure AI Search is often a natural choice.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;40. Azure AI Search vs Database LIKE&lt;/h1&gt;&lt;p&gt;Bad approach for large-scale AI search:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT *
FROM Documents
WHERE Content LIKE &#39;%password%&#39;;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Better:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure AI Search
      |
      +-- Full Text
      +-- Vector
      +-- Hybrid
      +-- Semantic Ranking&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;41. Common Mistakes&lt;/h1&gt;&lt;h2&gt;Mistake 1 – Indexing entire documents as one chunk&lt;/h2&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Document
   |
   v
Meaningful chunks&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Mistake 2 – Using only vector search&lt;/h2&gt;&lt;p&gt;Vector search is powerful, but exact keywords can be important.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;INC-45872&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A keyword search may be more useful than semantic similarity.&lt;/p&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Keyword + Vector&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;is often preferable.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Mistake 3 – Sending too many search results to the LLM&lt;/h2&gt;&lt;p&gt;Don&#39;t retrieve hundreds of chunks.&lt;/p&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Retrieve
   |
   v
Rank
   |
   v
Top relevant chunks
   |
   v
LLM&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Mistake 4 – Ignoring security&lt;/h2&gt;&lt;p&gt;Never assume:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;If the document is indexed,
every user can see it.&quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Security trimming and authorization must be designed into the solution.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Mistake 5 – Storing secrets in source code&lt;/h2&gt;&lt;p&gt;Avoid:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;const string apiKey = &quot;xxxxxxxx&quot;;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Managed Identity
Azure Key Vault
Microsoft Entra ID&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;42. Performance Optimization&lt;/h1&gt;&lt;p&gt;Important considerations include:&lt;/p&gt;&lt;h3&gt;Chunk Size&lt;/h3&gt;&lt;p&gt;Avoid extremely large chunks.&lt;/p&gt;&lt;p&gt;Use logically meaningful sections.&lt;/p&gt;&lt;h3&gt;Top K&lt;/h3&gt;&lt;p&gt;Retrieve a controlled number of candidates.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Top 5
Top 10
Top 20&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;depending on the workload.&lt;/p&gt;&lt;h3&gt;Hybrid Search&lt;/h3&gt;&lt;p&gt;Use hybrid retrieval when both exact matching and semantic matching matter.&lt;/p&gt;&lt;h3&gt;Semantic Ranking&lt;/h3&gt;&lt;p&gt;Use semantic ranking when better relevance justifies its additional cost/latency.&lt;/p&gt;&lt;h3&gt;Filters&lt;/h3&gt;&lt;p&gt;Apply metadata filters when possible.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;department = &#39;IT&#39;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;documentType = &#39;Policy&#39;&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Monitoring&lt;/h3&gt;&lt;p&gt;Monitor:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Latency
Query volume
Failed queries
Search relevance
Token usage
LLM latency
Cost&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;43. Production Architecture&lt;/h1&gt;&lt;p&gt;A more complete enterprise implementation might look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Users
                      |
                      v
                 Azure Front Door
                      |
                      v
                API Management
                      |
                      v
              ASP.NET Core API
                      |
          +-----------+-----------+
          |                       |
          v                       v
 Azure AI Search             Azure OpenAI
          |
          |
    +-----+------+
    |            |
    v            v
Vector Index   Text Index
    |
    v
Blob Storage
    |
    v
Documents&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Supporting services:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Key Vault
Azure Monitor
Application Insights
Azure Service Bus
Microsoft Entra ID&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;44. Monitoring&lt;/h1&gt;&lt;p&gt;Use Azure monitoring tools to observe:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Search latency
Request count
Errors
Throttling
Application latency
AI model latency
Token usage&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Application Insights can help trace:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HTTP Request
     |
     v
Search Query
     |
     v
Azure OpenAI
     |
     v
Response&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is especially valuable when debugging slow RAG applications.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;45. How to Design a Production RAG Pipeline&lt;/h1&gt;&lt;p&gt;A recommended pipeline is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1. Collect documents
        |
2. Extract text
        |
3. Clean text
        |
4. Split into chunks
        |
5. Generate embeddings
        |
6. Store chunks + vectors
        |
7. Build search index
        |
8. User asks question
        |
9. Retrieve candidates
        |
10. Hybrid search
        |
11. Semantic reranking
        |
12. Security filtering
        |
13. Build context
        |
14. Call Azure OpenAI
        |
15. Return answer + sources&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;46. Classic RAG vs Agentic Retrieval&lt;/h1&gt;&lt;p&gt;Azure AI Search now also provides &lt;strong&gt;agentic retrieval&lt;/strong&gt; capabilities.&lt;/p&gt;&lt;p&gt;Classic RAG generally follows:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Question
   |
   v
Search
   |
   v
Results
   |
   v
LLM&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Agentic retrieval can use an LLM to help understand and decompose more complex queries before retrieval.&lt;/p&gt;&lt;p&gt;Microsoft currently documents agentic retrieval as a newer retrieval approach, with some capabilities available in preview depending on the API/features used. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/search-relevance-overview?utm_source=chatgpt.com&quot; title=&quot;Relevance and Ranking Overview - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;For a first production implementation, classic hybrid RAG is often easier to understand, test, and operate.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;47. Recommended Technology Stack&lt;/h1&gt;&lt;p&gt;For a Microsoft-based enterprise application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Frontend
    Angular

Backend
    ASP.NET Core Web API

Search
    Azure AI Search

LLM
    Azure OpenAI

Embeddings
    Azure OpenAI embedding model

Storage
    Azure Blob Storage

Database
    Azure SQL

Messaging
    Azure Service Bus

Secrets
    Azure Key Vault

Identity
    Microsoft Entra ID

Monitoring
    Application Insights
    Azure Monitor

Deployment
    Azure App Service / AKS&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;48. Complete Request Flow&lt;/h1&gt;&lt;p&gt;Let&#39;s summarize the complete request:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    USER
                      |
                      v
                Angular App
                      |
                      v
              ASP.NET Core API
                      |
                      v
               User Question
                      |
                      v
             Query Processing
                      |
             +--------+--------+
             |                 |
             v                 v
        Keyword Search    Vector Search
             |                 |
             +--------+--------+
                      |
                      v
                     RRF
                      |
                      v
              Semantic Ranking
                      |
                      v
              Security Filtering
                      |
                      v
              Top Relevant Chunks
                      |
                      v
                 Prompt Builder
                      |
                      v
                Azure OpenAI
                      |
                      v
                Final Answer
                      |
                      v
             Answer + Citations
                      |
                      v
                    USER&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;49. Key Interview Questions&lt;/h1&gt;&lt;p&gt;If you are preparing for a .NET/Azure interview, these are important questions.&lt;/p&gt;&lt;h3&gt;Q1. What is Azure AI Search?&lt;/h3&gt;&lt;p&gt;A managed Azure service for information retrieval supporting full-text, vector, hybrid, semantic, and generative-AI search scenarios.&lt;/p&gt;&lt;h3&gt;Q2. What is vector search?&lt;/h3&gt;&lt;p&gt;Searching for documents based on vector similarity rather than only exact keywords.&lt;/p&gt;&lt;h3&gt;Q3. What is hybrid search?&lt;/h3&gt;&lt;p&gt;Combining keyword/full-text and vector search in the same request and merging their rankings using RRF. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/hybrid-search-overview?utm_source=chatgpt.com&quot; title=&quot;Hybrid Search Overview - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;h3&gt;Q4. What is semantic ranking?&lt;/h3&gt;&lt;p&gt;A second-stage relevance process that reranks an initial result set using language understanding models. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/semantic-search-overview?utm_source=chatgpt.com&quot; title=&quot;Semantic Ranking Overview - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;h3&gt;Q5. Why use Azure AI Search with Azure OpenAI?&lt;/h3&gt;&lt;p&gt;Azure AI Search retrieves enterprise-specific information, while Azure OpenAI generates a natural-language response based on that retrieved context.&lt;/p&gt;&lt;h3&gt;Q6. What is RAG?&lt;/h3&gt;&lt;p&gt;Retrieval-Augmented Generation: retrieve relevant external knowledge and provide it to an LLM as context for generating an answer.&lt;/p&gt;&lt;h3&gt;Q7. Why chunk documents?&lt;/h3&gt;&lt;p&gt;To retrieve smaller, relevant pieces of information instead of sending entire documents to the LLM.&lt;/p&gt;&lt;h3&gt;Q8. What is RRF?&lt;/h3&gt;&lt;p&gt;Reciprocal Rank Fusion is used to combine rankings from multiple search result sets, including hybrid search results. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/vector-search-ranking?utm_source=chatgpt.com&quot; title=&quot;Vector Relevance and Ranking - Azure AI Search | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;h3&gt;Q9. How do you secure Azure AI Search?&lt;/h3&gt;&lt;p&gt;Use Microsoft Entra ID, managed identities, RBAC, and security-aware filtering/authorization appropriate to the application.&lt;/p&gt;&lt;h3&gt;Q10. How would you integrate Azure AI Search into a .NET microservices architecture?&lt;/h3&gt;&lt;p&gt;Use a dedicated search/indexing component, publish domain events through messaging when data changes, and update the search index asynchronously.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;50. Final Takeaway&lt;/h1&gt;&lt;p&gt;Azure AI Search is much more than a traditional search engine.&lt;/p&gt;&lt;p&gt;It can provide:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Traditional Search
       +
Vector Search
       +
Hybrid Search
       +
Semantic Ranking
       +
RAG Retrieval
       +
Enterprise Security&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The most important architecture to remember is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;              YOUR DATA
                  |
                  v
          Azure AI Search
                  |
        +---------+---------+
        |                   |
   Keyword Search      Vector Search
        |                   |
        +---------+---------+
                  |
                 RRF
                  |
          Semantic Ranking
                  |
                  v
          Relevant Context
                  |
                  v
            Azure OpenAI
                  |
                  v
          Grounded Response&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a .NET developer, a particularly powerful enterprise stack is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   ↓
ASP.NET Core
   ↓
Azure AI Search
   ↓
Azure OpenAI
   ↓
Azure SQL / Blob Storage
   ↓
Azure Service Bus
   ↓
Key Vault + Managed Identity
   ↓
Application Insights&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This architecture can be used to build &lt;strong&gt;enterprise knowledge assistants, customer-support copilots, product search, document search, internal AI assistants, and RAG-based applications&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Microsoft also provides an official .NET RAG sample that combines Azure AI Search and Azure OpenAI, including document indexing and managed-identity-based authentication. (&lt;a href=&quot;https://learn.microsoft.com/th-th/azure/app-service/tutorial-ai-openai-search-dotnet?utm_source=chatgpt.com&quot; title=&quot;RAG application with Azure OpenAI and Azure AI Search (.NET) - Azure App Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;h2&gt;Official Microsoft References&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/?utm_source=chatgpt.com&quot;&gt;Azure AI Search Documentation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/hybrid-search-overview?utm_source=chatgpt.com&quot;&gt;Hybrid Search Overview&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/vector-search-overview?utm_source=chatgpt.com&quot;&gt;Vector Search Overview&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/retrieval-augmented-generation-overview?utm_source=chatgpt.com&quot;&gt;RAG with Azure AI Search&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/search/semantic-search-overview?utm_source=chatgpt.com&quot;&gt;Semantic Ranking&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/app-service/tutorial-ai-openai-search-dotnet?utm_source=chatgpt.com&quot;&gt;.NET RAG Tutorial with Azure OpenAI and Azure AI Search&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;In one sentence:&lt;/strong&gt; Azure AI Search is the retrieval layer that helps your application find the &lt;em&gt;right information&lt;/em&gt;, while Azure OpenAI is the generation layer that turns that information into a useful natural-language answer.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/3672127788042161530/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/3672127788042161530' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/3672127788042161530'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/3672127788042161530'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/azure-ai-search-complete-guide-with.html' title='Azure AI Search: Complete Guide with a Real-Time .NET Example'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvd47uIaAGxMX6neUu364E3EDz30iD5IlEjBPN8G79CYytmj7l8xccuU2GNGlWvBjI2LDAILASamPauPJ-pHFRWe65r2_kPR9mxqCKC2Dnp0K8k1e6fOZbe6TWDLmwKV-rB1biG8QkEhW3hv0i-ix6hAoOR76Ct2k8TAf1ADeLREmtaXjv2_xj8QwjFNQ/s72-w563-h319-c/AzureSearch.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-5644582668851537473</id><published>2026-08-19T13:06:24.974+05:30</published><updated>2026-08-19T13:06:24.975+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Migrating Database to Azure Cloud"/><title type='text'>How to Migrate SQL Server Database from Local Server to Azure Cloud</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdGQ5mN1rvIFZfm6aobO76vU0V0KOuqA9Hr01O9t0nYdeQhSFjKMe4KRBZQrhxSUFKmtEWG26ggJ_hrcW8a5jWLVgzjVo-4Nbe5ytiGe8ktC90Mrzt6xjsgLcus0icFaSJLlaSYRHHmZhExodwb8sTnmP1CBPl4CxqbtD1tSYyZItN6DV60jIQaoJS6Rc/s1536/MigratingDatabase.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;275&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdGQ5mN1rvIFZfm6aobO76vU0V0KOuqA9Hr01O9t0nYdeQhSFjKMe4KRBZQrhxSUFKmtEWG26ggJ_hrcW8a5jWLVgzjVo-4Nbe5ytiGe8ktC90Mrzt6xjsgLcus0icFaSJLlaSYRHHmZhExodwb8sTnmP1CBPl4CxqbtD1tSYyZItN6DV60jIQaoJS6Rc/w537-h275/MigratingDatabase.png&quot; width=&quot;537&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2&gt;Complete Step-by-Step Guide for SQL Server to Azure Migration&lt;/h2&gt;&lt;p&gt;Moving a SQL Server database from an on-premises/local server to Microsoft Azure is a common requirement when organizations want to modernize their infrastructure, improve scalability, increase availability, and reduce the operational effort involved in maintaining physical database servers.&lt;/p&gt;&lt;p&gt;In this article, we will walk through the complete migration process:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Local SQL Server → Azure Storage → Azure SQL → Application Connection&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;We will also discuss the different Azure SQL options, backup and restore, Azure Database Migration Service (DMS), validation, application connection-string changes, and post-migration activities.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. What Are We Migrating?&lt;/h1&gt;&lt;p&gt;Assume we currently have the following environment:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LOCAL / ON-PREMISES SERVER
        |
        | SQL Server
        |
        +-- CustomerDB
        +-- OrderDB
        +-- ProductDB
        |
        +-- ASP.NET Core Web API
        +-- Angular Application&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We want to move the database to Azure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         AZURE CLOUD
                              |
                    +---------+---------+
                    |                   |
               Azure SQL          Azure Storage
                    |
              CustomerDB
              OrderDB
              ProductDB
                    |
              ASP.NET Core API
                    |
                 Angular&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The migration does not necessarily mean simply copying the &lt;code inline=&quot;&quot;&gt;.mdf&lt;/code&gt; and &lt;code inline=&quot;&quot;&gt;.ldf&lt;/code&gt; files to Azure.&lt;/p&gt;&lt;p&gt;The correct migration approach depends on the Azure target you choose.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. Azure SQL Deployment Options&lt;/h1&gt;&lt;p&gt;Before migrating, the first and most important decision is:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Where should the SQL Server database run in Azure?&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;There are three major options.&lt;/p&gt;&lt;h2&gt;Option 1 – Azure SQL Database&lt;/h2&gt;&lt;p&gt;Azure SQL Database is a fully managed database platform.&lt;/p&gt;&lt;p&gt;Microsoft manages many infrastructure tasks such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Hardware&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Operating system&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Database patching&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Backups&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;High availability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Infrastructure maintenance&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It is generally the best choice when your application can work with a database-as-a-service model.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core API
       |
       v
Azure SQL Database
       |
       v
Managed by Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, Azure SQL Database is not identical to a traditional SQL Server instance, so compatibility should be assessed before migration.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Option 2 – Azure SQL Managed Instance&lt;/h1&gt;&lt;p&gt;Azure SQL Managed Instance provides much greater compatibility with traditional SQL Server.&lt;/p&gt;&lt;p&gt;It is particularly useful when your existing application depends on SQL Server instance-level capabilities or you want a more lift-and-shift-oriented migration.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ON-PREMISES

SQL Server Instance
       |
       +-- Database A
       +-- Database B
       +-- Database C
       |
       +-- Logins
       +-- SQL Agent Jobs
       +-- Cross-database functionality&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;can be moved toward:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;AZURE

SQL Managed Instance
       |
       +-- Database A
       +-- Database B
       +-- Database C&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft describes SQL Managed Instance as a suitable target when you need maximum compatibility and when your applications depend on instance-level or cross-database functionality. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/managed-instance/guide?utm_source=chatgpt.com&quot; title=&quot;SQL Server to Azure SQL Managed Instance: Migration Guide | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;4. Option 3 – SQL Server on Azure Virtual Machine&lt;/h1&gt;&lt;p&gt;This is the closest approach to your existing environment.&lt;/p&gt;&lt;p&gt;You create an Azure VM and install/run SQL Server on it.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure
 |
 +-- Virtual Network
      |
      +-- SQL Server VM
             |
             +-- SQL Server
                    |
                    +-- Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This approach is useful when you need very high compatibility with the existing SQL Server environment.&lt;/p&gt;&lt;p&gt;It is essentially a &lt;strong&gt;lift-and-shift&lt;/strong&gt; approach.&lt;/p&gt;&lt;p&gt;Microsoft&#39;s current migration tooling supports SQL Server migrations to SQL Server on Azure VMs using Azure Database Migration Service. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/virtual-machines/database-migration-service-online?utm_source=chatgpt.com&quot; title=&quot;Tutorial: Migrate SQL Server to SQL Server on an Azure Virtual Machine with Azure DMS (Online) - Azure Database Migration Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Which Azure Option Should You Choose?&lt;/h1&gt;&lt;p&gt;A simplified decision table is:&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Requirement&lt;/th&gt;&lt;th&gt;Recommended Target&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Fully managed database&lt;/td&gt;&lt;td&gt;Azure SQL Database&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;High SQL Server compatibility&lt;/td&gt;&lt;td&gt;Azure SQL Managed Instance&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Almost identical SQL Server environment&lt;/td&gt;&lt;td&gt;SQL Server on Azure VM&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Cross-database functionality&lt;/td&gt;&lt;td&gt;Managed Instance / Azure VM&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SQL Agent and instance-level dependencies&lt;/td&gt;&lt;td&gt;Managed Instance / Azure VM&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Modern cloud-native application&lt;/td&gt;&lt;td&gt;Azure SQL Database&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Lift-and-shift migration&lt;/td&gt;&lt;td&gt;Managed Instance / Azure VM&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Do not choose the target only because it is easy to create.&lt;/p&gt;&lt;p&gt;First perform a compatibility and dependency assessment.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. Migration Architecture&lt;/h1&gt;&lt;p&gt;A typical migration architecture looks like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 ON-PREMISES
              +----------------+
              | Local SQL      |
              | Server         |
              |                |
              | CustomerDB     |
              | OrderDB        |
              +-------+--------+
                      |
                      | Backup
                      v
              +---------------+
              | Azure Storage |
              | Blob          |
              +-------+-------+
                      |
                      v
              +---------------+
              | Azure Database|
              | Migration     |
              | Service       |
              +-------+-------+
                      |
                      v
              +---------------+
              | Azure SQL     |
              | Managed       |
              | Instance /    |
              | SQL Database  |
              +-------+-------+
                      |
                      v
              ASP.NET Core API
                      |
                      v
                 Angular App&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For some migration scenarios, Azure DMS uses database backup files stored in Azure Storage. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/virtual-machines/database-migration-service-online?utm_source=chatgpt.com&quot; title=&quot;Tutorial: Migrate SQL Server to SQL Server on an Azure Virtual Machine with Azure DMS (Online) - Azure Database Migration Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;7. Step 1 – Analyze the Existing SQL Server&lt;/h1&gt;&lt;p&gt;Before moving anything, collect information about your existing SQL Server.&lt;/p&gt;&lt;p&gt;Check:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SQL Server version&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL Server edition&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Database size&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Number of databases&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Database compatibility level&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL Agent jobs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Logins&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Users&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Linked servers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Stored procedures&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Functions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Views&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Triggers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SSIS packages&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cross-database queries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;CLR dependencies&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Encryption&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;External dependencies&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Application connection strings&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
    name,
    database_id,
    compatibility_level,
    state_desc
FROM sys.databases
ORDER BY name;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Check database size:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
    DB_NAME(database_id) AS DatabaseName,
    SUM(size) * 8 / 1024 AS SizeMB
FROM sys.master_files
GROUP BY database_id
ORDER BY SizeMB DESC;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This gives you an initial understanding of your environment.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. Step 2 – Perform a Compatibility Assessment&lt;/h1&gt;&lt;p&gt;This step is extremely important.&lt;/p&gt;&lt;p&gt;Do not immediately migrate a production database.&lt;/p&gt;&lt;p&gt;First determine whether your existing SQL Server features are supported by the Azure target.&lt;/p&gt;&lt;p&gt;Microsoft&#39;s current SSMS migration functionality can assess a SQL Server instance and recommend Azure SQL targets such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure SQL Database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure SQL Managed Instance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL Server on Azure VM&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It can also identify compatibility considerations before migration. (&lt;a href=&quot;https://learn.microsoft.com/en-us/ssms/migrate/migrate-sql-server-azure-sql?utm_source=chatgpt.com&quot; title=&quot;Migrate SQL Server to Azure SQL | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;A typical process is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Discover
   |
   v
Assess
   |
   v
Identify blockers
   |
   v
Fix compatibility issues
   |
   v
Migrate&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;9. Step 3 – Create an Azure Account&lt;/h1&gt;&lt;p&gt;Open the Azure Portal:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;https://portal.azure.com&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Sign in with your Azure account.&lt;/p&gt;&lt;p&gt;You need an Azure subscription.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. Step 4 – Create a Resource Group&lt;/h1&gt;&lt;p&gt;A Resource Group is a logical container for Azure resources.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Resource Group:
rg-production-database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You may place resources such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;rg-production-database
 |
 +-- Azure SQL
 +-- Storage Account
 +-- Database Migration Service
 +-- Key Vault
 +-- Monitoring resources&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For production environments, use a naming convention appropriate for your organization.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;rg-prod-sql-eastus
rg-prod-storage-eastus&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Step 5 – Create Azure Storage&lt;/h1&gt;&lt;p&gt;Azure Storage can be used as an intermediate location for database backup files.&lt;/p&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Storage Account
      |
      +-- Blob Container
             |
             +-- sqlbackups&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;https://mystorageaccount.blob.core.windows.net/sqlbackups/&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can place backup files here:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CustomerDB.bak
OrderDB.bak
ProductDB.bak&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For migration projects using Azure DMS, Microsoft recommends using a dedicated storage account for migration-related backup files rather than sharing it with unrelated workloads. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/virtual-machines/database-migration-service-online?utm_source=chatgpt.com&quot; title=&quot;Tutorial: Migrate SQL Server to SQL Server on an Azure Virtual Machine with Azure DMS (Online) - Azure Database Migration Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Step 6 – Take a Full SQL Server Backup&lt;/h1&gt;&lt;p&gt;On your local SQL Server, take a full backup.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;BACKUP DATABASE CustomerDB
TO DISK = &#39;D:\SQLBackups\CustomerDB.bak&#39;
WITH
    INIT,
    COMPRESSION,
    STATS = 10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Verify that the backup completed successfully.&lt;/p&gt;&lt;p&gt;You can check backup history:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
    database_name,
    backup_start_date,
    backup_finish_date,
    type,
    backup_size
FROM msdb.dbo.backupset
WHERE database_name = &#39;CustomerDB&#39;
ORDER BY backup_finish_date DESC;&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;13. Step 7 – Upload the Backup to Azure Storage&lt;/h1&gt;&lt;p&gt;Upload:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CustomerDB.bak&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Storage
     |
     +-- sqlbackups
           |
           +-- CustomerDB.bak&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can use Azure Storage tools or Azure-supported migration workflows.&lt;/p&gt;&lt;p&gt;For large databases, uploading the backup can take significant time, so estimate the transfer duration before scheduling production migration.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. Step 8 – Create the Azure SQL Target&lt;/h1&gt;&lt;p&gt;Now create the target.&lt;/p&gt;&lt;p&gt;For example, if you selected Azure SQL Managed Instance:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Portal
    |
    +-- Azure SQL
          |
          +-- SQL Managed Instance&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Subscription&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Resource Group&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Region&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Instance name&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Compute&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Networking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Authentication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security settings&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For Azure SQL Database, create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure SQL Server
       |
       +-- Azure SQL Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For SQL Server on Azure VM:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure VM
   |
   +-- SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. Step 9 – Configure Networking&lt;/h1&gt;&lt;p&gt;This is one of the most commonly overlooked parts of a database migration.&lt;/p&gt;&lt;p&gt;Your application must be able to reach the Azure database.&lt;/p&gt;&lt;p&gt;Typical architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Internet
                       |
                       v
                Azure Front Door
                       |
                       v
                 Application
                       |
                       v
                ASP.NET Core API
                       |
                       v
                 Private Network
                       |
                       v
                Azure SQL&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For production systems, consider:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Virtual Network&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Private Endpoint / Private networking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Network Security Groups&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Firewall rules&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DNS configuration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;VPN&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ExpressRoute where required&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Avoid exposing a production database unnecessarily to the public internet.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. Step 10 – Choose Your Migration Method&lt;/h1&gt;&lt;p&gt;There are several approaches.&lt;/p&gt;&lt;h2&gt;Method A – BACPAC&lt;/h2&gt;&lt;p&gt;Useful for certain Azure SQL Database migration scenarios.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Local SQL Server
       |
       | Export
       v
    .bacpac
       |
       v
Azure SQL Database&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Azure SQL supports importing a BACPAC file into Azure SQL Database or SQL Managed Instance. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/azure-sql/database/database-import?view=azuresql&amp;amp;utm_source=chatgpt.com&quot; title=&quot;Import a BACPAC File to Create a Database in Azure SQL Database - Azure SQL Database &amp;amp; Azure SQL Managed Instance | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. Method B – Backup and Restore&lt;/h1&gt;&lt;p&gt;This is a traditional SQL Server migration approach.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Local SQL Server
       |
       | .bak
       v
Azure Storage
       |
       v
Azure SQL Managed Instance&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This approach is especially useful for SQL Managed Instance.&lt;/p&gt;&lt;p&gt;Microsoft supports native backup/restore of SQL Server backups stored in Azure Storage for SQL Managed Instance. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/managed-instance/guide?utm_source=chatgpt.com&quot; title=&quot;SQL Server to Azure SQL Managed Instance: Migration Guide | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;RESTORE DATABASE CustomerDB
FROM URL =
&#39;https://mystorageaccount.blob.core.windows.net/sqlbackups/CustomerDB.bak&#39;;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The exact credential and restore configuration depends on your target and storage authentication method.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;18. Method C – Azure Database Migration Service&lt;/h1&gt;&lt;p&gt;Azure Database Migration Service, or Azure DMS, is designed specifically for database migration scenarios.&lt;/p&gt;&lt;p&gt;The general workflow is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Source SQL Server
       |
       v
Azure Database Migration Service
       |
       v
Azure SQL Target&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft currently provides DMS migration paths for SQL Server to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure SQL Database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure SQL Managed Instance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL Server on Azure VM. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/dms/?utm_source=chatgpt.com&quot; title=&quot;Azure Database Migration Service documentation | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;19. Step 11 – Create Azure Database Migration Service&lt;/h1&gt;&lt;p&gt;In the Azure Portal:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Portal
  |
  +-- Search
       |
       +-- Azure Database Migration Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Create&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Subscription
Resource Group
Region
Service name
Networking&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After deployment:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Database Migration Service
              |
              +-- New Migration&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Step 12 – Configure Source SQL Server&lt;/h1&gt;&lt;p&gt;Provide your source SQL Server information.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Source Server:
192.168.1.50

Database:
CustomerDB

Authentication:
SQL Authentication / Windows Authentication&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The exact connectivity setup depends on your migration scenario and network architecture.&lt;/p&gt;&lt;p&gt;If backup files are located on an on-premises network share, some DMS scenarios require a self-hosted integration runtime so the migration service can access the source environment and backup files. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/virtual-machines/database-migration-service-online?utm_source=chatgpt.com&quot; title=&quot;Tutorial: Migrate SQL Server to SQL Server on an Azure Virtual Machine with Azure DMS (Online) - Azure Database Migration Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;21. Step 13 – Select the Target&lt;/h1&gt;&lt;p&gt;Select the Azure destination.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Source:
SQL Server

Target:
Azure SQL Managed Instance&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Subscription
Resource Group
Managed Instance
Target Database&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;22. Step 14 – Configure Backup Storage&lt;/h1&gt;&lt;p&gt;Tell the migration service where the backup files are located.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Storage Account
     |
     +-- sqlbackups
           |
           +-- CustomerDB.bak
           +-- CustomerDB_Log.trn&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Depending on the migration mode, full and subsequent transaction-log backups may be involved.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;23. Step 15 – Start the Migration&lt;/h1&gt;&lt;p&gt;Once configuration is complete:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Validate
   |
   v
Start Migration&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Azure DMS will perform the migration according to the selected migration scenario.&lt;/p&gt;&lt;p&gt;Monitor:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Migration Status
        |
        +-- Starting
        +-- In Progress
        +-- Validating
        +-- Completed
        +-- Failed&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Microsoft&#39;s DMS documentation describes monitoring the migration from the DMS monitoring experience. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/virtual-machines/database-migration-service-online?utm_source=chatgpt.com&quot; title=&quot;Tutorial: Migrate SQL Server to SQL Server on an Azure Virtual Machine with Azure DMS (Online) - Azure Database Migration Service | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;24. Step 16 – Monitor Migration&lt;/h1&gt;&lt;p&gt;Do not immediately switch your application to Azure.&lt;/p&gt;&lt;p&gt;First verify the migration.&lt;/p&gt;&lt;p&gt;Check:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Database Status
Data Size
Tables
Indexes
Stored Procedures
Functions
Views
Triggers
Users
Permissions&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Run:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
    name,
    state_desc
FROM sys.databases;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then connect to the Azure target using SSMS.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;25. Step 17 – Validate the Data&lt;/h1&gt;&lt;p&gt;This is one of the most important steps.&lt;/p&gt;&lt;p&gt;Compare:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LOCAL DATABASE
       vs
AZURE DATABASE&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Check table counts:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
    t.name AS TableName,
    SUM(p.rows) AS RowCount
FROM sys.tables t
INNER JOIN sys.partitions p
    ON t.object_id = p.object_id
WHERE p.index_id IN (0,1)
GROUP BY t.name
ORDER BY t.name;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Run the same query against the Azure database.&lt;/p&gt;&lt;p&gt;Compare:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer
Local: 1,250,000
Azure: 1,250,000

Orders
Local: 8,500,000
Azure: 8,500,000&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Also validate:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Primary keys&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Foreign keys&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Indexes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Constraints&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Stored procedures&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Functions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Views&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Triggers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Permissions&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;26. Step 18 – Test Application Connectivity&lt;/h1&gt;&lt;p&gt;Suppose your existing ASP.NET Core application has:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;ConnectionStrings&quot;: {
    &quot;DefaultConnection&quot;: &quot;Server=LOCALSERVER;Database=CustomerDB;Trusted_Connection=True;&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After migration, the application must connect to the Azure database.&lt;/p&gt;&lt;p&gt;The new connection string depends on your selected Azure service and authentication method.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;ConnectionStrings&quot;: {
    &quot;DefaultConnection&quot;: &quot;Server=&amp;lt;AZURE-SQL-SERVER&amp;gt;;Database=CustomerDB;...&quot;
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Do not hard-code production passwords into source code.&lt;/p&gt;&lt;p&gt;For production applications, consider Azure Key Vault and managed identity-based authentication where appropriate.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. Step 19 – Update ASP.NET Core Configuration&lt;/h1&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddDbContext&amp;lt;ApplicationDbContext&amp;gt;(options =&amp;gt;
    options.UseSqlServer(
        builder.Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application code does not necessarily need to change.&lt;/p&gt;&lt;p&gt;Usually, the major change is the database connection configuration.&lt;/p&gt;&lt;p&gt;This is one of the major advantages of using Entity Framework Core with SQL Server-compatible Azure targets.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;28. Step 20 – Test CRUD Operations&lt;/h1&gt;&lt;p&gt;After changing the connection string, test:&lt;/p&gt;&lt;h3&gt;Create&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Create Customer&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Read&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Get Customer&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Update&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Update Customer&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Delete&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Delete Customer&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Also test:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Login
Search
Reports
Transactions
Batch jobs
Background services
Stored procedures
File uploads
Notifications&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;29. Step 21 – Performance Testing&lt;/h1&gt;&lt;p&gt;Do not assume that migration automatically means better performance.&lt;/p&gt;&lt;p&gt;Measure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Before Migration
----------------
API Response: 250 ms
DB Query: 100 ms

After Migration
---------------
API Response: 180 ms
DB Query: 70 ms&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or identify queries that became slower.&lt;/p&gt;&lt;p&gt;Check:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;CPU&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Memory&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DTU/vCore usage depending on Azure SQL offering&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Query duration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Blocking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deadlocks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Index usage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Database waits&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Connection pool usage&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Use Azure monitoring capabilities and SQL performance tools to investigate performance.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;30. Step 22 – Security Configuration&lt;/h1&gt;&lt;p&gt;Production databases should be secured properly.&lt;/p&gt;&lt;p&gt;Consider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure SQL
   |
   +-- Firewall
   +-- Private Endpoint
   +-- Microsoft Entra authentication
   +-- Managed Identity
   +-- Encryption
   +-- Auditing
   +-- Defender for SQL
   +-- Key Vault&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Never publish credentials in:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;GitHub
appsettings.json
Source Code
Dockerfile
Azure DevOps YAML&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For production, use secure secret-management mechanisms.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;31. Step 23 – Configure Backups&lt;/h1&gt;&lt;p&gt;One major advantage of Azure SQL services is that Azure provides managed backup capabilities.&lt;/p&gt;&lt;p&gt;However, you should still understand:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Backup
   |
   +-- Retention
   +-- Point-in-time restore
   +-- Long-term retention
   +-- Disaster recovery&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Your backup strategy should match your organization&#39;s Recovery Point Objective (RPO) and Recovery Time Objective (RTO).&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;32. Step 24 – Configure Monitoring&lt;/h1&gt;&lt;p&gt;Use Azure monitoring capabilities to observe your database.&lt;/p&gt;&lt;p&gt;Typical monitoring architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure SQL
   |
   +-- Azure Monitor
   |
   +-- Log Analytics
   |
   +-- Application Insights
   |
   +-- Alerts&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create alerts for important conditions such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;High CPU
High storage usage
Connection failures
Long-running queries
Availability problems&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;33. Step 25 – Application Cutover&lt;/h1&gt;&lt;p&gt;Once testing is successful, perform the final cutover.&lt;/p&gt;&lt;p&gt;A typical production cutover is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1. Notify users
        |
2. Stop application writes
        |
3. Complete final synchronization
        |
4. Validate Azure database
        |
5. Update connection string
        |
6. Deploy application
        |
7. Start application
        |
8. Perform smoke testing
        |
9. Monitor&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For migration methods that maintain synchronization, Microsoft recommends ensuring the target is synchronized and validated before switching application traffic. (&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/azure-sql/database/migrate-to-database-from-sql-server?view=azuresql&amp;amp;utm_source=chatgpt.com&quot; title=&quot;SQL Server to Azure SQL Database: Migration Guide | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;34. Example Production Migration&lt;/h1&gt;&lt;p&gt;Suppose we have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LOCAL SERVER

Server: SQLSERVER01

Database:
SalesDB

Size:
500 GB

Application:
ASP.NET Core Web API

Frontend:
Angular&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We want:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;AZURE

Azure SQL Managed Instance

Database:
SalesDB&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The migration architecture becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 ON-PREMISES
                     |
                     |
              SQLSERVER01
                     |
                  SalesDB
                     |
                  Backup
                     |
                     v
              Azure Storage
                     |
                     v
        Azure Database Migration
                 Service
                     |
                     v
          Azure SQL Managed
                Instance
                     |
                     v
              ASP.NET Core API
                     |
                     v
                 Angular&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;35. Complete Migration Flow&lt;/h1&gt;&lt;p&gt;The complete process can be summarized as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;              LOCAL SQL SERVER
                     |
                     v
             Database Assessment
                     |
                     v
             Compatibility Check
                     |
                     v
              Choose Azure Target
                     |
          +----------+----------+
          |          |          |
          v          v          v
       SQL DB       MI       Azure VM
          |          |          |
          +----------+----------+
                     |
                     v
              Create Azure
              Infrastructure
                     |
                     v
             Create Storage
                     |
                     v
              Take Backup
                     |
                     v
          Upload / Configure
              Backup Storage
                     |
                     v
            Azure DMS / Restore
                     |
                     v
             Migration Complete
                     |
                     v
             Validate Database
                     |
                     v
             Test Application
                     |
                     v
             Performance Test
                     |
                     v
                Cutover
                     |
                     v
              Azure Production&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;36. Common Migration Problems&lt;/h1&gt;&lt;h2&gt;Problem 1 – Unsupported SQL Server Feature&lt;/h2&gt;&lt;p&gt;Your local SQL Server may use a feature that isn&#39;t available on the selected Azure target.&lt;/p&gt;&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;Perform compatibility assessment before migration.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Problem 2 – Application Cannot Connect&lt;/h2&gt;&lt;p&gt;Possible causes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Firewall
Networking
DNS
Authentication
Connection String
Private Endpoint
Credentials&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Check each layer systematically.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Problem 3 – Database Is Very Large&lt;/h2&gt;&lt;p&gt;For a very large database, BACPAC export/import may not be the best approach.&lt;/p&gt;&lt;p&gt;Consider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Database Migration Service
Backup/Restore
Managed Instance Link
Log Replay Service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;depending on your target and downtime requirements.&lt;/p&gt;&lt;p&gt;Microsoft documents multiple migration paths for SQL Managed Instance, including DMS, Managed Instance link, Log Replay Service, and native restore. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/managed-instance/guide?utm_source=chatgpt.com&quot; title=&quot;SQL Server to Azure SQL Managed Instance: Migration Guide | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;37. What About Minimal Downtime?&lt;/h1&gt;&lt;p&gt;Suppose your database is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;2 TB&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and your application cannot be stopped for several hours.&lt;/p&gt;&lt;p&gt;A simple:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Backup
   ↓
Upload
   ↓
Restore&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;may result in too much downtime.&lt;/p&gt;&lt;p&gt;Instead, consider a migration method that supports ongoing synchronization/replication, depending on your target.&lt;/p&gt;&lt;p&gt;The architecture becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LOCAL SQL SERVER
       |
       | Initial migration
       v
AZURE DATABASE
       ^
       |
       | Continuous changes
       |
LOCAL SQL SERVER&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Stop application
      |
      v
Final synchronization
      |
      v
Validate target
      |
      v
Change connection string
      |
      v
Start application&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can significantly reduce the final cutover window.&lt;/p&gt;&lt;p&gt;For SQL Managed Instance, Microsoft documents DMS, Managed Instance link, and Log Replay Service for migration scenarios designed to reduce downtime. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/managed-instance/guide?utm_source=chatgpt.com&quot; title=&quot;SQL Server to Azure SQL Managed Instance: Migration Guide | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;38. What Happens to SQL Agent Jobs?&lt;/h1&gt;&lt;p&gt;This depends heavily on your target.&lt;/p&gt;&lt;p&gt;If you move to SQL Server on Azure VM, you retain a traditional SQL Server environment.&lt;/p&gt;&lt;p&gt;With SQL Managed Instance, many SQL Server instance-level capabilities are supported, including SQL Agent-related workloads, although you should still assess individual dependencies.&lt;/p&gt;&lt;p&gt;With Azure SQL Database, you should not assume that every SQL Server instance-level feature will move directly.&lt;/p&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL Server Agent Jobs
        |
        +-- Identify
        |
        +-- Assess
        |
        +-- Recreate / redesign where required&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;39. What Happens to Logins and Users?&lt;/h1&gt;&lt;p&gt;Database users and server-level logins are different concepts.&lt;/p&gt;&lt;p&gt;You should inventory:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Server Logins
Database Users
Roles
Permissions
Application Accounts
Service Accounts&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After migration, verify that every application identity has the correct permissions.&lt;/p&gt;&lt;p&gt;Do not simply grant:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;db_owner&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;to every application account.&lt;/p&gt;&lt;p&gt;Use the minimum permissions required.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;40. What Happens to Stored Procedures?&lt;/h1&gt;&lt;p&gt;Stored procedures generally migrate well when supported by the selected target.&lt;/p&gt;&lt;p&gt;After migration, execute important procedures and compare results.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;EXEC dbo.GetCustomerOrders
     @CustomerId = 1001;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Compare the results between:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Local SQL Server
vs
Azure SQL&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;41. What Happens to SQL Server Jobs and SSIS?&lt;/h1&gt;&lt;p&gt;Create an inventory before migration.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL Agent Jobs
SSIS Packages
Linked Servers
Maintenance Plans
Database Mail
Cross Database Queries
CLR
Replication&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Some workloads may need redesign when moving to a fully managed Azure SQL platform.&lt;/p&gt;&lt;p&gt;This is one reason why &lt;strong&gt;assessment before migration is critical&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;42. Rollback Strategy&lt;/h1&gt;&lt;p&gt;Never perform a production database migration without a rollback plan.&lt;/p&gt;&lt;p&gt;Before cutover:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LOCAL DATABASE
       |
       +-- Final backup
       |
       +-- Keep source available&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If something goes wrong:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure
  |
  X
  |
Rollback
  |
  v
Local SQL Server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Do not immediately delete the original database after migration.&lt;/p&gt;&lt;p&gt;Keep the source environment available until:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application validated
Data validated
Business users approved
Performance validated
Monitoring stable
Rollback window completed&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;43. Production Migration Checklist&lt;/h1&gt;&lt;p&gt;Before migration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;☐ Inventory SQL Server
☐ Check database size
☐ Check SQL Server version
☐ Assess compatibility
☐ Identify dependencies
☐ Identify SQL Agent jobs
☐ Identify logins/users
☐ Identify linked servers
☐ Choose Azure target
☐ Create Azure subscription/resource group
☐ Configure networking
☐ Create target database/server
☐ Configure Azure Storage
☐ Take backup
☐ Test restore&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;During migration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;☐ Start migration
☐ Monitor migration
☐ Check errors
☐ Verify database state
☐ Compare row counts
☐ Validate schema
☐ Validate indexes
☐ Validate users
☐ Validate permissions&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Before cutover:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;☐ Test application
☐ Test APIs
☐ Test reports
☐ Test transactions
☐ Test performance
☐ Prepare rollback
☐ Notify stakeholders&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After cutover:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;☐ Update connection string
☐ Deploy application
☐ Smoke test
☐ Monitor database
☐ Monitor API
☐ Monitor errors
☐ Monitor performance
☐ Obtain business approval&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;44. Recommended Architecture for a .NET + Angular Application&lt;/h1&gt;&lt;p&gt;For a modern application, the architecture could look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                       USERS
                         |
                         v
                    Angular SPA
                         |
                         v
                Azure Front Door
                         |
                         v
                Azure API Management
                         |
                         v
                 ASP.NET Core APIs
                         |
              +----------+----------+
              |                     |
              v                     v
       Azure Service Bus       Azure SQL
              |               Managed Instance
              |                     |
              v                     v
       Background Workers       Database
              |
              v
       External Services&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Additional Azure services can be introduced based on requirements:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Key Vault
Azure Monitor
Application Insights
Azure Storage
Azure Container Registry
AKS / App Service
Azure Functions&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;45. Azure SQL Database vs Managed Instance vs Azure VM&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Azure SQL Database&lt;/th&gt;&lt;th&gt;SQL Managed Instance&lt;/th&gt;&lt;th&gt;SQL Server Azure VM&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Fully managed&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SQL Server compatibility&lt;/td&gt;&lt;td&gt;Moderate&lt;/td&gt;&lt;td&gt;High&lt;/td&gt;&lt;td&gt;Very High&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;OS management&lt;/td&gt;&lt;td&gt;Azure&lt;/td&gt;&lt;td&gt;Azure&lt;/td&gt;&lt;td&gt;Customer&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SQL Server instance access&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;High&lt;/td&gt;&lt;td&gt;Full&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Lift-and-shift&lt;/td&gt;&lt;td&gt;Sometimes&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Cross-database scenarios&lt;/td&gt;&lt;td&gt;Limited compared with MI&lt;/td&gt;&lt;td&gt;Strong&lt;/td&gt;&lt;td&gt;Strong&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SQL Agent&lt;/td&gt;&lt;td&gt;Not traditional SQL Agent&lt;/td&gt;&lt;td&gt;Supported scenarios&lt;/td&gt;&lt;td&gt;Full&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Infrastructure control&lt;/td&gt;&lt;td&gt;Low&lt;/td&gt;&lt;td&gt;Medium&lt;/td&gt;&lt;td&gt;High&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Administration effort&lt;/td&gt;&lt;td&gt;Lowest&lt;/td&gt;&lt;td&gt;Medium&lt;/td&gt;&lt;td&gt;Highest&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Always verify the current feature support for your exact SQL Server version and Azure target before production migration.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;46. Recommended Approach&lt;/h1&gt;&lt;p&gt;For a typical enterprise application currently running:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core
Angular
SQL Server
Azure Services&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I recommend this decision process:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 Existing SQL Server
                         |
                         v
                Compatibility Assessment
                         |
             +-----------+-----------+
             |                       |
       Minimal changes          Cloud modernization
             |                       |
             v                       v
     SQL Managed Instance       Azure SQL Database
             |
             |
       Very high SQL
       compatibility
             |
             v
     SQL Server Azure VM&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a large existing SQL Server environment with many instance-level dependencies, &lt;strong&gt;Azure SQL Managed Instance&lt;/strong&gt; is often a strong candidate.&lt;/p&gt;&lt;p&gt;For a modern application that can adapt to Azure SQL Database capabilities, &lt;strong&gt;Azure SQL Database&lt;/strong&gt; can reduce infrastructure administration.&lt;/p&gt;&lt;p&gt;For applications requiring maximum control and near-traditional SQL Server behavior, &lt;strong&gt;SQL Server on Azure VM&lt;/strong&gt; is the closest lift-and-shift option.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;47. Final Takeaway&lt;/h1&gt;&lt;p&gt;Migrating SQL Server to Azure is not simply:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Copy Database
      ↓
Azure&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A successful migration is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASSESS
   ↓
PLAN
   ↓
CHOOSE TARGET
   ↓
PREPARE AZURE
   ↓
BACKUP / MIGRATE
   ↓
VALIDATE
   ↓
TEST
   ↓
CUTOVER
   ↓
MONITOR
   ↓
OPTIMIZE&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The most important rule is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Never migrate a production database directly without first performing compatibility assessment, testing the migration, validating the data, and preparing a rollback plan.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Azure provides several migration approaches, and the correct choice depends on the target platform, database size, SQL Server features, network architecture, and acceptable downtime. Microsoft currently documents Azure DMS, native backup/restore, Managed Instance link, and Log Replay Service among the available migration approaches for relevant SQL Server-to-Azure scenarios. (&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/managed-instance/guide?utm_source=chatgpt.com&quot; title=&quot;SQL Server to Azure SQL Managed Instance: Migration Guide | Microsoft Learn&quot;&gt;Microsoft Learn&lt;/a&gt;)&lt;/p&gt;&lt;h2&gt;Official Microsoft References&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/ssms/migrate/migrate-sql-server-azure-sql?utm_source=chatgpt.com&quot;&gt;Microsoft Learn – Migrate SQL Server to Azure SQL&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/dms/?utm_source=chatgpt.com&quot;&gt;Microsoft Learn – Azure Database Migration Service&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/azure-sql/database/migrate-to-database-from-sql-server?utm_source=chatgpt.com&quot;&gt;SQL Server to Azure SQL Database Migration Guide&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/data-migration/sql-server/managed-instance/guide?utm_source=chatgpt.com&quot;&gt;SQL Server to Azure SQL Managed Instance Migration Guide&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/azure-sql/database/database-import?utm_source=chatgpt.com&quot;&gt;Import BACPAC into Azure SQL&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/5644582668851537473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/5644582668851537473' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/5644582668851537473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/5644582668851537473'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/how-to-migrate-sql-server-database-from.html' title='How to Migrate SQL Server Database from Local Server to Azure Cloud'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdGQ5mN1rvIFZfm6aobO76vU0V0KOuqA9Hr01O9t0nYdeQhSFjKMe4KRBZQrhxSUFKmtEWG26ggJ_hrcW8a5jWLVgzjVo-4Nbe5ytiGe8ktC90Mrzt6xjsgLcus0icFaSJLlaSYRHHmZhExodwb8sTnmP1CBPl4CxqbtD1tSYyZItN6DV60jIQaoJS6Rc/s72-w537-h275-c/MigratingDatabase.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-4164376258199362699</id><published>2026-08-18T06:16:48.212+05:30</published><updated>2026-08-18T06:16:48.212+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="RAG"/><category scheme="http://www.blogger.com/atom/ns#" term="Retrieval-Augmented Generation"/><title type='text'>Retrieval-Augmented Generation (RAG): Complete Guide with Architecture, Real-Time Examples and .NET Implementation</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTK6SoJeJ1un_PoIZkl3A-W_JYpvygK4Es1A3de96BYKx24Fc41V0dY-M7QajLtrUMrygxiyfKvR78cdUAX2uNiqUvEXGxbS3dtGss66MrDl-Yh2iQxUVnzutPBAc1JDSGb85sk9vgBVQowMiYMWYqvgh8LLZjzH51A2xZLb1nf-CzUPUmCMqemWn_Rug/s1536/RAG.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;287&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTK6SoJeJ1un_PoIZkl3A-W_JYpvygK4Es1A3de96BYKx24Fc41V0dY-M7QajLtrUMrygxiyfKvR78cdUAX2uNiqUvEXGxbS3dtGss66MrDl-Yh2iQxUVnzutPBAc1JDSGb85sk9vgBVQowMiYMWYqvgh8LLZjzH51A2xZLb1nf-CzUPUmCMqemWn_Rug/w539-h287/RAG.png&quot; width=&quot;539&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h1&gt;Introduction&lt;/h1&gt;&lt;p&gt;Large Language Models (LLMs) such as GPT, Gemini, Claude, and other generative AI models can understand questions and generate remarkably useful answers. However, an LLM has an important limitation:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;An LLM does not automatically know your organization&#39;s private, frequently changing, or newly created information.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;For example, imagine a company has:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;10,000 internal documents&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;HR policies&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Product manuals&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Customer records&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Technical documentation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Financial reports&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Support tickets&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Project documents&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Frequently changing business data&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;You could train or fine-tune a model on some of this information, but that can be expensive and does not solve the problem of constantly changing information.&lt;/p&gt;&lt;p&gt;This is where &lt;strong&gt;RAG — Retrieval-Augmented Generation&lt;/strong&gt; becomes extremely useful.&lt;/p&gt;&lt;p&gt;RAG allows an AI application to:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Receive a user&#39;s question.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Search an external knowledge source.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Retrieve the most relevant information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Give that information to an LLM.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generate an answer grounded in the retrieved information.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;In simple terms:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;RAG = Search for relevant knowledge + Give it to the LLM + Generate an answer&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;1. What is RAG?&lt;/h1&gt;&lt;p&gt;RAG stands for:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Retrieval-Augmented Generation&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;It combines two major capabilities:&lt;/p&gt;&lt;h3&gt;Retrieval&lt;/h3&gt;&lt;p&gt;Find relevant information from an external knowledge source.&lt;/p&gt;&lt;h3&gt;Generation&lt;/h3&gt;&lt;p&gt;Use an LLM to generate a natural-language answer using that retrieved information.&lt;/p&gt;&lt;p&gt;A simplified representation is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User Question
      |
      v
   Retriever
      |
      v
Relevant Documents
      |
      v
   LLM / GPT
      |
      v
Generated Answer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;p&gt;User asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;What is our company&#39;s leave policy for employees with more than 5 years of service?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The LLM itself may not know your company&#39;s policy.&lt;/p&gt;&lt;p&gt;A RAG system searches your company&#39;s HR documents, finds the relevant policy, and passes it to the LLM.&lt;/p&gt;&lt;p&gt;The LLM then answers:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;According to the company&#39;s leave policy, employees with more than five years of service are eligible for ...&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The important part is that the answer is based on &lt;strong&gt;your organization&#39;s data&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. Who Invented RAG?&lt;/h1&gt;&lt;p&gt;RAG was not created as a commercial product by a single company.&lt;/p&gt;&lt;p&gt;The term and a well-known formal RAG architecture were introduced in the research paper:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&quot;Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks&quot;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;published in 2020.&lt;/p&gt;&lt;p&gt;The paper was authored by:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Patrick Lewis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ethan Perez&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Aleksandra Piktus&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fabio Petroni&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Vladimir Karpukhin&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Naman Goyal&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Heinrich Küttler&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Mike Lewis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Wen-tau Yih&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Tim Rocktäschel&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sebastian Riedel&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Douwe Kiela&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The paper described RAG models that combine a pretrained sequence-to-sequence model with a dense vector index used as external non-parametric memory.&lt;/p&gt;&lt;p&gt;The original work was associated with the Facebook AI Research ecosystem, now part of &lt;strong&gt;Meta AI&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;However, it is important to understand that the broader idea of retrieving external knowledge and combining it with language models existed before the 2020 RAG paper. For example, Google&#39;s &lt;strong&gt;REALM&lt;/strong&gt; research also explored retrieval-augmented language modeling in 2020.&lt;/p&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;RAG is a research architecture/pattern, not a programming language or a single software product.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;3. In Which Programming Language Was RAG Developed?&lt;/h1&gt;&lt;p&gt;This is one of the most common misconceptions.&lt;/p&gt;&lt;p&gt;RAG is &lt;strong&gt;not a programming language&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;It is an &lt;strong&gt;AI architecture/pattern&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;You can implement RAG using many programming languages.&lt;/p&gt;&lt;p&gt;Common choices include:&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Language&lt;/th&gt;&lt;th&gt;Typical Usage&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Python&lt;/td&gt;&lt;td&gt;AI/ML, RAG experimentation, LangChain, LlamaIndex&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;C#&lt;/td&gt;&lt;td&gt;Enterprise .NET applications&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Java&lt;/td&gt;&lt;td&gt;Enterprise applications&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;JavaScript/TypeScript&lt;/td&gt;&lt;td&gt;Node.js applications&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Go&lt;/td&gt;&lt;td&gt;High-performance backend services&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;C++&lt;/td&gt;&lt;td&gt;High-performance AI infrastructure&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Python is particularly popular in AI research because of its extensive machine-learning ecosystem.&lt;/p&gt;&lt;p&gt;But a company building an enterprise application using:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;ASP.NET Core&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Angular&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL Server&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;can implement RAG using &lt;strong&gt;C#/.NET&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;4. Why Was RAG Needed?&lt;/h1&gt;&lt;p&gt;Traditional LLM architecture looks like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User
 |
 v
LLM
 |
 v
Answer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The model relies primarily on knowledge encoded in its parameters.&lt;/p&gt;&lt;p&gt;This creates several problems.&lt;/p&gt;&lt;h2&gt;Problem 1 — Private Data&lt;/h2&gt;&lt;p&gt;Suppose your company has:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;EmployeePolicy.pdf
ProductManual.pdf
CustomerSupport.pdf
Architecture.docx
ProjectDocumentation.pdf
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The public LLM does not automatically know these documents.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Problem 2 — Frequently Changing Data&lt;/h2&gt;&lt;p&gt;Imagine asking:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;What is today&#39;s product inventory?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The answer may change every hour.&lt;/p&gt;&lt;p&gt;You don&#39;t want to retrain an LLM every time inventory changes.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Problem 3 — Hallucination&lt;/h2&gt;&lt;p&gt;An LLM can sometimes generate information that sounds convincing but is incorrect.&lt;/p&gt;&lt;p&gt;RAG can reduce this risk by supplying relevant source information to the model.&lt;/p&gt;&lt;p&gt;However:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;RAG does not completely eliminate hallucinations.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Research continues to show that insufficient or poor-quality retrieved context can still cause incorrect answers.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. Main Purpose of RAG&lt;/h1&gt;&lt;p&gt;The primary purpose of RAG is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;To allow an LLM to use external, relevant and potentially up-to-date knowledge while generating an answer.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This provides several benefits:&lt;/p&gt;&lt;h3&gt;1. Access private information&lt;/h3&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Company HR Documents
Company Technical Documents
Company Product Documents
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;2. Access frequently changing information&lt;/h3&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Inventory
Prices
Policies
News
Tickets
Orders
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;3. Reduce hallucination&lt;/h3&gt;&lt;p&gt;The model can use retrieved evidence instead of relying entirely on its internal knowledge.&lt;/p&gt;&lt;h3&gt;4. Provide source references&lt;/h3&gt;&lt;p&gt;A well-designed RAG application can show:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Source:
Employee_Leave_Policy.pdf
Page 12
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;5. Avoid retraining for every document update&lt;/h3&gt;&lt;p&gt;Instead of retraining the LLM whenever a document changes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Update Document
      |
      v
Update Knowledge Index
      |
      v
RAG uses new information
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;6. RAG Architecture&lt;/h1&gt;&lt;p&gt;A typical RAG system looks like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                  ┌──────────────────┐
                  │     User         │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ User Question    │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Query Processing │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Embedding Model  │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Vector Database  │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Relevant Chunks  │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Prompt + Context │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │       LLM        │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Final Answer     │
                  └──────────────────┘
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. The Two Major Parts of RAG&lt;/h1&gt;&lt;p&gt;A RAG system generally has two major workflows:&lt;/p&gt;&lt;h2&gt;A. Data Ingestion&lt;/h2&gt;&lt;p&gt;This happens before users ask questions.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Documents
   |
   v
Document Extraction
   |
   v
Chunking
   |
   v
Embeddings
   |
   v
Vector Database
&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;B. Query Processing&lt;/h2&gt;&lt;p&gt;This happens when the user asks a question.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User Question
   |
   v
Embedding
   |
   v
Vector Search
   |
   v
Relevant Chunks
   |
   v
LLM
   |
   v
Answer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Understanding these two pipelines is essential for understanding RAG.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. What Is an Embedding?&lt;/h1&gt;&lt;p&gt;An embedding converts text into a numerical representation called a &lt;strong&gt;vector&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;How can I reset my password?&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;might be represented conceptually as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[0.21, -0.45, 0.73, 0.11, ...]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Real embedding vectors can contain hundreds or thousands of dimensions depending on the embedding model.&lt;/p&gt;&lt;p&gt;The important concept is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Similar meanings produce vectors that are close to each other in vector space.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;How do I change my password?&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;What is the procedure for resetting my password?&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;have different words but similar meaning.&lt;/p&gt;&lt;p&gt;Their embeddings should therefore be semantically similar.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. Why Do We Need a Vector Database?&lt;/h1&gt;&lt;p&gt;Suppose you have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1,000 documents
10,000 documents
1 million documents
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Searching all the text directly for every question can become inefficient.&lt;/p&gt;&lt;p&gt;A vector database stores embeddings and allows similarity searches.&lt;/p&gt;&lt;p&gt;Common technologies include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure AI Search&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;PostgreSQL with pgvector&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Elasticsearch&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;OpenSearch&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pinecone&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Weaviate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Milvus&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Qdrant&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Chroma&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Redis with vector search capabilities&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The exact technology depends on your architecture and requirements.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. What Is a Vector Database?&lt;/h1&gt;&lt;p&gt;A vector database stores data such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Document ID
Chunk ID
Text
Embedding
Metadata
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DocumentId:
EMP001

ChunkId:
EMP001-CHUNK-12

Text:
Employees are eligible for 20 days of annual leave...

Embedding:
[0.21, 0.52, -0.11, ...]

Metadata:
Department = HR
DocumentType = Policy
Year = 2026
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Document Chunking&lt;/h1&gt;&lt;p&gt;One of the most important steps in RAG is &lt;strong&gt;chunking&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Suppose a PDF contains 100 pages.&lt;/p&gt;&lt;p&gt;You generally should not send the entire PDF to the LLM for every question.&lt;/p&gt;&lt;p&gt;Instead, divide it into smaller pieces.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Document
   |
   +---- Chunk 1
   |
   +---- Chunk 2
   |
   +---- Chunk 3
   |
   +---- Chunk 4
   |
   +---- Chunk 5
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A chunk might contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;500–1000 tokens
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The exact size should be determined experimentally based on the document type and retrieval quality.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Chunk Overlap&lt;/h1&gt;&lt;p&gt;Sometimes important information crosses chunk boundaries.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Chunk 1:
Employees are eligible for annual leave after completing...

Chunk 2:
...one year of continuous service.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If there is no overlap, retrieval may lose context.&lt;/p&gt;&lt;p&gt;Therefore, systems may use overlapping chunks.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Chunk 1
---------------------
A B C D E F G H

Chunk 2
              E F G H I J K L
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The overlap improves the chance that related information remains together.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. Metadata&lt;/h1&gt;&lt;p&gt;Metadata is extremely important in enterprise RAG.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;documentId&quot;: &quot;HR-2026-001&quot;,
  &quot;department&quot;: &quot;HR&quot;,
  &quot;documentType&quot;: &quot;LeavePolicy&quot;,
  &quot;year&quot;: 2026,
  &quot;region&quot;: &quot;India&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Metadata allows filtering.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Search only HR documents from 2026.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Instead of searching the entire knowledge base:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Vector Search
+
Department = HR
+
Year = 2026
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is called &lt;strong&gt;metadata filtering&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. End-to-End RAG Pipeline&lt;/h1&gt;&lt;p&gt;Let&#39;s understand the complete process.&lt;/p&gt;&lt;h2&gt;Step 1 — Upload Documents&lt;/h2&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HRPolicy.pdf
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 2 — Extract Text&lt;/h2&gt;&lt;p&gt;The system extracts text from:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PDF
DOCX
TXT
HTML
Web pages
Database
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For scanned documents, OCR may be required.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Step 3 — Chunk the Text&lt;/h2&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HRPolicy.pdf

       |
       +-- Chunk 1
       +-- Chunk 2
       +-- Chunk 3
       +-- Chunk 4
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 4 — Generate Embeddings&lt;/h2&gt;&lt;p&gt;Each chunk is converted into a vector.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Chunk 1
   |
Embedding Model
   |
Vector
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 5 — Store in Vector Database&lt;/h2&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Vector
+
Text
+
Metadata
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;is stored.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;15. Query-Time Process&lt;/h1&gt;&lt;p&gt;Now the user asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;How many annual leave days can I take?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The system performs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Question
   |
   v
Embedding
   |
   v
Vector Search
   |
   v
Top Relevant Chunks
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Suppose the database returns:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Chunk 12
Chunk 27
Chunk 31
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;These are passed to the LLM.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. Prompt Augmentation&lt;/h1&gt;&lt;p&gt;The application creates a prompt similar to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;You are an HR assistant.

Answer the question using only the provided context.

Context:
--------------------
Employees are entitled to 20 days
of annual leave per calendar year.

Leave must be requested through
the employee portal.

Question:
How many annual leave days can I take?
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The LLM then generates:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Employees are entitled to 20 days
of annual leave per calendar year.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is the &lt;strong&gt;generation&lt;/strong&gt; part of RAG.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. RAG vs Traditional LLM&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Traditional LLM&lt;/th&gt;&lt;th&gt;RAG&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;General knowledge&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Private company data&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Dynamic data&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;External documents&lt;/td&gt;&lt;td&gt;Not automatically&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Knowledge updates&lt;/td&gt;&lt;td&gt;Model-dependent&lt;/td&gt;&lt;td&gt;Update knowledge source/index&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Source citations&lt;/td&gt;&lt;td&gt;Not guaranteed&lt;/td&gt;&lt;td&gt;Can be implemented&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Hallucination risk&lt;/td&gt;&lt;td&gt;Exists&lt;/td&gt;&lt;td&gt;Can be reduced&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Retraining required for every document&lt;/td&gt;&lt;td&gt;No/depends&lt;/td&gt;&lt;td&gt;Usually no&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Enterprise knowledge assistant&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Excellent fit&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;18. RAG vs Fine-Tuning&lt;/h1&gt;&lt;p&gt;This is one of the most important concepts.&lt;/p&gt;&lt;h3&gt;Fine-Tuning&lt;/h3&gt;&lt;p&gt;Fine-tuning changes model behavior/weights using training examples.&lt;/p&gt;&lt;p&gt;Useful for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Style
Behavior
Task specialization
Output format
Domain-specific behavior
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;RAG&lt;/h3&gt;&lt;p&gt;RAG provides external knowledge at query time.&lt;/p&gt;&lt;p&gt;Useful for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Private documents
Current information
Frequently changing information
Knowledge bases
Company policies
Product documentation
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A simple rule:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Use RAG to give the model knowledge.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Use fine-tuning to change how the model behaves.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Sometimes enterprises use both.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;19. Real-Time Example #1 — Company HR Assistant&lt;/h1&gt;&lt;p&gt;Imagine a company has:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Employee Handbook
Leave Policy
Travel Policy
Insurance Policy
Work From Home Policy
Salary Policy
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;An employee asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;How many work-from-home days can I take?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;RAG:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User
 |
 v
Question
 |
 v
Embedding
 |
 v
Vector Search
 |
 v
HR Documents
 |
 v
Relevant Policy
 |
 v
LLM
 |
 v
Answer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The employee doesn&#39;t need to manually search hundreds of pages.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;20. Real-Time Example #2 — Customer Support&lt;/h1&gt;&lt;p&gt;Suppose an organization sells networking equipment.&lt;/p&gt;&lt;p&gt;Documents:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Router Manual
Switch Manual
Troubleshooting Guide
Warranty Policy
Installation Guide
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Customer asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;My router is showing a red status light. What should I check?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;RAG retrieves the troubleshooting section.&lt;/p&gt;&lt;p&gt;The LLM generates a user-friendly answer based on the retrieved manual.&lt;/p&gt;&lt;p&gt;This is much better than asking the model to guess the troubleshooting procedure.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;21. Real-Time Example #3 — Banking&lt;/h1&gt;&lt;p&gt;A bank may have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Loan Policy
Credit Card Policy
Interest Rate Policy
KYC Documentation
Account Rules
Product Terms
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A customer asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;What documents are required for this loan?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;RAG retrieves the relevant policy.&lt;/p&gt;&lt;p&gt;The LLM summarizes it.&lt;/p&gt;&lt;p&gt;The application can also provide:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Source Document
Section
Page
Last Updated Date
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is particularly valuable for regulated environments.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Real-Time Example #4 — Software Development&lt;/h1&gt;&lt;p&gt;Suppose your organization has:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Architecture Documents
API Documentation
Coding Standards
Database Documentation
Microservice Documentation
Deployment Documentation
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A developer asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;How does the Customer Service communicate with the Order Service?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;RAG searches the architecture documentation.&lt;/p&gt;&lt;p&gt;It may retrieve:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer Service
      |
      v
Azure Service Bus
      |
      v
Order Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The LLM can then explain the architecture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;23. Real-Time Example #5 — E-Commerce&lt;/h1&gt;&lt;p&gt;Suppose an online store has:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Products
Prices
Inventory
Returns
Shipping Policies
Customer Orders
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Customer asks:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Can I return my order?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;RAG can retrieve the applicable return policy.&lt;/p&gt;&lt;p&gt;For dynamic information such as order status, the RAG application may also retrieve information directly from operational APIs or databases.&lt;/p&gt;&lt;p&gt;This leads to an important architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LLM
 |
 +---- Vector Search
 |
 +---- SQL Database
 |
 +---- REST API
 |
 +---- Business Services
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is often more powerful than document-only RAG.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;24. RAG With SQL Database&lt;/h1&gt;&lt;p&gt;RAG does not mean everything has to be stored in a vector database.&lt;/p&gt;&lt;p&gt;Suppose you ask:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;How many orders did customer 10025 place last month?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;A vector database is not necessarily the right tool.&lt;/p&gt;&lt;p&gt;A better architecture may be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User Question
      |
      v
Intent Detection
      |
      +------------------+
      |                  |
      v                  v
Document Search       SQL Query
      |                  |
      +--------+---------+
               |
               v
              LLM
               |
               v
            Answer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is often called a &lt;strong&gt;hybrid/agentic architecture&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;25. RAG + SQL Example&lt;/h1&gt;&lt;p&gt;Question:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;What is our return policy?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Vector Search
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Question:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;How many orders were placed yesterday?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Question:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Why was customer 12345&#39;s order delayed?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Potentially use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL
+
Order API
+
Support tickets
+
RAG
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The LLM can orchestrate the sources.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. Semantic Search vs Keyword Search&lt;/h1&gt;&lt;p&gt;Traditional search might search:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;password reset&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and look for exact words.&lt;/p&gt;&lt;p&gt;Semantic search understands meaning.&lt;/p&gt;&lt;p&gt;Question:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;I forgot my login credentials. How can I get back into my account?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;It can retrieve:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Password Reset Procedure
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;even though the exact phrase may not appear.&lt;/p&gt;&lt;p&gt;This is one of the major benefits of embeddings.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. Hybrid Search&lt;/h1&gt;&lt;p&gt;Modern enterprise RAG systems often combine:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Keyword Search
+
Vector Search
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BM25 / keyword search
        +
Semantic vector search
        |
        v
Combined Results
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Why?&lt;/p&gt;&lt;p&gt;Keyword search is excellent for exact identifiers such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;INV-2026-00125
Customer ID 10045
Error E5001
API-123
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Vector search is excellent for semantic meaning.&lt;/p&gt;&lt;p&gt;Combining both can improve retrieval quality.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;28. Reranking&lt;/h1&gt;&lt;p&gt;Retrieving the top 20 documents does not necessarily mean all 20 are equally relevant.&lt;/p&gt;&lt;p&gt;A reranker can evaluate them again.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Query
 |
 v
Retriever
 |
 v
Top 20 documents
 |
 v
Reranker
 |
 v
Top 5 documents
 |
 v
LLM
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can improve the quality of the context provided to the LLM.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;29. Basic RAG Architecture for .NET&lt;/h1&gt;&lt;p&gt;For your .NET ecosystem, an enterprise architecture could look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Angular
                       |
                       v
                 ASP.NET Core
                       |
             +---------+---------+
             |                   |
             v                   v
        RAG Service          Business APIs
             |
             v
      Embedding Service
             |
             v
       Azure AI Search
             |
             v
      Enterprise Documents
             |
             v
            LLM
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Possible Azure components include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
Azure App Service / Static Web Apps
   |
ASP.NET Core Web API
   |
Azure AI Search
   |
Azure OpenAI
   |
Blob Storage
   |
SQL Server / Azure SQL
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The exact Azure services can vary depending on the application.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;30. Simple C# RAG Flow&lt;/h1&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task&amp;lt;string&amp;gt; AskAsync(string question)
{
    var queryEmbedding =
        await embeddingService.CreateEmbeddingAsync(question);

    var documents =
        await vectorStore.SearchAsync(queryEmbedding, topK: 5);

    var context = string.Join(
        &quot;\n\n&quot;,
        documents.Select(x =&amp;gt; x.Content));

    var prompt = $&quot;&quot;&quot;
        Answer the question using only the context below.

        Context:
        {context}

        Question:
        {question}
        &quot;&quot;&quot;;

    return await llm.GenerateAsync(prompt);
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important flow is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Question
   ↓
Embedding
   ↓
Vector Search
   ↓
Relevant Documents
   ↓
Prompt
   ↓
LLM
   ↓
Answer
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;31. Document Ingestion in C#&lt;/h1&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task IndexDocumentAsync(Document document)
{
    var chunks = ChunkDocument(document.Content);

    foreach (var chunk in chunks)
    {
        var embedding =
            await embeddingService.CreateEmbeddingAsync(chunk);

        await vectorStore.AddAsync(new VectorDocument
        {
            DocumentId = document.Id,
            Content = chunk,
            Embedding = embedding,
            Metadata = document.Metadata
        });
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This creates the knowledge base.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;32. RAG Application Using Angular + .NET&lt;/h1&gt;&lt;p&gt;A practical enterprise solution could be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                Angular
                   |
                   |
              HTTP / HTTPS
                   |
                   v
          ASP.NET Core Web API
                   |
           +-------+-------+
           |               |
           v               v
      RAG Service       Auth Service
           |
     +-----+------+
     |            |
     v            v
Embedding       Vector DB
Service
     |
     v
     LLM
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Angular provides:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Chat UI
Document Upload
Source Display
Conversation History
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ASP.NET Core provides:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Authentication
Authorization
RAG orchestration
Document processing
Business logic
API endpoints
Logging
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;33. Example API&lt;/h1&gt;&lt;p&gt;A simple API could be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/rag/ask
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Request:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;question&quot;: &quot;What is the leave policy?&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Response:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;answer&quot;: &quot;Employees are eligible for annual leave...&quot;,
  &quot;sources&quot;: [
    {
      &quot;document&quot;: &quot;LeavePolicy.pdf&quot;,
      &quot;page&quot;: 12
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Angular can display:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Answer
--------------------------------
Employees are eligible for...

Sources
--------------------------------
LeavePolicy.pdf
Page 12
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;34. RAG Security&lt;/h1&gt;&lt;p&gt;Enterprise RAG must take security seriously.&lt;/p&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Employee A
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;should not access:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Employee B&#39;s salary information.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Simply storing everything in one vector index can create security problems.&lt;/p&gt;&lt;p&gt;The system should enforce:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User
 |
 v
Authentication
 |
 v
Authorization
 |
 v
Security Filter
 |
 v
Retrieval
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Metadata can help:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;department&quot;: &quot;Finance&quot;,
  &quot;classification&quot;: &quot;Confidential&quot;,
  &quot;allowedRoles&quot;: [
    &quot;FinanceManager&quot;
  ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The retrieval layer should apply appropriate authorization filters before returning context.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;35. RAG and JWT Authentication&lt;/h1&gt;&lt;p&gt;In an ASP.NET Core enterprise application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
   v
JWT
   |
   v
ASP.NET Core
   |
   v
User Claims
   |
   v
RAG Authorization
   |
   v
Filtered Retrieval
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Role = HRManager
Department = HR
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;could result in:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Department = HR
AND
UserAuthorized = true
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;during retrieval.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. RAG and Microservices&lt;/h1&gt;&lt;p&gt;RAG fits naturally into microservice architecture.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    API Gateway
                         |
          +--------------+--------------+
          |              |              |
          v              v              v
      User Service   Order Service   RAG Service
                                         |
                              +----------+----------+
                              |                     |
                              v                     v
                        Vector Search             LLM
                              |
                              v
                       Document Store
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A dedicated RAG service can own:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Document ingestion
Chunking
Embedding
Retrieval
Reranking
Prompt construction
LLM interaction
Citation generation
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;37. RAG + Azure Service Bus&lt;/h1&gt;&lt;p&gt;For large enterprise applications, document processing should not always happen synchronously.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User uploads PDF
       |
       v
Blob Storage
       |
       v
Azure Service Bus
       |
       v
Document Processing Service
       |
       v
Text Extraction
       |
       v
Chunking
       |
       v
Embedding
       |
       v
Azure AI Search
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This provides an asynchronous ingestion pipeline.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;38. RAG + Blob Storage&lt;/h1&gt;&lt;p&gt;A common Azure architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Blob Storage
                         |
                         v
                Document Processor
                         |
                    Chunking
                         |
                    Embeddings
                         |
                         v
                  Azure AI Search
                         |
                         v
                    RAG API
                         |
                         v
                    Azure OpenAI
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Documents can remain in Blob Storage while searchable chunks and metadata are stored in the search system.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;39. RAG Evaluation&lt;/h1&gt;&lt;p&gt;Building a RAG application is not just about making it work.&lt;/p&gt;&lt;p&gt;You need to measure it.&lt;/p&gt;&lt;p&gt;Important metrics include:&lt;/p&gt;&lt;h3&gt;Retrieval Precision&lt;/h3&gt;&lt;p&gt;Did the system retrieve relevant documents?&lt;/p&gt;&lt;h3&gt;Retrieval Recall&lt;/h3&gt;&lt;p&gt;Did it retrieve the information needed to answer the question?&lt;/p&gt;&lt;h3&gt;Faithfulness&lt;/h3&gt;&lt;p&gt;Does the generated answer actually follow the retrieved context?&lt;/p&gt;&lt;h3&gt;Answer Relevance&lt;/h3&gt;&lt;p&gt;Does the answer address the user&#39;s question?&lt;/p&gt;&lt;h3&gt;Latency&lt;/h3&gt;&lt;p&gt;How long does the complete request take?&lt;/p&gt;&lt;h3&gt;Cost&lt;/h3&gt;&lt;p&gt;How many embedding and LLM tokens are being consumed?&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;40. Common RAG Problems&lt;/h1&gt;&lt;h2&gt;Problem 1 — Bad Chunking&lt;/h2&gt;&lt;p&gt;If chunks are too large:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Too much irrelevant context
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If chunks are too small:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Important context may be lost
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Problem 2 — Poor Retrieval&lt;/h2&gt;&lt;p&gt;If the retriever returns irrelevant documents:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Wrong Context
     ↓
LLM
     ↓
Poor Answer
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Problem 3 — Hallucination&lt;/h2&gt;&lt;p&gt;Even with RAG, an LLM may generate information not supported by the context.&lt;/p&gt;&lt;p&gt;Therefore prompts should clearly instruct the model:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Use the provided context.

If the answer cannot be found in
the context, say that the information
is not available.
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Problem 4 — Too Much Context&lt;/h2&gt;&lt;p&gt;Sending hundreds of irrelevant chunks to the LLM can:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Increase cost
Increase latency
Reduce answer quality
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Therefore retrieval and reranking are important.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;41. Advanced RAG&lt;/h1&gt;&lt;p&gt;Basic RAG:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Question
   ↓
Vector Search
   ↓
LLM
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Advanced RAG can look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User Question
      |
      v
Query Rewriting
      |
      v
Hybrid Retrieval
      |
      v
Metadata Filtering
      |
      v
Reranking
      |
      v
Context Compression
      |
      v
LLM
      |
      v
Citation / Validation
      |
      v
Answer
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;42. Agentic RAG&lt;/h1&gt;&lt;p&gt;A newer approach is &lt;strong&gt;Agentic RAG&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Instead of performing one retrieval operation, an AI agent can determine what information it needs and use multiple tools.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User:
&quot;Why was customer 10025&#39;s order delayed?&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The agent may decide to query:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer API
       +
Order Database
       +
Support Tickets
       +
Product Documentation
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then combine the results.&lt;/p&gt;&lt;p&gt;A modern Agentic RAG system may therefore contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;              AI Agent
                  |
        +---------+---------+
        |         |         |
        v         v         v
      SQL       Search      API
        |         |         |
        +---------+---------+
                  |
                  v
                 LLM
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Recent industry research is increasingly exploring agentic RAG architectures that use planning, routing and retrieval to improve grounded responses.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;43. RAG vs Agentic RAG&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Basic RAG&lt;/th&gt;&lt;th&gt;Agentic RAG&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Retrieval&lt;/td&gt;&lt;td&gt;Usually fixed&lt;/td&gt;&lt;td&gt;Dynamic&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Decision making&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Agent-driven&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Multiple tools&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SQL/API integration&lt;/td&gt;&lt;td&gt;Possible&lt;/td&gt;&lt;td&gt;Strong&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Query planning&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Complexity&lt;/td&gt;&lt;td&gt;Lower&lt;/td&gt;&lt;td&gt;Higher&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Cost&lt;/td&gt;&lt;td&gt;Lower&lt;/td&gt;&lt;td&gt;Potentially higher&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Enterprise workflows&lt;/td&gt;&lt;td&gt;Good&lt;/td&gt;&lt;td&gt;Excellent for complex workflows&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;44. RAG Security Architecture&lt;/h1&gt;&lt;p&gt;For enterprise applications:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    User
                     |
                     v
              Authentication
                     |
                     v
              Authorization
                     |
                     v
               RAG API
                     |
              Security Filter
                     |
                     v
               Retrieval
                     |
                     v
                   LLM
                     |
                     v
             Output Validation
                     |
                     v
                  User
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Important controls include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Authentication
Authorization
Tenant isolation
Document-level permissions
Metadata filtering
Encryption
Audit logging
PII protection
Prompt-injection defenses
Output validation
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;45. Multi-Tenant RAG&lt;/h1&gt;&lt;p&gt;Consider a SaaS application with:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Company A
Company B
Company C
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The system must prevent:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Company A → Company B documents
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A common approach is to include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;TenantId
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;in document metadata.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;tenantId&quot;: &quot;COMPANY-A&quot;,
  &quot;documentId&quot;: &quot;DOC-1001&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;At query time:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;WHERE TenantId = CurrentUser.TenantId
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is critical for enterprise SaaS systems.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;46. RAG Cost Optimization&lt;/h1&gt;&lt;p&gt;RAG does not automatically mean low cost.&lt;/p&gt;&lt;p&gt;Costs may come from:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Embedding generation
Vector search
LLM input tokens
LLM output tokens
Storage
Document processing
OCR
Reranking
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Optimization techniques include:&lt;/p&gt;&lt;h3&gt;1. Good chunking&lt;/h3&gt;&lt;p&gt;Avoid unnecessary context.&lt;/p&gt;&lt;h3&gt;2. Top-K optimization&lt;/h3&gt;&lt;p&gt;Don&#39;t retrieve 100 chunks when 5 are enough.&lt;/p&gt;&lt;h3&gt;3. Reranking&lt;/h3&gt;&lt;p&gt;Retrieve candidates first, then select the best ones.&lt;/p&gt;&lt;h3&gt;4. Cache embeddings&lt;/h3&gt;&lt;p&gt;Don&#39;t regenerate embeddings unnecessarily.&lt;/p&gt;&lt;h3&gt;5. Cache frequent questions&lt;/h3&gt;&lt;p&gt;For repeated queries, response caching may help.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;47. RAG Complete Architecture for an Enterprise .NET Application&lt;/h1&gt;&lt;p&gt;A production architecture could look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Angular
                            |
                            v
                     API Management
                            |
                            v
                    ASP.NET Core API
                            |
                    +-------+-------+
                    |               |
                    v               v
                RAG Service     Business APIs
                    |
         +----------+----------+
         |          |           |
         v          v           v
     Embedding   Search      SQL/API
      Service     Index
         |          |
         |          v
         |      Vector Search
         |          |
         +----------+
                    |
                    v
                   LLM
                    |
                    v
              Answer + Sources
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Document ingestion:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User/Admin
    |
    v
Blob Storage
    |
    v
Service Bus
    |
    v
Document Processor
    |
    v
Text Extraction
    |
    v
Chunking
    |
    v
Embedding
    |
    v
Search Index
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;48. Recommended Technology Stack for a .NET Developer&lt;/h1&gt;&lt;p&gt;For an enterprise .NET developer, one possible stack is:&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Layer&lt;/th&gt;&lt;th&gt;Technology&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Frontend&lt;/td&gt;&lt;td&gt;Angular&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Backend&lt;/td&gt;&lt;td&gt;ASP.NET Core&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Authentication&lt;/td&gt;&lt;td&gt;Microsoft Entra ID / OAuth/OIDC&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;LLM&lt;/td&gt;&lt;td&gt;Azure OpenAI or another LLM provider&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Search&lt;/td&gt;&lt;td&gt;Azure AI Search&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Document Storage&lt;/td&gt;&lt;td&gt;Azure Blob Storage&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Database&lt;/td&gt;&lt;td&gt;Azure SQL&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Messaging&lt;/td&gt;&lt;td&gt;Azure Service Bus&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Monitoring&lt;/td&gt;&lt;td&gt;Application Insights / Azure Monitor&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Secrets&lt;/td&gt;&lt;td&gt;Azure Key Vault&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;API Gateway&lt;/td&gt;&lt;td&gt;Azure API Management&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Containerization&lt;/td&gt;&lt;td&gt;Docker&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Orchestration&lt;/td&gt;&lt;td&gt;AKS&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CI/CD&lt;/td&gt;&lt;td&gt;Azure DevOps&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Embeddings&lt;/td&gt;&lt;td&gt;Embedding model&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Vector Store&lt;/td&gt;&lt;td&gt;Azure AI Search / another vector-capable store&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;This is particularly suitable for organizations already invested in Microsoft technologies.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;49. RAG Request Flow&lt;/h1&gt;&lt;p&gt;Let&#39;s follow one request from beginning to end.&lt;/p&gt;&lt;p&gt;User asks:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;What is our refund policy?&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 1&lt;/h3&gt;&lt;p&gt;Angular sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/rag/ask
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 2&lt;/h3&gt;&lt;p&gt;ASP.NET Core authenticates the user.&lt;/p&gt;&lt;h3&gt;Step 3&lt;/h3&gt;&lt;p&gt;RAG service creates an embedding.&lt;/p&gt;&lt;h3&gt;Step 4&lt;/h3&gt;&lt;p&gt;Search system performs semantic/hybrid search.&lt;/p&gt;&lt;h3&gt;Step 5&lt;/h3&gt;&lt;p&gt;Relevant documents are retrieved.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;RefundPolicy.pdf
Section 4
Section 7
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 6&lt;/h3&gt;&lt;p&gt;Reranker selects the best chunks.&lt;/p&gt;&lt;h3&gt;Step 7&lt;/h3&gt;&lt;p&gt;Application constructs the prompt.&lt;/p&gt;&lt;h3&gt;Step 8&lt;/h3&gt;&lt;p&gt;LLM generates the answer.&lt;/p&gt;&lt;h3&gt;Step 9&lt;/h3&gt;&lt;p&gt;Application returns:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;answer&quot;: &quot;Customers can request a refund within...&quot;,
  &quot;sources&quot;: [
    {
      &quot;document&quot;: &quot;RefundPolicy.pdf&quot;,
      &quot;section&quot;: &quot;4&quot;
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 10&lt;/h3&gt;&lt;p&gt;Angular displays the answer and sources.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;50. Is RAG a Replacement for an LLM?&lt;/h1&gt;&lt;p&gt;No.&lt;/p&gt;&lt;p&gt;RAG normally works &lt;strong&gt;with&lt;/strong&gt; an LLM.&lt;/p&gt;&lt;p&gt;Think of the responsibilities like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Vector Search
     |
     | Finds information
     v
Relevant Context
     |
     | Gives context
     v
LLM
     |
     | Understands and generates
     v
Human-readable Answer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The vector database does not replace the LLM.&lt;/p&gt;&lt;p&gt;The LLM does not replace the search engine.&lt;/p&gt;&lt;p&gt;They work together.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;51. Is RAG the Same as ChatGPT?&lt;/h1&gt;&lt;p&gt;No.&lt;/p&gt;&lt;p&gt;ChatGPT is an AI application/service that can use LLMs and various tools.&lt;/p&gt;&lt;p&gt;RAG is an architectural pattern.&lt;/p&gt;&lt;p&gt;A developer can build:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Custom RAG Application
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core
+
Vector Database
+
Embedding Model
+
LLM
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;52. When Should You Use RAG?&lt;/h1&gt;&lt;p&gt;RAG is a strong choice when:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;You have private documents
        OR
You have frequently changing information
        OR
You need source-grounded answers
        OR
You need enterprise knowledge search
        OR
You need natural-language access to documentation
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;HR Assistant
Customer Support Assistant
Legal Document Search
Technical Documentation Assistant
Product Assistant
Knowledge Management
Research Assistant
Enterprise Search
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;53. When RAG May Not Be the Best Solution&lt;/h1&gt;&lt;p&gt;Don&#39;t automatically use RAG for everything.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Calculate 125 × 75.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;You don&#39;t need document retrieval.&lt;/p&gt;&lt;p&gt;Similarly:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Sort this list.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;RAG isn&#39;t necessary.&lt;/p&gt;&lt;p&gt;For structured business data:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL
API
Business Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;may be more appropriate.&lt;/p&gt;&lt;p&gt;The best enterprise architecture often combines:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LLM
+
RAG
+
SQL
+
APIs
+
Business Services
+
Tools
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;54. RAG vs Search Engine&lt;/h1&gt;&lt;p&gt;Traditional search:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Question
   |
   v
Search Engine
   |
   v
10 Results
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;RAG:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Question
   |
   v
Search
   |
   v
Relevant Documents
   |
   v
LLM
   |
   v
Natural Language Answer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Traditional search gives you documents.&lt;/p&gt;&lt;p&gt;RAG can &lt;strong&gt;understand the retrieved information and synthesize an answer&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;55. RAG vs Database&lt;/h1&gt;&lt;p&gt;A database is designed primarily for structured data.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CustomerId
Name
OrderId
OrderDate
Amount
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;RAG is especially useful for unstructured/semi-structured knowledge such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PDFs
Manuals
Policies
Documentation
Emails
Knowledge articles
Text
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Enterprise systems often use both.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;56. Golden Rule for RAG&lt;/h1&gt;&lt;p&gt;A very useful way to remember RAG is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LLM = Brain

Embedding Model = Meaning Representation

Vector Database = Memory/Search

Retriever = Finds Memory

Prompt = Instructions

RAG = Brain + External Memory
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is only an analogy, but it makes the architecture easier to understand.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;57. The Future of RAG&lt;/h1&gt;&lt;p&gt;RAG is evolving beyond simple:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Search → Prompt → LLM
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Modern systems increasingly explore:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Query Planning
+
Hybrid Search
+
Reranking
+
Knowledge Graphs
+
Multimodal Retrieval
+
Agentic Workflows
+
Tool Calling
+
SQL
+
APIs
+
Validation
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Research is also exploring techniques for improving RAG efficiency and answer quality, including systems that use multiple retrieved document subsets and verification stages.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;58. Complete RAG Mental Model&lt;/h1&gt;&lt;p&gt;Remember this architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 ┌─────────────────┐
                 │      USER       │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │     QUESTION    │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │ QUERY PROCESSOR │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │   EMBEDDING     │
                 └────────┬────────┘
                          |
                          v
              ┌───────────────────────┐
              │ VECTOR / HYBRID SEARCH│
              └───────────┬───────────┘
                          |
                          v
                 ┌─────────────────┐
                 │    RERANKER     │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │ RELEVANT CONTEXT│
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │       LLM       │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │ ANSWER + SOURCE │
                 └─────────────────┘
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;59. Key Takeaways&lt;/h1&gt;&lt;p&gt;The most important points are:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;RAG stands for Retrieval-Augmented Generation.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;RAG is an architecture/pattern, not a programming language.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The well-known RAG architecture was introduced in a 2020 research paper by Patrick Lewis and collaborators.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;RAG combines:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Retrieval + LLM Generation
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Embeddings convert text into vectors representing semantic meaning.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Vector databases/search engines allow semantic retrieval.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Documents should normally be split into chunks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Metadata is extremely important for filtering and security.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;RAG can use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PDFs
DOCX
Websites
Databases
APIs
Knowledge Bases
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;RAG can reduce hallucination but &lt;strong&gt;cannot guarantee that every answer is correct&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fine-tuning and RAG solve different problems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;RAG is highly useful for enterprise applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;.NET developers can build RAG applications using:&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
+
ASP.NET Core
+
Embedding Model
+
Vector Search
+
LLM
+
SQL
+
Azure Services
&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&quot;14&quot;&gt;&lt;li&gt;&lt;p&gt;Advanced RAG can include:&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Hybrid Search
Reranking
Metadata Filtering
Query Rewriting
Context Compression
Agentic Workflows
SQL
APIs
Knowledge Graphs
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;60. Final Conclusion&lt;/h1&gt;&lt;p&gt;RAG is one of the most important architectural patterns for building practical enterprise generative-AI applications.&lt;/p&gt;&lt;p&gt;An LLM provides the &lt;strong&gt;reasoning and language-generation capability&lt;/strong&gt;, while RAG provides a mechanism for accessing &lt;strong&gt;external knowledge&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;The basic concept is simple:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             Traditional LLM

Question ──────────&amp;gt; LLM ──────────&amp;gt; Answer


             RAG Application

Question
   |
   v
Retrieve Knowledge
   |
   v
Relevant Context
   |
   v
LLM
   |
   v
Grounded Answer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The real power appears when RAG is combined with enterprise technologies:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   +
ASP.NET Core
   +
Azure OpenAI
   +
Azure AI Search
   +
Azure SQL
   +
Blob Storage
   +
Azure Service Bus
   +
API Management
   +
Key Vault
   +
Application Insights
   +
Docker / AKS
   +
Azure DevOps
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This combination allows developers to build practical systems such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Enterprise Knowledge Assistant
Customer Support AI
HR Assistant
Technical Documentation Assistant
Product Assistant
Financial Document Assistant
Legal Document Search
Developer Copilot
Enterprise Search
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The key idea to remember is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;RAG does not teach an LLM everything permanently. Instead, it retrieves the right information at the right time and gives that information to the LLM so it can generate a more relevant, grounded response.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;That makes RAG one of the most useful bridges between &lt;strong&gt;traditional enterprise data and modern Generative AI&lt;/strong&gt;.&lt;/p&gt;&lt;h2&gt;References&lt;/h2&gt;&lt;p&gt;The original RAG research paper is available on arXiv: &lt;a href=&quot;https://arxiv.org/abs/2005.11401?utm_source=chatgpt.com&quot;&gt;Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Google&#39;s research on REALM provides useful background on retrieval-augmented language modeling and explicit external knowledge retrieval.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/4164376258199362699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/4164376258199362699' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/4164376258199362699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/4164376258199362699'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/retrieval-augmented-generation-rag.html' title='Retrieval-Augmented Generation (RAG): Complete Guide with Architecture, Real-Time Examples and .NET Implementation'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTK6SoJeJ1un_PoIZkl3A-W_JYpvygK4Es1A3de96BYKx24Fc41V0dY-M7QajLtrUMrygxiyfKvR78cdUAX2uNiqUvEXGxbS3dtGss66MrDl-Yh2iQxUVnzutPBAc1JDSGb85sk9vgBVQowMiYMWYqvgh8LLZjzH51A2xZLb1nf-CzUPUmCMqemWn_Rug/s72-w539-h287-c/RAG.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-7325766443467623134</id><published>2026-08-16T08:27:37.755+05:30</published><updated>2026-08-16T08:27:37.755+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ACR and AKS"/><category scheme="http://www.blogger.com/atom/ns#" term="Azure DevOps"/><category scheme="http://www.blogger.com/atom/ns#" term="Docker"/><title type='text'>Complete CI/CD Pipeline for .NET 9 Microservices on Azure Using Azure DevOps, Docker, ACR and AKS</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkHx29FvBtFFOTDXc94kqtUZYO3YG0OesJmZiPN8DsM3ORbeyhP8mlEJrnotHpo0F8sUg3vm62pZ9Z4Z-sIax1DI13YBNc-pd1_7pXBLyNrYLeNHhA1pBHMSQWRJuP7DHzjUkwePox9eIANbBbeLQr0c0CrMtAzuEUJ0__nTVwrikchMHnVVndPU_0EFs/s1536/CiCDPipeline.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;279&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkHx29FvBtFFOTDXc94kqtUZYO3YG0OesJmZiPN8DsM3ORbeyhP8mlEJrnotHpo0F8sUg3vm62pZ9Z4Z-sIax1DI13YBNc-pd1_7pXBLyNrYLeNHhA1pBHMSQWRJuP7DHzjUkwePox9eIANbBbeLQr0c0CrMtAzuEUJ0__nTVwrikchMHnVVndPU_0EFs/w507-h279/CiCDPipeline.png&quot; width=&quot;507&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;h1&gt;Complete CI/CD Pipeline for .NET 9 Microservices on Azure Using Azure DevOps, Docker, ACR and AKS&lt;/h1&gt;&lt;h2&gt;Introduction&lt;/h2&gt;&lt;p&gt;Modern enterprise applications require a reliable and automated process for building, testing, packaging, and deploying applications across multiple environments.&lt;/p&gt;&lt;p&gt;In a typical microservices-based application, developers continuously make changes to individual services. Manually building and deploying these services is time-consuming and error-prone.&lt;/p&gt;&lt;p&gt;This is where &lt;strong&gt;CI/CD — Continuous Integration and Continuous Delivery/Deployment&lt;/strong&gt; — becomes extremely important.&lt;/p&gt;&lt;p&gt;In this article, we will build a complete CI/CD pipeline for the following enterprise architecture:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Angular Web Application&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;.NET 9 Web API / Microservices&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Docker&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Container Registry (ACR)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Kubernetes Service (AKS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure SQL Database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Service Bus&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure DevOps&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kubernetes Ingress&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DEV, QA, UAT and PRODUCTION environments&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We will specifically use the &lt;strong&gt;Azure DevOps Classic/Visual UI approach&lt;/strong&gt;, so you can understand how to configure the pipeline directly through the Azure DevOps portal without initially writing an &lt;code inline=&quot;&quot;&gt;azure-pipelines.yml&lt;/code&gt; file.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Microsoft recommends YAML pipelines for new development, but Classic pipelines remain useful for understanding the Azure DevOps pipeline concepts and for organizations that still use the Classic UI.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;1. What Are We Going to Build?&lt;/h1&gt;&lt;p&gt;The overall CI/CD architecture will look like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer
    |
    | Git Push
    v
Azure Repos
    |
    v
+-----------------------------+
|       CI / Build Pipeline   |
|                             |
|  1. Restore                 |
|  2. Build                   |
|  3. Unit Test               |
|  4. Publish                 |
|  5. Docker Build            |
|  6. Docker Push             |
+-------------+---------------+
              |
              v
      Azure Container Registry
              |
              | Docker Image
              v
+-----------------------------+
|      CD / Release Pipeline  |
|                             |
|       DEV                   |
|         |                   |
|         v                   |
|       QA                    |
|         |                   |
|         v                   |
|       UAT                   |
|         |                   |
|     Approval                |
|         |                   |
|         v                   |
|     PRODUCTION              |
+-------------+---------------+
              |
              v
             AKS
              |
       +------+------+
       |      |      |
       v      v      v
    Order  Customer Product
     API     API     API
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The basic principle is:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Code → Build → Test → Docker Image → ACR → Deploy → AKS&lt;/strong&gt;&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. Prerequisites&lt;/h1&gt;&lt;p&gt;Before creating the pipeline, we need several Azure and Azure DevOps resources.&lt;/p&gt;&lt;h2&gt;Azure Resources&lt;/h2&gt;&lt;p&gt;You should have:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Subscription&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Resource Group&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Container Registry&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Kubernetes Service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure SQL Database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Service Bus&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Monitor / Application Insights&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Azure DevOps&lt;/h2&gt;&lt;p&gt;You should have:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure DevOps Organization&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure DevOps Project&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Repos&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pipeline permissions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Microsoft-hosted agent capability&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Microsoft-hosted agents are suitable for many standard .NET builds. Self-hosted agents can be used when an organization requires custom tooling or private-network access.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Example Enterprise Application&lt;/h1&gt;&lt;p&gt;Let&#39;s assume our solution has the following structure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;EnterpriseApp
│
├── EnterpriseApp.sln
│
├── src
│   ├── CustomerService
│   │   └── CustomerService.csproj
│   │
│   ├── OrderService
│   │   └── OrderService.csproj
│   │
│   └── ProductService
│       └── ProductService.csproj
│
├── tests
│   └── OrderService.Tests
│
├── Dockerfile
│
└── k8s
    ├── namespace.yaml
    ├── order-deployment.yaml
    ├── order-service.yaml
    ├── customer-deployment.yaml
    ├── customer-service.yaml
    └── ingress.yaml
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For our first example, we will deploy:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderService
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Once the process is understood, the same approach can be applied to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;CustomerService&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ProductService&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;InventoryService&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;PaymentService&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;NotificationService&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Other microservices&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;4. Step 1 — Create an Azure DevOps Project&lt;/h1&gt;&lt;p&gt;Open your Azure DevOps organization and create a project.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Organization
    |
    └── EnterpriseProject
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Inside the project, Azure DevOps provides services such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Boards
Repos
Pipelines
Test Plans
Artifacts
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For our CI/CD implementation, the most important areas are:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Repos
Pipelines
Project Settings
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;5. Step 2 — Add Source Code to Azure Repos&lt;/h1&gt;&lt;p&gt;Navigate to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Repos
    |
    └── Files
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create or import your Git repository.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;EnterpriseApp
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The repository might contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;EnterpriseApp.sln

src/
    CustomerService/
    OrderService/
    ProductService/

tests/
    OrderService.Tests/

Dockerfile

k8s/
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Developers can then work with the repository using Git:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git clone &amp;lt;repository&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After making changes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git add .
git commit -m &quot;Update order validation&quot;
git push
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This Git push can eventually trigger the CI pipeline automatically.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. Step 3 — Create Azure Container Registry&lt;/h1&gt;&lt;p&gt;The Azure Container Registry (ACR) stores the Docker images generated by the CI pipeline.&lt;/p&gt;&lt;p&gt;In the Azure Portal:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Create a resource
        ↓
Container Registry
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Registry Name:
enterpriseacr
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The registry endpoint could be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;enterpriseacr.azurecr.io
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Our Docker image can then be tagged as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;enterpriseacr.azurecr.io/order-service:1.0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or, preferably, with a unique build number:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;enterpriseacr.azurecr.io/order-service:1234
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using a unique build identifier makes it easier to identify exactly which source version produced a container image.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;7. Step 4 — Create Azure Kubernetes Service&lt;/h1&gt;&lt;p&gt;Create an AKS cluster from the Azure Portal or Azure CLI.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;EnterpriseAKS
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;An AKS cluster contains:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;AKS Cluster
    |
    ├── Node Pools
    |
    ├── Kubernetes Control Plane
    |
    └── Workloads
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After connecting your local environment to the cluster, you can verify the nodes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;kubectl get nodes
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;8. Step 5 — Connect ACR with AKS&lt;/h1&gt;&lt;p&gt;AKS needs permission to pull Docker images from Azure Container Registry.&lt;/p&gt;&lt;p&gt;A common Azure CLI approach is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az aks update \
  --resource-group EnterpriseRG \
  --name EnterpriseAKS \
  --attach-acr enterpriseacr
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The relationship becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Container Registry
          |
          | Pull Docker Image
          v
         AKS
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is important because the CI pipeline pushes the image into ACR, while AKS pulls that image when deploying the application.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. Step 6 — Create Azure DevOps Service Connection&lt;/h1&gt;&lt;p&gt;Azure DevOps needs permission to access Azure resources.&lt;/p&gt;&lt;p&gt;Navigate to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure DevOps
    ↓
Project Settings
    ↓
Service connections
    ↓
New service connection
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Resource Manager
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure the connection according to your organization&#39;s authentication and security requirements.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Service Connection Name:

Azure-Enterprise-Connection
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure DevOps
       |
       | Service Connection
       v
Azure Subscription
       |
       +---- ACR
       +---- AKS
       +---- Other Azure Resources
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Service connections are a critical security boundary, so they should be granted only the permissions required by the pipeline.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;10. Step 7 — Create the CI Build Pipeline&lt;/h1&gt;&lt;p&gt;Now we can create the Continuous Integration pipeline.&lt;/p&gt;&lt;p&gt;Navigate to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pipelines
    ↓
Builds
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Depending on your Azure DevOps UI, select the option to create a new pipeline and choose the &lt;strong&gt;Classic editor&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;The Classic editor allows you to configure the build process using the Azure DevOps UI rather than writing YAML.&lt;/p&gt;&lt;p&gt;Select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Repos Git
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Project:
EnterpriseProject

Repository:
EnterpriseApp

Branch:
main
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Click:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Continue
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Step 8 — Select Empty Job&lt;/h1&gt;&lt;p&gt;Instead of allowing Azure DevOps to automatically create all the tasks, select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Empty Job
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You should now see something similar to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Agent Job 1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This approach is useful when learning CI/CD because you can understand each pipeline task individually.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Step 9 — Configure the Build Agent&lt;/h1&gt;&lt;p&gt;Select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Agent Job 1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Choose an agent specification.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ubuntu-latest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;windows-latest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For Docker and Linux-based containers, Ubuntu is commonly convenient.&lt;/p&gt;&lt;p&gt;Our pipeline now starts with:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Agent Job
     |
     v
Use .NET SDK
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;13. Step 10 — Install / Select .NET SDK&lt;/h1&gt;&lt;p&gt;Add a task:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;+
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Search for the .NET SDK task.&lt;/p&gt;&lt;p&gt;Configure the required .NET version.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SDK Version:

9.x
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This ensures that the build agent uses the expected .NET SDK version.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. Step 11 — Restore NuGet Packages&lt;/h1&gt;&lt;p&gt;Add a .NET Core task.&lt;/p&gt;&lt;p&gt;Configure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Command:

restore
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Path to project:

EnterpriseApp.sln
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The pipeline becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Use .NET SDK
      |
      v
Restore
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This downloads the NuGet dependencies required by the solution.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;15. Step 12 — Build the Application&lt;/h1&gt;&lt;p&gt;Add another .NET task.&lt;/p&gt;&lt;p&gt;Configure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Command:

build
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;EnterpriseApp.sln
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Arguments:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;--configuration Release --no-restore
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The pipeline is now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Use .NET SDK
      |
      v
Restore
      |
      v
Build
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The equivalent .NET CLI operation is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet build EnterpriseApp.sln \
    --configuration Release \
    --no-restore
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;16. Step 13 — Execute Unit Tests&lt;/h1&gt;&lt;p&gt;Add another .NET task.&lt;/p&gt;&lt;p&gt;Configure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Command:

test
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;tests/**/*.csproj
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Arguments:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;--configuration Release --no-build
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The pipeline becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Restore
   |
   v
Build
   |
   v
Unit Tests
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If the unit tests fail:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Build ❌
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;the pipeline should stop.&lt;/p&gt;&lt;p&gt;This is an important CI principle:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Code should not progress toward deployment if automated tests are failing.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;17. Step 14 — Publish the .NET Application&lt;/h1&gt;&lt;p&gt;Add another .NET task.&lt;/p&gt;&lt;p&gt;Configure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Command:

publish
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Project:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;src/OrderService/OrderService.csproj
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configuration:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Release
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Output:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;$(Build.ArtifactStagingDirectory)/order-service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The flow becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Build
  |
  v
Test
  |
  v
Publish
  |
  v
Build Artifact
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;18. Step 15 — Build the Docker Image&lt;/h1&gt;&lt;p&gt;Now we move from application build to containerization.&lt;/p&gt;&lt;p&gt;Add a Docker task.&lt;/p&gt;&lt;p&gt;Select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Docker
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Command:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Build
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure the Azure Container Registry connection.&lt;/p&gt;&lt;p&gt;Repository:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;order-service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Dockerfile:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;$(Build.SourcesDirectory)/src/OrderService/Dockerfile
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Tag:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;$(Build.BuildId)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The resulting image could be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;enterpriseacr.azurecr.io/order-service:1234
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;19. Step 16 — Push Docker Image to ACR&lt;/h1&gt;&lt;p&gt;Add another Docker task.&lt;/p&gt;&lt;p&gt;Select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Docker
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Command:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Push
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Repository:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;order-service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Tag:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;$(Build.BuildId)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The CI process is now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Git Push
    |
    v
Restore
    |
    v
Build
    |
    v
Unit Test
    |
    v
Publish
    |
    v
Docker Build
    |
    v
Docker Push
    |
    v
Azure Container Registry
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is the core Continuous Integration workflow.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;20. Step 17 — Save and Run the CI Pipeline&lt;/h1&gt;&lt;p&gt;Save the pipeline with a name such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CI-OrderService
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Save &amp;amp; Queue
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Run the pipeline.&lt;/p&gt;&lt;p&gt;You should see tasks such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;✔ Restore
✔ Build
✔ Unit Test
✔ Publish
✔ Docker Build
✔ Docker Push
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If everything succeeds:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;BUILD SUCCESSFUL
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;21. Step 18 — Verify the Docker Image in ACR&lt;/h1&gt;&lt;p&gt;Open:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Portal
    ↓
Container Registry
    ↓
Repositories
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You should see:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;order-service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Inside the repository:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;order-service
    |
    └── 1234
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The tag &lt;code inline=&quot;&quot;&gt;1234&lt;/code&gt; represents the pipeline build number.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. Step 19 — Create the CD / Release Pipeline&lt;/h1&gt;&lt;p&gt;The next step is Continuous Delivery/Deployment.&lt;/p&gt;&lt;p&gt;In the Classic pipeline model, the release pipeline is separate from the build pipeline.&lt;/p&gt;&lt;p&gt;Navigate to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pipelines
    ↓
Releases
    ↓
New pipeline
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Empty Job
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Rename the first stage:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DEV
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A typical enterprise release pipeline can contain:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DEV
  |
  v
QA
  |
  v
UAT
  |
  v
PRODUCTION
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;23. Step 20 — Configure the Release Artifact&lt;/h1&gt;&lt;p&gt;Add the output from the CI/build process as the release artifact.&lt;/p&gt;&lt;p&gt;For containerized applications, the key deployment input is the Docker image and its version/tag stored in ACR.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CI Pipeline
     |
     v
Docker Image
     |
     v
ACR
     |
     v
Release Pipeline
     |
     v
AKS
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;24. Step 21 — Configure DEV Deployment&lt;/h1&gt;&lt;p&gt;Open the &lt;code inline=&quot;&quot;&gt;DEV&lt;/code&gt; stage.&lt;/p&gt;&lt;p&gt;Add a Kubernetes deployment task.&lt;/p&gt;&lt;p&gt;Configure the Azure connection:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Connection Type:

Azure Resource Manager
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Select:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Subscription:

Azure-Enterprise-Connection
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then select the AKS cluster:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;EnterpriseAKS
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use a namespace such as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;dev
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This allows the same AKS cluster to host workloads for multiple environments when that is appropriate for the organization&#39;s architecture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;25. Kubernetes Deployment&lt;/h1&gt;&lt;p&gt;A simplified Kubernetes Deployment might look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: apps/v1
kind: Deployment

metadata:
  name: order-service

spec:
  replicas: 3

  selector:
    matchLabels:
      app: order-service

  template:
    metadata:
      labels:
        app: order-service

    spec:
      containers:
        - name: order-service

          image: enterpriseacr.azurecr.io/order-service:1234

          ports:
            - containerPort: 8080
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important part is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;image: enterpriseacr.azurecr.io/order-service:1234
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When a new version is released, the image tag changes.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Old:

order-service:1233
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;New:

order-service:1234
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Kubernetes then performs a rollout to replace the old application version with the new one.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. DEV Deployment Flow&lt;/h1&gt;&lt;p&gt;The deployment now looks like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ACR
 |
 | order-service:1234
 v
AKS
 |
 v
DEV Namespace
 |
 +---- Pod 1
 |
 +---- Pod 2
 |
 +---- Pod 3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Running multiple replicas provides application redundancy and enables Kubernetes to distribute traffic across available Pods.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. Step 22 — Create QA Stage&lt;/h1&gt;&lt;p&gt;Add another stage:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;QA
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure the deployment to target:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;QA
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and use the appropriate Kubernetes namespace:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;qa
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The pipeline becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DEV
 |
 v
QA
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure the QA stage to execute after successful DEV deployment.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;28. Step 23 — Create UAT Stage&lt;/h1&gt;&lt;p&gt;Create another stage:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;UAT
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The release flow becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DEV
 |
 v
QA
 |
 v
UAT
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;UAT is generally used for business/user acceptance validation before production.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;29. Step 24 — Create Production Stage&lt;/h1&gt;&lt;p&gt;Create the final stage:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PRODUCTION
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The complete release flow is now:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DEV
 |
 v
QA
 |
 v
UAT
 |
 v
PRODUCTION
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;30. Step 25 — Add Production Approval&lt;/h1&gt;&lt;p&gt;Production deployments should normally have appropriate controls.&lt;/p&gt;&lt;p&gt;Instead of allowing:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer
   |
   v
DEV
   |
   v
QA
   |
   v
UAT
   |
   v
PRODUCTION
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;without any control, introduce an approval gate:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;DEV
 |
 v
QA
 |
 v
UAT
 |
 v
+----------------------+
| Production Approval  |
|                      |
| Lead / Manager       |
+----------+-----------+
           |
           v
      PRODUCTION
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the Classic Release pipeline, configure:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;PRODUCTION
    ↓
Pre-deployment conditions
    ↓
Pre-deployment approvals
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Add the authorized reviewers according to your organization&#39;s release-management process.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;31. Complete CI/CD Architecture&lt;/h1&gt;&lt;p&gt;The complete architecture now looks like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         DEVELOPER
                             |
                             | Git Push
                             v
                      +--------------+
                      | Azure Repos  |
                      +------+-------+
                             |
                             v
                  +----------------------+
                  |    CI / BUILD        |
                  |                      |
                  | Restore              |
                  | Build                |
                  | Unit Test            |
                  | Publish              |
                  | Docker Build         |
                  | Docker Push          |
                  +----------+-----------+
                             |
                             v
                  +----------------------+
                  | Azure Container      |
                  | Registry (ACR)       |
                  +----------+-----------+
                             |
                             v
                  +----------------------+
                  |    CD / RELEASE      |
                  +----------+-----------+
                             |
                             v
                        +---------+
                        |   DEV   |
                        +----+----+
                             |
                             v
                        +---------+
                        |   QA    |
                        +----+----+
                             |
                             v
                        +---------+
                        |   UAT   |
                        +----+----+
                             |
                          Approval
                             |
                             v
                     +---------------+
                     | PRODUCTION    |
                     +-------+-------+
                             |
                             v
                            AKS
                             |
             +---------------+---------------+
             |               |               |
             v               v               v
        Customer API    Order API       Product API
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;32. Where Does Ingress Fit?&lt;/h1&gt;&lt;p&gt;Ingress is part of the Kubernetes application architecture. It is not a replacement for Azure DevOps.&lt;/p&gt;&lt;p&gt;A typical AKS architecture can look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Internet
                            |
                            v
                     +--------------+
                     |    Ingress   |
                     |   / Gateway  |
                     +------+-------+
                            |
              +-------------+-------------+
              |             |             |
              v             v             v
        Customer API    Order API    Product API
              |             |             |
              v             v             v
            Pods          Pods          Pods
              |             |             |
              +-------------+-------------+
                            |
                   +--------+--------+
                   |                 |
                   v                 v
              Azure SQL       Azure Service Bus
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important distinction is:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Azure DevOps automates application delivery.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Kubernetes/AKS runs the application.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Ingress/Gateway manages incoming application traffic.&lt;/strong&gt;&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;33. Where Do Azure SQL and Azure Service Bus Fit?&lt;/h1&gt;&lt;p&gt;Azure SQL and Azure Service Bus are generally infrastructure dependencies rather than resources that should be recreated every time the application pipeline runs.&lt;/p&gt;&lt;p&gt;A typical environment contains:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Infrastructure
    |
    +── AKS
    |
    +── ACR
    |
    +── Azure SQL
    |
    +── Azure Service Bus
    |
    +── Key Vault
    |
    +── Monitoring
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The CI/CD pipeline then deploys the application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;CI/CD
   |
   v
AKS
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application can communicate with:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
    |
    +---- Azure SQL
    |
    +---- Azure Service Bus
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;34. Managing Secrets&lt;/h1&gt;&lt;p&gt;Sensitive information should never be hardcoded into:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Source code&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dockerfiles&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kubernetes manifests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pipeline scripts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Git repositories&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Examples include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SQL connection strings
Service Bus credentials
JWT secrets
API keys
Third-party credentials
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A recommended architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Azure Key Vault
                          |
                          |
                    Managed Identity
                          |
                          v
                         AKS
                          |
                          v
                    Microservices
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Azure DevOps variable/secret mechanisms can also be used where appropriate, but secrets should be managed according to your organization&#39;s security architecture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;35. What Happens When a Developer Commits Code?&lt;/h1&gt;&lt;p&gt;Suppose a developer changes the &lt;code inline=&quot;&quot;&gt;OrderService&lt;/code&gt; validation logic.&lt;/p&gt;&lt;p&gt;The developer executes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git add .
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git commit -m &quot;Update order validation&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git push origin main
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The automated process becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Git Push
   |
   v
CI Trigger
   |
   v
Restore
   |
   v
Build
   |
   v
Unit Tests
   |
   v
Docker Build
   |
   v
Docker Image
   |
   v
ACR
   |
   v
Release Pipeline
   |
   v
DEV
   |
   v
QA
   |
   v
UAT
   |
   v
Approval
   |
   v
PRODUCTION
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is the essence of CI/CD.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. Continuous Integration vs Continuous Delivery&lt;/h1&gt;&lt;p&gt;Understanding the difference between CI and CD is important.&lt;/p&gt;&lt;h2&gt;Continuous Integration&lt;/h2&gt;&lt;p&gt;Continuous Integration focuses on validating the application whenever code changes.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Code
 |
 v
Restore
 |
 v
Build
 |
 v
Test
 |
 v
Package
 |
 v
Docker Image
 |
 v
ACR
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The primary question is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;Is my code buildable, testable and packageable?&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt;Continuous Delivery / Deployment&lt;/h2&gt;&lt;p&gt;Continuous Delivery/Deployment focuses on moving the validated application version through environments.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ACR
 |
 v
DEV
 |
 v
QA
 |
 v
UAT
 |
 v
Approval
 |
 v
PRODUCTION
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The primary question is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;Can this version be safely deployed to the required environments?&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Therefore:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;CI = Build, test and package the application&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;CD = Deliver/deploy the application through environments&lt;/strong&gt;&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;37. Classic Pipeline vs YAML Pipeline&lt;/h1&gt;&lt;p&gt;The Classic UI is an excellent way to learn Azure DevOps because you can visually see:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Agent
Tasks
Stages
Artifacts
Approvals
Deployment
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, for modern enterprise projects, YAML pipelines are often preferred because the pipeline definition can be stored alongside the source code.&lt;/p&gt;&lt;p&gt;A modern architecture can look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure DevOps
      |
      v
YAML Pipeline
      |
      +---- CI
      |
      +---- Build
      |
      +---- Unit Tests
      |
      +---- Docker
      |
      +---- Security
      |
      +---- ACR
      |
      +---- CD
             |
             +---- DEV
             |
             +---- QA
             |
             +---- UAT
             |
             +---- PROD
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The key advantage is &lt;strong&gt;Pipeline as Code&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;The pipeline itself becomes version-controlled, reviewable, and reproducible.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;38. Recommended Enterprise Improvements&lt;/h1&gt;&lt;p&gt;The basic pipeline described above can be extended significantly for production environments.&lt;/p&gt;&lt;h2&gt;Security&lt;/h2&gt;&lt;p&gt;Add:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Managed Identity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Microsoft Entra ID&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Container image scanning&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dependency scanning&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secret scanning&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Least-privilege service connections&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Quality&lt;/h2&gt;&lt;p&gt;Add:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Unit tests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integration tests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Code coverage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SonarQube/SonarCloud&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API testing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Performance testing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Deployment&lt;/h2&gt;&lt;p&gt;Add:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Rolling deployments&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Health probes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Readiness probes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Liveness probes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deployment strategies&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automatic rollback&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Environment approvals&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Observability&lt;/h2&gt;&lt;p&gt;Add:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Application Insights&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Monitor&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Log Analytics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kubernetes monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Alerts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dashboards&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;39. Production-Ready Microservices Flow&lt;/h1&gt;&lt;p&gt;A mature enterprise architecture could eventually look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Developer
                             |
                             v
                        Azure Repos
                             |
                             v
                    Azure DevOps CI
                             |
          +------------------+------------------+
          |                  |                  |
          v                  v                  v
      Build/Test        Security Scan       Code Quality
          |                  |                  |
          +------------------+------------------+
                             |
                             v
                         Docker Build
                             |
                             v
                           ACR
                             |
                             v
                    Deployment Pipeline
                             |
            +----------------+----------------+
            |                |                |
            v                v                v
           DEV              QA               UAT
                                             |
                                         Approval
                                             |
                                             v
                                         PROD
                                             |
                                             v
                                            AKS
                                             |
                         +-------------------+-------------------+
                         |                   |                   |
                         v                   v                   v
                    Customer API        Order API          Product API
                         |                   |                   |
                         +-------------------+-------------------+
                                             |
                    +------------------------+----------------------+
                    |                                               |
                    v                                               v
                Azure SQL                                  Azure Service Bus
                    |
                    v
               Application
                 Insights
                    |
                    v
               Azure Monitor
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;40. Important Takeaways&lt;/h1&gt;&lt;p&gt;The complete deployment journey can be remembered as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer
   ↓
Git
   ↓
Azure DevOps
   ↓
CI
   ↓
Build
   ↓
Test
   ↓
Docker
   ↓
ACR
   ↓
CD
   ↓
DEV
   ↓
QA
   ↓
UAT
   ↓
Approval
   ↓
PRODUCTION
   ↓
AKS
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The responsibilities of the major components are:&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Component&lt;/th&gt;&lt;th&gt;Responsibility&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Azure Repos&lt;/td&gt;&lt;td&gt;Source-code management&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure DevOps&lt;/td&gt;&lt;td&gt;CI/CD automation&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Docker&lt;/td&gt;&lt;td&gt;Application containerization&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ACR&lt;/td&gt;&lt;td&gt;Docker image storage&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;AKS&lt;/td&gt;&lt;td&gt;Container orchestration&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Kubernetes&lt;/td&gt;&lt;td&gt;Application workload management&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Ingress/Gateway&lt;/td&gt;&lt;td&gt;Incoming traffic routing&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure SQL&lt;/td&gt;&lt;td&gt;Relational database&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure Service Bus&lt;/td&gt;&lt;td&gt;Asynchronous messaging&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Key Vault&lt;/td&gt;&lt;td&gt;Secret management&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Application Insights&lt;/td&gt;&lt;td&gt;Application telemetry&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure Monitor&lt;/td&gt;&lt;td&gt;Monitoring and alerting&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;41. Final Conclusion&lt;/h1&gt;&lt;p&gt;Implementing CI/CD for a .NET microservices application on Azure provides a repeatable and controlled way to move software from development to production.&lt;/p&gt;&lt;p&gt;The complete lifecycle is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Code
  ↓
Commit
  ↓
Build
  ↓
Unit Test
  ↓
Docker Image
  ↓
Azure Container Registry
  ↓
AKS Deployment
  ↓
DEV
  ↓
QA
  ↓
UAT
  ↓
Production Approval
  ↓
PRODUCTION
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For learning Azure DevOps, the &lt;strong&gt;Classic UI pipeline&lt;/strong&gt; is a very useful starting point because every stage and task is visible through the portal.&lt;/p&gt;&lt;p&gt;For a new enterprise implementation, however, it is worth moving toward &lt;strong&gt;YAML-based pipelines&lt;/strong&gt;, infrastructure as code, automated security scanning, managed identities, automated testing, deployment strategies, and comprehensive monitoring.&lt;/p&gt;&lt;p&gt;The ultimate goal is not simply to automate deployment.&lt;/p&gt;&lt;p&gt;The goal is to create a &lt;strong&gt;secure, repeatable, observable, and reliable software delivery process&lt;/strong&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Quick Reference&lt;/h2&gt;&lt;h3&gt;CI&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Git
 ↓
Restore
 ↓
Build
 ↓
Test
 ↓
Publish
 ↓
Docker Build
 ↓
Docker Push
 ↓
ACR
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;CD&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ACR
 ↓
DEV
 ↓
QA
 ↓
UAT
 ↓
Approval
 ↓
PRODUCTION
 ↓
AKS
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Application Architecture&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Internet
   ↓
Ingress / Gateway
   ↓
Microservices
   ↓
Azure SQL
   +
Azure Service Bus
   +
Key Vault
   +
Application Insights
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This architecture provides a strong foundation for deploying modern &lt;strong&gt;.NET 9 microservices applications on Azure using Azure DevOps, Docker, ACR and AKS&lt;/strong&gt;.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/7325766443467623134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/7325766443467623134' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/7325766443467623134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/7325766443467623134'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/complete-cicd-pipeline-for-net-9.html' title='Complete CI/CD Pipeline for .NET 9 Microservices on Azure Using Azure DevOps, Docker, ACR and AKS'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkHx29FvBtFFOTDXc94kqtUZYO3YG0OesJmZiPN8DsM3ORbeyhP8mlEJrnotHpo0F8sUg3vm62pZ9Z4Z-sIax1DI13YBNc-pd1_7pXBLyNrYLeNHhA1pBHMSQWRJuP7DHzjUkwePox9eIANbBbeLQr0c0CrMtAzuEUJ0__nTVwrikchMHnVVndPU_0EFs/s72-w507-h279-c/CiCDPipeline.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-812128428934627004</id><published>2026-08-14T12:18:51.425+05:30</published><updated>2026-08-14T12:30:10.449+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="SignalR vs Azure Service Bus vs Kafka vs RabbitMQ: Complete Guide with Real-Time Examples and C# Code"/><title type='text'>SignalR vs Azure Service Bus vs Kafka vs RabbitMQ: Complete Guide with Real-Time Examples and C# Code</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2iHkkGfCYWK-Jf0vtwfdA8zqUNWxZbwQdzjseWKNEMnPsnIBBFe5aqfk5ZKvhRFlZ6J2pC37thQQWQIkSAhehEvzl_23dL8khk0vIv4doy1Gp95FRYCIsrpAeJDzzUDHIIpJ1CaPwVDqBWgxVq8wrXsU4Nuh1D6pMbQn6gwaksemhbHAOCYE7TkvCCTI/s1536/MessageCommunication.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;309&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2iHkkGfCYWK-Jf0vtwfdA8zqUNWxZbwQdzjseWKNEMnPsnIBBFe5aqfk5ZKvhRFlZ6J2pC37thQQWQIkSAhehEvzl_23dL8khk0vIv4doy1Gp95FRYCIsrpAeJDzzUDHIIpJ1CaPwVDqBWgxVq8wrXsU4Nuh1D6pMbQn6gwaksemhbHAOCYE7TkvCCTI/w563-h309/MessageCommunication.png&quot; width=&quot;563&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h1&gt;SignalR vs Azure Service Bus vs Kafka vs RabbitMQ: Complete Guide with Real-Time Examples and C# Code&lt;/h1&gt;&lt;p&gt;Modern enterprise applications often use multiple applications, microservices, background workers, and front-end clients that need to communicate with each other. Choosing the right communication technology is therefore an important architectural decision.&lt;/p&gt;&lt;p&gt;Four technologies frequently considered in .NET and microservices architectures are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;ASP.NET Core SignalR&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Azure Service Bus&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;RabbitMQ&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Although they are sometimes compared with each other, they are designed for &lt;strong&gt;different communication patterns&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;The most important principle is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;SignalR is primarily for real-time client communication, Azure Service Bus and RabbitMQ are message brokers, while Kafka is primarily an event-streaming platform.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt;1. Introduction&lt;/h2&gt;&lt;p&gt;Consider an enterprise e-commerce application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Angular Application
                           |
                           v
                     Order Web API
                           |
             +-------------+-------------+
             |             |             |
             v             v             v
        Payment        Inventory     Notification
        Service          Service        Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now consider the following requirements:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Notify the customer&#39;s browser immediately when the order status changes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Send an order-processing message reliably to another microservice.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Route messages to different queues based on business requirements.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Store large volumes of events and allow multiple applications to process them independently.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Replay historical events for analytics or recovery.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;One technology is not necessarily the best solution for all these requirements.&lt;/p&gt;&lt;p&gt;This is where SignalR, Azure Service Bus, RabbitMQ and Kafka come into the picture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. Quick Comparison&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Technology&lt;/th&gt;&lt;th&gt;Primary Purpose&lt;/th&gt;&lt;th&gt;Best Use Case&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;SignalR&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Real-time client communication&lt;/td&gt;&lt;td&gt;Notifications, chat, live dashboards&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Azure Service Bus&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Enterprise messaging&lt;/td&gt;&lt;td&gt;Reliable microservice communication&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;RabbitMQ&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Message broker&lt;/td&gt;&lt;td&gt;Queues, routing, work distribution&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Kafka&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Event streaming&lt;/td&gt;&lt;td&gt;High-volume events, analytics, event pipelines&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;3. SignalR&lt;/h1&gt;&lt;p&gt;SignalR is an ASP.NET Core library designed for &lt;strong&gt;real-time communication between a server and connected clients&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Instead of the client repeatedly asking:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Is my order ready?

Is my order ready?

Is my order ready?
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;the server can push an update immediately:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order #1001 has been shipped.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;SignalR supports WebSockets and fallback transports such as Server-Sent Events and Long Polling.&lt;/p&gt;&lt;h3&gt;Typical SignalR use cases&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Real-time notifications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Chat applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Live dashboards&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Order tracking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Stock/price updates&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Progress notifications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Collaborative applications&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;4. SignalR Architecture&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                ASP.NET Core Server
                       |
                       |
                    SignalR
                       |
              WebSocket Connection
                       |
          +------------+------------+
          |            |            |
          v            v            v
       Browser 1    Browser 2    Browser 3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important point is that SignalR is generally about &lt;strong&gt;connected clients&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;It is not intended to replace a durable enterprise message broker.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. SignalR C# Example&lt;/h1&gt;&lt;p&gt;Install the SignalR package if required:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.AspNetCore.SignalR
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create a Hub:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class NotificationHub : Hub
{
    public async Task SendNotification(string message)
    {
        await Clients.All.SendAsync(
            &quot;ReceiveNotification&quot;,
            message);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure the Hub:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSignalR();

var app = builder.Build();

app.MapHub&amp;lt;NotificationHub&amp;gt;(&quot;/notificationHub&quot;);

app.Run();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A client can connect to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;/notificationHub
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The server can then send:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await hubContext.Clients.All.SendAsync(
    &quot;ReceiveNotification&quot;,
    &quot;Order #1001 has been shipped.&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;All connected clients receive the notification.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. SignalR with Angular&lt;/h1&gt;&lt;p&gt;Install the SignalR client:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install @microsoft/signalr
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create a connection:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;import * as signalR from &#39;@microsoft/signalr&#39;;

const connection =
    new signalR.HubConnectionBuilder()
        .withUrl(&#39;https://localhost:7000/notificationHub&#39;)
        .build();

connection.on(&#39;ReceiveNotification&#39;, message =&amp;gt; {
    console.log(message);
});

await connection.start();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The communication looks like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core
     |
     | SignalR
     | WebSocket
     v
Angular Application
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. Azure Service Bus&lt;/h1&gt;&lt;p&gt;Azure Service Bus is a &lt;strong&gt;fully managed enterprise message broker&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;It is designed for reliable communication between applications and services.&lt;/p&gt;&lt;p&gt;Microsoft describes Azure Service Bus as a cloud messaging system supporting queues, topics, subscriptions and enterprise messaging scenarios.&lt;/p&gt;&lt;p&gt;Consider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
    |
    | OrderCreated
    v
Azure Service Bus
    |
    +------&amp;gt; Payment Service
    |
    +------&amp;gt; Inventory Service
    |
    +------&amp;gt; Notification Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The producer and consumer don&#39;t need to execute at exactly the same time.&lt;/p&gt;&lt;p&gt;The broker provides the decoupling layer.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. Azure Service Bus Queue&lt;/h1&gt;&lt;p&gt;A queue generally represents a &lt;strong&gt;point-to-point&lt;/strong&gt; communication model.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Producer
   |
   v
+----------------+
| Order Queue    |
+----------------+
   |
   v
Consumer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
    |
    v
OrderQueue
    |
    v
Payment Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The message can remain available until a consumer successfully processes it.&lt;/p&gt;&lt;p&gt;This is particularly useful for background processing and microservice workflows.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. Azure Service Bus C# Producer&lt;/h1&gt;&lt;p&gt;Install:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Azure.Messaging.ServiceBus
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Producer:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Azure.Messaging.ServiceBus;
using System.Text.Json;

string connectionString = &quot;...&quot;;
string queueName = &quot;orders&quot;;

await using var client =
    new ServiceBusClient(connectionString);

ServiceBusSender sender =
    client.CreateSender(queueName);

var order = new
{
    OrderId = 1001,
    CustomerId = 5001,
    Amount = 2500
};

string json = JsonSerializer.Serialize(order);

var message = new ServiceBusMessage(json);

await sender.SendMessageAsync(message);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
    |
    | SendMessageAsync()
    v
Azure Service Bus
    |
    v
Order Queue
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;10. Azure Service Bus Consumer&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;ServiceBusProcessor processor =
    client.CreateProcessor(queueName);

processor.ProcessMessageAsync += async args =&amp;gt;
{
    string message =
        args.Message.Body.ToString();

    Console.WriteLine(message);

    await args.CompleteMessageAsync(args.Message);
};

processor.ProcessErrorAsync += args =&amp;gt;
{
    Console.WriteLine(args.Exception);
    return Task.CompletedTask;
};

await processor.StartProcessingAsync();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The consumer processes the message and explicitly completes it.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;11. Azure Service Bus Topic&lt;/h1&gt;&lt;p&gt;A topic is useful when the same business event needs to reach multiple subscribers.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Order API
                       |
                       v
                 OrderCreated
                       |
                       v
                Azure Service Bus
                     Topic
                       |
          +------------+------------+
          |            |            |
          v            v            v
     Subscription  Subscription  Subscription
       Payment       Inventory    Notification
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreated
      |
      +---- Payment Service
      |
      +---- Inventory Service
      |
      +---- Notification Service
      |
      +---- Audit Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Azure Service Bus topics and subscriptions provide a publish/subscribe model.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. RabbitMQ&lt;/h1&gt;&lt;p&gt;RabbitMQ is a popular &lt;strong&gt;message broker&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;One of its most important architectural concepts is the &lt;strong&gt;exchange&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;The typical flow is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Producer
   |
   v
Exchange
   |
   | Routing
   |
   +--------+--------+
   |        |        |
   v        v        v
Queue A   Queue B   Queue C
   |        |        |
   v        v        v
Consumer  Consumer  Consumer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;RabbitMQ supports different exchange types, including:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Direct&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Topic&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fanout&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Headers&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This provides flexible message-routing capabilities.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. RabbitMQ C# Producer&lt;/h1&gt;&lt;p&gt;A commonly used .NET package is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package RabbitMQ.Client
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using RabbitMQ.Client;
using System.Text;

var factory = new ConnectionFactory
{
    HostName = &quot;localhost&quot;
};

using var connection =
    await factory.CreateConnectionAsync();

using var channel =
    await connection.CreateChannelAsync();

await channel.QueueDeclareAsync(
    queue: &quot;orders&quot;,
    durable: true,
    exclusive: false,
    autoDelete: false);

string message = &quot;Order #1001 created&quot;;

byte[] body =
    Encoding.UTF8.GetBytes(message);

await channel.BasicPublishAsync(
    exchange: &quot;&quot;,
    routingKey: &quot;orders&quot;,
    body: body);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The message is sent to the RabbitMQ broker.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. RabbitMQ Consumer&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var consumer =
    new AsyncEventingBasicConsumer(channel);

consumer.ReceivedAsync += async (sender, args) =&amp;gt;
{
    string message =
        Encoding.UTF8.GetString(args.Body.ToArray());

    Console.WriteLine(message);

    await channel.BasicAckAsync(
        args.DeliveryTag,
        multiple: false);
};

await channel.BasicConsumeAsync(
    queue: &quot;orders&quot;,
    autoAck: false,
    consumer: consumer);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The acknowledgement tells RabbitMQ that the message has been successfully processed.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;15. Kafka&lt;/h1&gt;&lt;p&gt;Apache Kafka is primarily an &lt;strong&gt;event-streaming platform&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;This is an important distinction.&lt;/p&gt;&lt;p&gt;Kafka is not simply:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Producer -&amp;gt; Queue -&amp;gt; Consumer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead, Kafka uses:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Producer
    |
    v
Kafka Topic
    |
    +--- Partition 0
    |
    +--- Partition 1
    |
    +--- Partition 2
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Kafka topics are divided into partitions, allowing data to be distributed and processed in parallel. Kafka consumers use offsets to track their position in the stream.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. Kafka Consumer Groups&lt;/h1&gt;&lt;p&gt;This is one of Kafka&#39;s most important concepts.&lt;/p&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreated
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;is published to Kafka.&lt;/p&gt;&lt;p&gt;Multiple independent systems can consume it.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Kafka Topic
                        |
              +---------+---------+
              |         |         |
              v         v         v
          Payment    Analytics   Fraud
           Group       Group      Group
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each consumer group maintains its own position.&lt;/p&gt;&lt;p&gt;Therefore, the same event can be processed independently by multiple systems.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. Kafka C# Producer&lt;/h1&gt;&lt;p&gt;Install:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Confluent.Kafka
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Producer:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Confluent.Kafka;

var config = new ProducerConfig
{
    BootstrapServers = &quot;localhost:9092&quot;
};

using var producer =
    new ProducerBuilder&amp;lt;string, string&amp;gt;(config)
        .Build();

await producer.ProduceAsync(
    &quot;orders&quot;,
    new Message&amp;lt;string, string&amp;gt;
    {
        Key = &quot;1001&quot;,
        Value = &quot;Order #1001 created&quot;
    });
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
    |
    v
Kafka Producer
    |
    v
orders topic
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;18. Kafka Consumer&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var config = new ConsumerConfig
{
    BootstrapServers = &quot;localhost:9092&quot;,
    GroupId = &quot;payment-service&quot;,
    AutoOffsetReset = AutoOffsetReset.Earliest
};

using var consumer =
    new ConsumerBuilder&amp;lt;string, string&amp;gt;(config)
        .Build();

consumer.Subscribe(&quot;orders&quot;);

while (true)
{
    var result = consumer.Consume();

    Console.WriteLine(
        $&quot;Received: {result.Message.Value}&quot;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The consumer group is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;payment-service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Kafka uses offsets to keep track of which events have been processed.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;19. The Most Important Difference: Queue vs Event Stream&lt;/h1&gt;&lt;p&gt;This is one of the most frequently asked interview questions.&lt;/p&gt;&lt;h2&gt;Traditional Message Queue&lt;/h2&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Producer
   |
   v
Queue
   |
   v
Consumer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The primary purpose is to deliver work/messages to consumers.&lt;/p&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure Service Bus Queue
RabbitMQ Queue
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Kafka Event Stream&lt;/h2&gt;&lt;p&gt;Kafka is based around a durable event log:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Producer
   |
   v
+-----------------------------+
| Kafka Topic                 |
|                             |
| E1 E2 E3 E4 E5 E6 E7 ...    |
+-----------------------------+
       |
       +---- Consumer Group A
       |
       +---- Consumer Group B
       |
       +---- Consumer Group C
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Events can be retained according to Kafka&#39;s retention configuration, and consumers can maintain their own offsets.&lt;/p&gt;&lt;p&gt;This makes Kafka particularly powerful for:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Event streaming&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Event replay&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Analytics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Data pipelines&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Audit/event history&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;High-volume processing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;20. SignalR vs Azure Service Bus&lt;/h1&gt;&lt;p&gt;These technologies solve very different problems.&lt;/p&gt;&lt;h3&gt;SignalR&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Server
   |
   | Real-time
   v
Browser
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Azure Service Bus&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Service A
   |
   v
Azure Service Bus
   |
   v
Service B
&lt;/code&gt;&lt;/pre&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th align=&quot;right&quot;&gt;SignalR&lt;/th&gt;&lt;th align=&quot;right&quot;&gt;Azure Service Bus&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Real-time browser updates&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;WebSockets&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Service-to-service messaging&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Not primary&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Durable messaging&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Not primary&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Queue&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;No&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Topic/Subscription&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Client groups&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Chat&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Not primary&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Background processing&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Not primary&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Enterprise workflows&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Not primary&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;21. Azure Service Bus vs RabbitMQ&lt;/h1&gt;&lt;p&gt;These are much closer competitors.&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th align=&quot;right&quot;&gt;Azure Service Bus&lt;/th&gt;&lt;th align=&quot;right&quot;&gt;RabbitMQ&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Message queue&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Pub/Sub&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Routing&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Good&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Managed Azure service&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;No, unless using a managed RabbitMQ offering&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Self-hosting&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;No&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure integration&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Exchanges&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;No&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Routing keys&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;No&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Enterprise messaging&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Operational overhead&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Lower&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Higher if self-managed&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;If your application is heavily based on Azure, Azure Service Bus is often a natural choice because it is a managed Azure service.&lt;/p&gt;&lt;p&gt;RabbitMQ becomes attractive when you need broker-level control, flexible routing, self-hosting, or a platform-independent messaging layer.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;22. RabbitMQ vs Kafka&lt;/h1&gt;&lt;p&gt;These are also frequently compared.&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th align=&quot;right&quot;&gt;RabbitMQ&lt;/th&gt;&lt;th align=&quot;right&quot;&gt;Kafka&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Primary purpose&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Message broker&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Event streaming&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Queue&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Different model&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Routing&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Event streaming&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Limited compared with Kafka&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Event retention&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Not its primary model&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Core capability&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Event replay&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Not primary&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Consumer groups&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Different model&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Core capability&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Partitioning&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;No Kafka-style partition model&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Core capability&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;High-volume streams&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Good&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Work queues&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Possible&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Complex routing&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Less central&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Analytics pipelines&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Good&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;23. Kafka vs Azure Service Bus&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th align=&quot;right&quot;&gt;Kafka&lt;/th&gt;&lt;th align=&quot;right&quot;&gt;Azure Service Bus&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Event streaming&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Traditional queues&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Possible&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Event replay&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Different model&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Consumer groups&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Core feature&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Different model&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Partitioning&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Core feature&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Different scaling model&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Enterprise messaging&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Analytics&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Data pipelines&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Good&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure-native applications&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Good&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Operational complexity&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Higher&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Lower&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Event history&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Excellent&lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Different model&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;24. Real-World E-Commerce Architecture&lt;/h1&gt;&lt;p&gt;Let&#39;s combine these technologies in a realistic enterprise application.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                        Angular
                           |
                           | HTTPS
                           v
                     Order Web API
                           |
                           |
                    +------+------+
                    |             |
                    v             v
              Azure Service      Kafka
                  Bus              |
                    |              |
          +---------+---------+    +----------+
          |         |         |    |          |
          v         v         v    v          v
       Payment   Inventory Notification Analytics
       Service     Service    Service
                                     
                           |
                           v
                       SignalR
                           |
                           v
                     Angular Browser
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let&#39;s understand the flow.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;25. Step 1 — Customer Places Order&lt;/h1&gt;&lt;p&gt;Angular calls:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;POST /api/orders
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Order API creates the order.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
   v
Order API
   |
   v
Order Created
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;26. Step 2 — Azure Service Bus&lt;/h1&gt;&lt;p&gt;The Order API sends a business message:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreated
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;to Azure Service Bus.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
    |
    v
Azure Service Bus
    |
    +---- Payment Service
    |
    +---- Inventory Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This gives the services loose coupling.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;27. Step 3 — Kafka&lt;/h1&gt;&lt;p&gt;The system can also publish an event:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;OrderCreated
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;to Kafka.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Kafka
                      |
          +-----------+-----------+
          |           |           |
          v           v           v
      Analytics      Fraud      Reporting
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;These systems can independently process the event.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;28. Step 4 — SignalR&lt;/h1&gt;&lt;p&gt;Once the order status changes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Processing
       |
       v
Order Shipped
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;the backend sends a SignalR notification:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
      |
      v
SignalR Hub
      |
      v
Angular
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The customer immediately sees:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Your order has been shipped!
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;29. Complete Enterprise Architecture&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         +----------------+
                         |    Angular     |
                         +-------+--------+
                                 |
                                 | REST
                                 v
                         +---------------+
                         |   API Layer   |
                         +-------+-------+
                                 |
                         +-------+-------+
                         |               |
                         v               v
                +----------------+   +----------+
                | Azure Service  |   |  Kafka   |
                |     Bus        |   |          |
                +-------+--------+   +-----+----+
                        |                  |
             +----------+----------+      |
             |          |          |      |
             v          v          v      v
          Payment   Inventory  Notification Analytics
          Service     Service      Service
             |
             |
             v
       Business Processing
             |
             v
         SignalR Hub
             |
             v
          Angular UI
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This architecture demonstrates why these technologies should not automatically be treated as interchangeable.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;30. When Should You Use SignalR?&lt;/h1&gt;&lt;p&gt;Use SignalR when the requirement is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;I need to push information from my server to connected clients immediately.&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Live notification
Live chat
Order status
Real-time dashboard
Progress updates
Monitoring
Collaboration
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;31. When Should You Use Azure Service Bus?&lt;/h1&gt;&lt;p&gt;Use Azure Service Bus when the requirement is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;I need reliable enterprise messaging between applications or microservices.&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order processing
Payment processing
Inventory processing
Background jobs
Business workflows
Microservice communication
Enterprise integration
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;32. When Should You Use RabbitMQ?&lt;/h1&gt;&lt;p&gt;Use RabbitMQ when the requirement is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;I need a flexible message broker with sophisticated routing and queue-based processing.&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Work queues
Task distribution
Microservice messaging
Complex routing
Pub/Sub
Self-hosted messaging infrastructure
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;33. When Should You Use Kafka?&lt;/h1&gt;&lt;p&gt;Use Kafka when the requirement is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;I need a high-throughput, durable event stream that can be consumed independently by many applications.&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;IoT events
Clickstream
Analytics
Data pipelines
Event-driven architecture
Audit events
Financial events
Real-time processing
Large-scale event ingestion
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;34. Can We Use All Four Together?&lt;/h1&gt;&lt;p&gt;Yes.&lt;/p&gt;&lt;p&gt;In a large enterprise system, using multiple technologies can be completely valid.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 Customer
                    |
                    v
                Angular
                    |
                    v
                ASP.NET
                    |
          +---------+---------+
          |                   |
          v                   v
    Azure Service Bus       Kafka
          |                   |
          v                   v
   Business Services      Analytics
          |
          v
       SignalR
          |
          v
       Angular
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;RabbitMQ could also be introduced for a specialized workload where its routing or queueing model is advantageous.&lt;/p&gt;&lt;p&gt;The important thing is not to add technologies unnecessarily.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;35. Common Architectural Mistakes&lt;/h1&gt;&lt;h2&gt;Mistake 1: Using SignalR as a message broker&lt;/h2&gt;&lt;p&gt;Don&#39;t design:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
    |
    v
SignalR
    |
    v
Payment Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;just because SignalR can send messages.&lt;/p&gt;&lt;p&gt;SignalR is primarily intended for real-time client communication.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Mistake 2: Using Kafka for every small background job&lt;/h2&gt;&lt;p&gt;Kafka is extremely powerful, but that doesn&#39;t mean every background task requires Kafka.&lt;/p&gt;&lt;p&gt;For a simple:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order API
    |
    v
Process Invoice
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;a traditional queue such as Azure Service Bus or RabbitMQ may be simpler.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Mistake 3: Choosing Kafka because it is &quot;fast&quot;&lt;/h2&gt;&lt;p&gt;Architecture should not be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Kafka is fast
       ↓
Use Kafka everywhere
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead ask:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Do I need event streaming?
Do I need retention?
Do I need replay?
Do I need many consumer groups?
Do I need high-volume event processing?
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If yes, Kafka becomes a strong candidate.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. Interview Question: Are SignalR, Kafka, RabbitMQ and Service Bus Alternatives?&lt;/h1&gt;&lt;p&gt;&lt;strong&gt;Answer: Not completely.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;They overlap in some areas, but their primary purposes are different.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SignalR
   ↓
Real-time client communication

Azure Service Bus
   ↓
Enterprise message broker

RabbitMQ
   ↓
Message broker + flexible routing

Kafka
   ↓
Distributed event streaming
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;37. Interview Question: Kafka vs RabbitMQ?&lt;/h1&gt;&lt;p&gt;A good answer:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;RabbitMQ is primarily a message broker focused on queues, routing and message delivery, whereas Kafka is primarily an event-streaming platform designed around durable event streams, partitions, consumer groups and high-throughput processing. I would typically consider RabbitMQ for work queues and complex routing, and Kafka when I need scalable event streaming, retention, replay and multiple independent consumers.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;38. Interview Question: SignalR vs Kafka?&lt;/h1&gt;&lt;p&gt;A good answer:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;SignalR is designed for real-time communication between servers and connected clients, typically browsers or mobile applications. Kafka is designed for durable, scalable event streaming between backend systems. In an enterprise application, I might use Kafka to distribute an OrderShipped event internally and SignalR to push the resulting status update to the customer&#39;s browser.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;39. Interview Question: Service Bus vs RabbitMQ?&lt;/h1&gt;&lt;p&gt;A good answer:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Both are message brokers. Azure Service Bus is a managed Azure messaging service with strong integration into the Azure ecosystem, while RabbitMQ provides a flexible broker with exchanges, bindings and routing capabilities and can be self-hosted. If the application is Azure-centric and we want minimal infrastructure management, Service Bus is attractive. If we require greater broker-level control or specific RabbitMQ routing capabilities, RabbitMQ can be a better choice.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;40. Interview Question: Can SignalR and Azure Service Bus Be Used Together?&lt;/h1&gt;&lt;p&gt;Absolutely.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
     |
     | OrderCompleted
     v
Azure Service Bus
     |
     v
Notification Service
     |
     v
SignalR
     |
     v
Browser
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Service Bus provides reliable backend messaging.&lt;/p&gt;&lt;p&gt;SignalR provides real-time delivery to the user.&lt;/p&gt;&lt;p&gt;This is often a cleaner architecture than trying to use SignalR for both responsibilities.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;41. Final Decision Matrix&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Requirement&lt;/th&gt;&lt;th&gt;Recommended Technology&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Real-time browser notification&lt;/td&gt;&lt;td&gt;&lt;strong&gt;SignalR&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Chat&lt;/td&gt;&lt;td&gt;&lt;strong&gt;SignalR&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Live dashboard&lt;/td&gt;&lt;td&gt;&lt;strong&gt;SignalR&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Microservice command&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Azure Service Bus / RabbitMQ&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Enterprise business messaging&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Azure Service Bus&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Complex broker routing&lt;/td&gt;&lt;td&gt;&lt;strong&gt;RabbitMQ&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Background work queue&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Azure Service Bus / RabbitMQ&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;High-volume event stream&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Kafka&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Event replay&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Kafka&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Data/analytics pipeline&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Kafka&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Multiple independent consumers&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Kafka&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure-native messaging&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Azure Service Bus&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Self-hosted broker&lt;/td&gt;&lt;td&gt;&lt;strong&gt;RabbitMQ / Kafka&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Server-to-browser communication&lt;/td&gt;&lt;td&gt;&lt;strong&gt;SignalR&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;42. Conclusion&lt;/h1&gt;&lt;p&gt;SignalR, Azure Service Bus, RabbitMQ and Kafka are powerful technologies, but they solve different problems.&lt;/p&gt;&lt;p&gt;The easiest way to remember the difference is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;+---------------------------------------------------+
|                   COMMUNICATION                   |
+---------------------------------------------------+
|                                                   |
|  SignalR                                          |
|  Server ---&amp;gt; Connected Clients                   |
|                                                   |
|  Azure Service Bus                                |
|  Application ---&amp;gt; Reliable Business Message      |
|                                                   |
|  RabbitMQ                                         |
|  Producer ---&amp;gt; Broker ---&amp;gt; Routed Queue           |
|                                                   |
|  Kafka                                            |
|  Producer ---&amp;gt; Durable Event Stream ---&amp;gt; Consumers|
|                                                   |
+---------------------------------------------------+
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;In one sentence:&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Use SignalR for real-time client communication, Azure Service Bus for reliable Azure enterprise messaging, RabbitMQ for flexible broker-based messaging and routing, and Kafka for scalable, durable event streaming.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;For a modern &lt;strong&gt;.NET 9/10 + Angular + Microservices + Azure&lt;/strong&gt; enterprise application, a combination such as &lt;strong&gt;Azure Service Bus + Kafka + SignalR&lt;/strong&gt; can be very effective when each technology is assigned a clear responsibility.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/812128428934627004/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/812128428934627004' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/812128428934627004'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/812128428934627004'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/signalr-vs-azure-service-bus-vs-kafka.html' title='SignalR vs Azure Service Bus vs Kafka vs RabbitMQ: Complete Guide with Real-Time Examples and C# Code'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2iHkkGfCYWK-Jf0vtwfdA8zqUNWxZbwQdzjseWKNEMnPsnIBBFe5aqfk5ZKvhRFlZ6J2pC37thQQWQIkSAhehEvzl_23dL8khk0vIv4doy1Gp95FRYCIsrpAeJDzzUDHIIpJ1CaPwVDqBWgxVq8wrXsU4Nuh1D6pMbQn6gwaksemhbHAOCYE7TkvCCTI/s72-w563-h309-c/MessageCommunication.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-1338484576340943589</id><published>2026-08-13T15:26:17.579+05:30</published><updated>2026-08-13T20:53:39.563+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET Core SignalR"/><title type='text'>ASP.NET Core SignalR: Complete Guide with Real-Time Examples</title><content type='html'>&lt;h1 style=&quot;text-align: left;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGZlccO08c6WjM9m-ucqC8aDpuZC_fNvL4Qn6qaD9YuJPhakDuV1ktkvO6optEGvHNnUCtMNegPROPUSV2WebNzJpqkgtMUphy30c5kg-eNfai14PEZTZpX3o6M_T3jIMJ3UNz_ZDc4BSAyyx1ePoJ5o8mwg5KUwoS_n3f6SyKpnbQX5JUIzZEL2Cq0uA/s1536/SignalR.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;264&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGZlccO08c6WjM9m-ucqC8aDpuZC_fNvL4Qn6qaD9YuJPhakDuV1ktkvO6optEGvHNnUCtMNegPROPUSV2WebNzJpqkgtMUphy30c5kg-eNfai14PEZTZpX3o6M_T3jIMJ3UNz_ZDc4BSAyyx1ePoJ5o8mwg5KUwoS_n3f6SyKpnbQX5JUIzZEL2Cq0uA/w478-h264/SignalR.png&quot; width=&quot;478&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/h1&gt;&lt;h1 style=&quot;text-align: left;&quot;&gt;ASP.NET Core SignalR: Complete Guide with Real-Time Examples&lt;/h1&gt;&lt;h2&gt;Introduction&lt;/h2&gt;&lt;p&gt;In traditional web applications, the client usually sends a request to the server and waits for a response.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular Application
       |
       | HTTP Request
       v
ASP.NET Core Web API
       |
       | HTTP Response
       v
Angular Application
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This works very well for normal CRUD operations.&lt;/p&gt;&lt;p&gt;But consider applications where information needs to appear immediately:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;💬 Chat applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;🔔 Real-time notifications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;📊 Live dashboards&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;🚚 Order/shipment tracking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;🏦 Stock-price updates&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;🛒 E-commerce order status&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;🏭 IoT monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;🎮 Multiplayer applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;👥 Collaboration applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;📢 System alerts&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Polling the server repeatedly is one possible solution, but it is inefficient.&lt;/p&gt;&lt;p&gt;This is where &lt;strong&gt;ASP.NET Core SignalR&lt;/strong&gt; becomes useful.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. What is SignalR?&lt;/h1&gt;&lt;p&gt;&lt;strong&gt;SignalR is a real-time communication library for ASP.NET Core applications.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;It allows the server to push data to connected clients without requiring the client to continuously request new data.&lt;/p&gt;&lt;p&gt;The communication can look like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 ASP.NET Core Server
                        |
                        |
                 SignalR Hub
                 /     |      \
                /      |       \
               /       |        \
          Client A   Client B   Client C
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When something happens on the server, the server can immediately notify connected clients.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Created
     |
     v
ASP.NET Core
     |
     v
SignalR Hub
     |
     +-----------&amp;gt; Customer 1
     |
     +-----------&amp;gt; Customer 2
     |
     +-----------&amp;gt; Admin Dashboard
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;No client polling is required.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. Why Do We Need SignalR?&lt;/h1&gt;&lt;p&gt;Suppose an Angular application displays an order status.&lt;/p&gt;&lt;p&gt;The order status changes on the server:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order #1001
Status = Processing
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A few seconds later:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order #1001
Status = Shipped
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Without SignalR, the Angular application might repeatedly call:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-http&quot;&gt;GET /api/orders/1001
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Every 5 seconds
     |
     +---- GET /api/orders/1001
     |
     +---- GET /api/orders/1001
     |
     +---- GET /api/orders/1001
     |
     +---- GET /api/orders/1001
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is called &lt;strong&gt;polling&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;It creates unnecessary HTTP requests.&lt;/p&gt;&lt;p&gt;With SignalR:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Server detects status change
           |
           v
      SignalR Hub
           |
           v
     Connected Client
           |
           v
     UI updates immediately
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;3. SignalR Architecture&lt;/h1&gt;&lt;p&gt;A simplified SignalR architecture looks like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             Angular / React / JavaScript
                         |
                         |
                 SignalR Connection
                         |
                         v
                  ASP.NET Core
                         |
                         v
                   SignalR Hub
                         |
              +----------+----------+
              |                     |
          Client A               Client B
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The major components are:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Client&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SignalR Connection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Hub&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Hub Methods&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Server-to-Client Calls&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Client-to-Server Calls&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Groups&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Connection Management&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr /&gt;&lt;h1&gt;4. What is a SignalR Hub?&lt;/h1&gt;&lt;p&gt;A &lt;strong&gt;Hub&lt;/strong&gt; is the central communication point between clients and the server.&lt;/p&gt;&lt;p&gt;A Hub is similar to a controller in the sense that it exposes methods, but its purpose is real-time communication rather than traditional HTTP request/response processing.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class NotificationHub : Hub
{
    public async Task SendNotification(string message)
    {
        await Clients.All.SendAsync(&quot;ReceiveNotification&quot;, message);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Clients.All
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;means all connected clients.&lt;/p&gt;&lt;p&gt;And:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;SendAsync(&quot;ReceiveNotification&quot;, message)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;invokes a client-side method named:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ReceiveNotification
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;5. Creating a SignalR Project&lt;/h1&gt;&lt;p&gt;Suppose we have an ASP.NET Core Web API application.&lt;/p&gt;&lt;p&gt;Install SignalR if necessary:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.AspNetCore.SignalR
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Depending on the ASP.NET Core version and project type, SignalR server functionality may already be included through the ASP.NET Core shared framework.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;6. Create a SignalR Hub&lt;/h1&gt;&lt;p&gt;Create a folder:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Hubs
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;NotificationHub.cs
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Code:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.AspNetCore.SignalR;

public class NotificationHub : Hub
{
    public async Task SendNotification(string message)
    {
        await Clients.All.SendAsync(
            &quot;ReceiveNotification&quot;,
            message);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is our first SignalR Hub.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;7. Configure SignalR in Program.cs&lt;/h1&gt;&lt;p&gt;In ASP.NET Core:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

builder.Services.AddSignalR();

var app = builder.Build();

app.UseHttpsRedirection();

app.MapControllers();

app.MapHub&amp;lt;NotificationHub&amp;gt;(&quot;/notificationHub&quot;);

app.Run();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important line is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddSignalR();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This registers SignalR.&lt;/p&gt;&lt;p&gt;The following line maps the Hub:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;app.MapHub&amp;lt;NotificationHub&amp;gt;(&quot;/notificationHub&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The client can connect to:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;/notificationHub
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;https://localhost:7001/notificationHub
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;8. Understanding SendAsync()&lt;/h1&gt;&lt;p&gt;Consider:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await Clients.All.SendAsync(
    &quot;ReceiveNotification&quot;,
    message);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There are three important pieces.&lt;/p&gt;&lt;h3&gt;Clients.All&lt;/h3&gt;&lt;p&gt;Sends the message to every connected client.&lt;/p&gt;&lt;h3&gt;ReceiveNotification&lt;/h3&gt;&lt;p&gt;This is the client-side method name.&lt;/p&gt;&lt;h3&gt;message&lt;/h3&gt;&lt;p&gt;This is the data being sent.&lt;/p&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Server

Clients.All.SendAsync(
      &quot;ReceiveNotification&quot;,
      &quot;Order Created&quot;
)

              |
              v

Client A -&amp;gt; ReceiveNotification(&quot;Order Created&quot;)

Client B -&amp;gt; ReceiveNotification(&quot;Order Created&quot;)

Client C -&amp;gt; ReceiveNotification(&quot;Order Created&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;9. JavaScript Client&lt;/h1&gt;&lt;p&gt;Install the SignalR JavaScript client:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install @microsoft/signalr
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;import * as signalR from &#39;@microsoft/signalr&#39;;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create a connection:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;const connection =
    new signalR.HubConnectionBuilder()
        .withUrl(&quot;https://localhost:7001/notificationHub&quot;)
        .withAutomaticReconnect()
        .build();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Start the connection:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;connection.start()
    .then(() =&amp;gt; {
        console.log(&quot;SignalR connected&quot;);
    })
    .catch(error =&amp;gt; {
        console.error(error);
    });
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;10. Receiving Messages&lt;/h1&gt;&lt;p&gt;The server sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await Clients.All.SendAsync(
    &quot;ReceiveNotification&quot;,
    message);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The JavaScript client listens for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;connection.on(
    &quot;ReceiveNotification&quot;,
    (message) =&amp;gt; {
        console.log(message);
    });
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the complete flow is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ASP.NET Core

Clients.All.SendAsync(
    &quot;ReceiveNotification&quot;,
    message
)

            |
            v

JavaScript

connection.on(
    &quot;ReceiveNotification&quot;,
    message =&amp;gt; {
        console.log(message);
    }
)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The method names must match:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ReceiveNotification
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;11. Complete Real-Time Notification Example&lt;/h1&gt;&lt;p&gt;Let&#39;s build a realistic notification system.&lt;/p&gt;&lt;p&gt;Imagine an e-commerce application.&lt;/p&gt;&lt;p&gt;When an order is created:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Customer places order
       |
       v
Order API
       |
       v
Database
       |
       v
SignalR Hub
       |
       v
Customer/Admin Dashboard
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The UI immediately displays:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;🔔 New Order Created

Order Number: ORD-1001
Status: Processing
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;12. Notification Hub&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.AspNetCore.SignalR;

public class NotificationHub : Hub
{
    public async Task SendNotification(
        string title,
        string message)
    {
        await Clients.All.SendAsync(
            &quot;ReceiveNotification&quot;,
            new
            {
                Title = title,
                Message = message,
                CreatedAt = DateTime.UtcNow
            });
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we can send an object rather than just a string.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. Calling SignalR from an API Controller&lt;/h1&gt;&lt;p&gt;Suppose we have:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[ApiController]
[Route(&quot;api/orders&quot;)]
public class OrdersController : ControllerBase
{
    private readonly IHubContext&amp;lt;NotificationHub&amp;gt; _hubContext;

    public OrdersController(
        IHubContext&amp;lt;NotificationHub&amp;gt; hubContext)
    {
        _hubContext = hubContext;
    }

    [HttpPost]
    public async Task&amp;lt;IActionResult&amp;gt; CreateOrder(
        CreateOrderRequest request)
    {
        // Save order into database

        var orderId = 1001;

        await _hubContext.Clients.All.SendAsync(
            &quot;OrderCreated&quot;,
            new
            {
                OrderId = orderId,
                Status = &quot;Processing&quot;
            });

        return Ok(new
        {
            OrderId = orderId
        });
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is an important real-world pattern.&lt;/p&gt;&lt;p&gt;We don&#39;t need to call a Hub method directly.&lt;/p&gt;&lt;p&gt;Instead, our Web API can inject:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;IHubContext&amp;lt;NotificationHub&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and send messages to clients.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. What is IHubContext?&lt;/h1&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;IHubContext&lt;/code&gt; allows application code outside the Hub to communicate with connected clients.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Controller
Service
Background Worker
Azure Function
Message Consumer
     |
     v
IHubContext
     |
     v
SignalR Clients
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;private readonly IHubContext&amp;lt;NotificationHub&amp;gt; _hubContext;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await _hubContext.Clients.All.SendAsync(
    &quot;ReceiveNotification&quot;,
    &quot;New order created&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. SignalR Client Types&lt;/h1&gt;&lt;p&gt;SignalR provides several ways to target clients.&lt;/p&gt;&lt;h2&gt;Clients.All&lt;/h2&gt;&lt;p&gt;Send to everyone.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await Clients.All.SendAsync(
    &quot;ReceiveNotification&quot;,
    message);
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Clients.Caller&lt;/h2&gt;&lt;p&gt;Send only to the client that made the request.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await Clients.Caller.SendAsync(
    &quot;ReceiveNotification&quot;,
    message);
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Clients.Others&lt;/h2&gt;&lt;p&gt;Send to everyone except the caller.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await Clients.Others.SendAsync(
    &quot;ReceiveNotification&quot;,
    message);
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Clients.Client&lt;/h2&gt;&lt;p&gt;Send to a specific connection.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await Clients.Client(connectionId)
    .SendAsync(
        &quot;ReceiveNotification&quot;,
        message);
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;16. SignalR Groups&lt;/h1&gt;&lt;p&gt;Groups are extremely useful in real-world applications.&lt;/p&gt;&lt;p&gt;Imagine an enterprise application with:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Sales Team
Support Team
Managers
Administrators
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We don&#39;t want every user to receive every notification.&lt;/p&gt;&lt;p&gt;Instead, we can create groups.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SignalR

+----------------------+
| Sales Group          |
| User A               |
| User B               |
+----------------------+

+----------------------+
| Support Group        |
| User C               |
| User D               |
+----------------------+

+----------------------+
| Manager Group        |
| User E               |
| User F               |
+----------------------+
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;17. Joining a Group&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task JoinGroup(string groupName)
{
    await Groups.AddToGroupAsync(
        Context.ConnectionId,
        groupName);
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A client can call:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;JoinGroup(&quot;Sales&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the client belongs to the Sales group.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;18. Sending to a Group&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await Clients.Group(&quot;Sales&quot;)
    .SendAsync(
        &quot;ReceiveNotification&quot;,
        &quot;New sales order received&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Only clients in the Sales group receive the message.&lt;/p&gt;&lt;p&gt;This is very useful for:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Department notifications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Tenant-based applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Project-based collaboration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Team dashboards&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Chat rooms&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Order-specific updates&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;19. Real-Time Order Tracking&lt;/h1&gt;&lt;p&gt;Let&#39;s create a more realistic example.&lt;/p&gt;&lt;p&gt;Suppose an e-commerce order moves through:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Created
     |
     v
Processing
     |
     v
Packed
     |
     v
Shipped
     |
     v
Out for Delivery
     |
     v
Delivered
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The server can notify the customer whenever the status changes.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await _hubContext.Clients
    .Group($&quot;order-{orderId}&quot;)
    .SendAsync(
        &quot;OrderStatusChanged&quot;,
        new
        {
            OrderId = orderId,
            Status = &quot;Shipped&quot;
        });
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Only users watching that order receive the update.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;20. Joining an Order Group&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task JoinOrderGroup(int orderId)
{
    await Groups.AddToGroupAsync(
        Context.ConnectionId,
        $&quot;order-{orderId}&quot;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Client:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;await connection.invoke(
    &quot;JoinOrderGroup&quot;,
    orderId);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then listen for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;connection.on(
    &quot;OrderStatusChanged&quot;,
    (order) =&amp;gt; {
        console.log(
            `Order ${order.orderId} status: ${order.status}`
        );
    }
);
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;21. Angular + SignalR&lt;/h1&gt;&lt;p&gt;SignalR works very well with Angular.&lt;/p&gt;&lt;p&gt;Install:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install @microsoft/signalr
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;signalr.service.ts
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;import { Injectable } from &#39;@angular/core&#39;;
import * as signalR from &#39;@microsoft/signalr&#39;;

@Injectable({
  providedIn: &#39;root&#39;
})
export class SignalRService {

  private connection!: signalR.HubConnection;

  startConnection(): void {

    this.connection =
      new signalR.HubConnectionBuilder()
        .withUrl(
          &#39;https://localhost:7001/notificationHub&#39;
        )
        .withAutomaticReconnect()
        .build();

    this.connection
      .start()
      .then(() =&amp;gt; {
        console.log(&#39;SignalR connected&#39;);
      })
      .catch(error =&amp;gt; {
        console.error(error);
      });
  }

  onNotification(
    callback: (message: any) =&amp;gt; void
  ): void {

    this.connection.on(
      &#39;ReceiveNotification&#39;,
      callback
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;22. Using SignalR Service in Angular Component&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;import { Component, OnInit } from &#39;@angular/core&#39;;
import { SignalRService } from &#39;./signalr.service&#39;;

@Component({
  selector: &#39;app-dashboard&#39;,
  templateUrl: &#39;./dashboard.component.html&#39;
})
export class DashboardComponent
  implements OnInit {

  notification: any;

  constructor(
    private signalRService: SignalRService
  ) {}

  ngOnInit(): void {

    this.signalRService.startConnection();

    this.signalRService.onNotification(
      (message) =&amp;gt; {

        this.notification = message;

        console.log(
          &#39;Notification received:&#39;,
          message
        );
      }
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;23. SignalR Connection Lifecycle&lt;/h1&gt;&lt;p&gt;A SignalR connection can have different states:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Disconnected
     |
     v
Connecting
     |
     v
Connected
     |
     v
Reconnecting
     |
     +----------+
     |          |
     v          v
 Connected   Disconnected
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can monitor connection events.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;connection.onreconnecting(error =&amp;gt; {
    console.log(&#39;Connection lost. Reconnecting...&#39;);
});

connection.onreconnected(connectionId =&amp;gt; {
    console.log(
        &#39;Reconnected:&#39;,
        connectionId
    );
});

connection.onclose(error =&amp;gt; {
    console.log(&#39;SignalR connection closed&#39;);
});
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;24. Automatic Reconnection&lt;/h1&gt;&lt;p&gt;SignalR supports automatic reconnect.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;const connection =
    new signalR.HubConnectionBuilder()
        .withUrl(&#39;/notificationHub&#39;)
        .withAutomaticReconnect()
        .build();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can also specify retry intervals:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;.withAutomaticReconnect([
    0,
    2000,
    5000,
    10000
])
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Meaning:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;First retry   -&amp;gt; Immediately
Second retry  -&amp;gt; 2 seconds
Third retry   -&amp;gt; 5 seconds
Fourth retry  -&amp;gt; 10 seconds
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;25. WebSockets and SignalR&lt;/h1&gt;&lt;p&gt;SignalR can use different transports.&lt;/p&gt;&lt;p&gt;The primary transport is:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;WebSockets
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Other supported transports can include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Server-Sent Events
Long Polling
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Conceptually:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SignalR
   |
   +---- WebSockets
   |
   +---- Server-Sent Events
   |
   +---- Long Polling
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;SignalR selects an appropriate transport based on the environment and client/server capabilities.&lt;/p&gt;&lt;p&gt;Therefore, developers normally don&#39;t need to implement WebSocket management manually.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. SignalR vs WebSocket&lt;/h1&gt;&lt;p&gt;A common interview question is:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&quot;What is the difference between WebSockets and SignalR?&quot;&lt;/strong&gt;&lt;/p&gt;&lt;h3&gt;WebSocket&lt;/h3&gt;&lt;p&gt;WebSocket is a communication protocol that provides full-duplex communication between client and server.&lt;/p&gt;&lt;h3&gt;SignalR&lt;/h3&gt;&lt;p&gt;SignalR is a higher-level framework/library that provides real-time communication and can use WebSockets when available, while also supporting fallback transports.&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;WebSocket&lt;/th&gt;&lt;th&gt;SignalR&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Communication&lt;/td&gt;&lt;td&gt;Real-time&lt;/td&gt;&lt;td&gt;Real-time&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Abstraction&lt;/td&gt;&lt;td&gt;Low-level&lt;/td&gt;&lt;td&gt;High-level&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Automatic reconnect&lt;/td&gt;&lt;td&gt;Implement yourself&lt;/td&gt;&lt;td&gt;Supported&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Groups&lt;/td&gt;&lt;td&gt;Implement yourself&lt;/td&gt;&lt;td&gt;Built-in&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Client management&lt;/td&gt;&lt;td&gt;Manual&lt;/td&gt;&lt;td&gt;Built-in abstractions&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ASP.NET Core integration&lt;/td&gt;&lt;td&gt;Manual&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Hub concept&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;27. SignalR vs Polling&lt;/h1&gt;&lt;h3&gt;Polling&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Client
  |
  | Request
  v
Server
  |
  | Response
  v
Client

Wait

Client
  |
  | Request
  v
Server
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This generates repeated requests.&lt;/p&gt;&lt;h3&gt;SignalR&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Client
   |
   | Establish connection
   v
SignalR Server
   |
   | Connection remains available
   |
   | &amp;lt;--- Real-time message
   |
   | &amp;lt;--- Real-time message
   |
   | &amp;lt;--- Real-time message
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is much more suitable for real-time communication.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;28. Authentication with SignalR&lt;/h1&gt;&lt;p&gt;Enterprise applications usually need authentication.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
   | JWT
   v
ASP.NET Core
   |
   v
SignalR Hub
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure authentication:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddAuthentication(
    JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =&amp;gt;
    {
        // JWT configuration
    });
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddAuthorization();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Hub:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[Authorize]
public class NotificationHub : Hub
{
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now only authenticated users can connect to the Hub.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;29. Accessing the Current User&lt;/h1&gt;&lt;p&gt;Inside a Hub:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var userId =
    Context.User?.FindFirst(&quot;sub&quot;)?.Value;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can also access:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Context.ConnectionId
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Context.User
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is useful for user-specific notifications.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;30. User-Specific Notifications&lt;/h1&gt;&lt;p&gt;Suppose User 1001 receives an order update.&lt;/p&gt;&lt;p&gt;We can send a message to that specific user:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await _hubContext.Clients
    .User(&quot;1001&quot;)
    .SendAsync(
        &quot;ReceiveNotification&quot;,
        &quot;Your order has been shipped.&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is different from:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;Clients.All
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;because only the specified user receives the notification.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;31. Real-Time Enterprise Architecture&lt;/h1&gt;&lt;p&gt;A typical enterprise architecture might look like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                Angular
                   |
                   |
             API Management
                   |
          +--------+--------+
          |                 |
       Web API          SignalR
          |                 |
          |                 |
     Microservices      SignalR Hub
          |                 |
          |          +------+------+
          |          |             |
          v          v             v
       Database   Client A      Client B
          |
          v
      Message Bus
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For larger systems, events can flow through a message broker.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
     |
     v
Azure Service Bus / Kafka
     |
     v
Notification Service
     |
     v
SignalR
     |
     +------&amp;gt; Angular Client
     |
     +------&amp;gt; Admin Dashboard
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This provides a scalable architecture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;32. SignalR with Background Services&lt;/h1&gt;&lt;p&gt;SignalR is not limited to controllers.&lt;/p&gt;&lt;p&gt;A background service can also send notifications.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderMonitoringService
    : BackgroundService
{
    private readonly IHubContext&amp;lt;NotificationHub&amp;gt;
        _hubContext;

    public OrderMonitoringService(
        IHubContext&amp;lt;NotificationHub&amp;gt; hubContext)
    {
        _hubContext = hubContext;
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            await _hubContext.Clients.All.SendAsync(
                &quot;ReceiveNotification&quot;,
                &quot;Background process completed&quot;,
                stoppingToken);

            await Task.Delay(
                TimeSpan.FromMinutes(1),
                stoppingToken);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Register:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddHostedService&amp;lt;OrderMonitoringService&amp;gt;();
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;33. SignalR in Microservices&lt;/h1&gt;&lt;p&gt;In a microservices architecture, avoid making every microservice directly responsible for client connections.&lt;/p&gt;&lt;p&gt;A better architecture can be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;              Angular
                 |
                 v
           SignalR Service
                 ^
                 |
          Notification Service
                 ^
                 |
        Azure Service Bus / Kafka
                 ^
                 |
       +---------+---------+
       |         |         |
    Order     Payment   Shipping
   Service     Service   Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Order Service
     |
     | OrderCreated event
     v
Azure Service Bus
     |
     v
Notification Service
     |
     v
SignalR
     |
     v
Angular
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This creates better separation of responsibilities.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;34. Scaling SignalR&lt;/h1&gt;&lt;p&gt;This is very important for production systems.&lt;/p&gt;&lt;p&gt;Imagine:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;100,000 users
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;connected to your application.&lt;/p&gt;&lt;p&gt;You may have multiple application instances:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Load Balancer
                         |
          +--------------+--------------+
          |              |              |
          v              v              v
      Server 1        Server 2        Server 3
          |              |              |
       SignalR        SignalR        SignalR
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The problem is that clients can be connected to different servers.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Client A ---&amp;gt; Server 1

Client B ---&amp;gt; Server 2
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If Server 1 sends a message locally, Server 2 may not automatically know about it.&lt;/p&gt;&lt;p&gt;For scaled-out SignalR deployments, you typically need a backplane or managed SignalR service depending on the architecture.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;35. Azure SignalR Service&lt;/h1&gt;&lt;p&gt;For Azure-based applications, &lt;strong&gt;Azure SignalR Service&lt;/strong&gt; can handle SignalR connection scaling.&lt;/p&gt;&lt;p&gt;Architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;              Angular Clients
             /       |       \
            /        |        \
           v         v         v
      Azure SignalR Service
                 |
                 |
                 v
          ASP.NET Core API
                 |
                 v
          Microservices
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This can reduce the responsibility of managing large numbers of persistent client connections in your application servers.&lt;/p&gt;&lt;p&gt;For enterprise applications deployed on Azure, Azure SignalR Service is an important option to evaluate.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;36. SignalR in AKS&lt;/h1&gt;&lt;p&gt;If your application runs in AKS:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    Azure
                      |
               Application Gateway
                      |
                  Ingress
                      |
          +-----------+-----------+
          |           |           |
          v           v           v
        Pod 1       Pod 2       Pod 3
          |           |           |
       SignalR     SignalR     SignalR
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Persistent connections introduce additional considerations when scaling.&lt;/p&gt;&lt;p&gt;For large-scale deployments, Azure SignalR Service can simplify the connection-management layer.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;37. Real-World Use Case: Live Dashboard&lt;/h1&gt;&lt;p&gt;Imagine an operations dashboard:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;+---------------------------------------+
|       REAL-TIME OPERATIONS DASHBOARD  |
+---------------------------------------+
| Orders Today              12,542      |
| Successful Orders         11,934      |
| Failed Orders                108      |
| Pending Orders               500      |
+---------------------------------------+

Recent Events
-----------------------------------------
10:20:12  Order #1001 Created
10:20:15  Order #1002 Created
10:20:18  Order #1003 Shipped
10:20:22  Order #1004 Delivered
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead of refreshing the browser:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Dashboard
    |
    | SignalR
    v
ASP.NET Core
    |
    v
Real-time events
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The dashboard updates automatically.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;38. SignalR Error Handling&lt;/h1&gt;&lt;p&gt;Always consider connection failures.&lt;/p&gt;&lt;p&gt;Server:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;try
{
    await Clients.All.SendAsync(
        &quot;ReceiveNotification&quot;,
        message);
}
catch (Exception ex)
{
    // Log exception
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Client:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;connection.start()
    .catch(error =&amp;gt; {
        console.error(
            &#39;SignalR connection failed&#39;,
            error
        );
    });
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use proper logging rather than silently ignoring errors.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;39. Important SignalR Best Practices&lt;/h1&gt;&lt;h3&gt;1. Don&#39;t put business logic inside the Hub&lt;/h3&gt;&lt;p&gt;Avoid:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public async Task CreateOrder()
{
    // 500 lines of business logic
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Prefer:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Hub
 |
 v
Application Service
 |
 v
Domain Service
 |
 v
Repository
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;2. Use strongly typed contracts&lt;/h3&gt;&lt;p&gt;Instead of sending arbitrary objects everywhere, define DTOs.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrderStatusNotification
{
    public int OrderId { get; set; }

    public string Status { get; set; } = string.Empty;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await _hubContext.Clients.All.SendAsync(
    &quot;OrderStatusChanged&quot;,
    notification);
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;3. Use Groups&lt;/h3&gt;&lt;p&gt;For large applications, groups are useful for:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Tenant
Department
Project
Order
Chat Room
Team
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;4. Enable Authentication&lt;/h3&gt;&lt;p&gt;Don&#39;t expose sensitive real-time data to unauthenticated clients.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;5. Handle Reconnection&lt;/h3&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;.withAutomaticReconnect()
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and monitor:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;onreconnecting
onreconnected
onclose
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;6. Don&#39;t Send Excessive Data&lt;/h3&gt;&lt;p&gt;Instead of:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Send entire database record
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;send only what the UI needs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &quot;orderId&quot;: 1001,
    &quot;status&quot;: &quot;Shipped&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;40. Complete SignalR Flow&lt;/h1&gt;&lt;p&gt;The complete application flow can be represented as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             Angular Application
                     |
                     |
             SignalR Connection
                     |
                     v
              NotificationHub
                     |
                     ^
                     |
             IHubContext
                     ^
                     |
              Order Service
                     |
                     v
                  Database
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With an event-driven architecture:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
   v
SignalR
   ^
   |
Notification Service
   ^
   |
Azure Service Bus / Kafka
   ^
   |
Order Service
   |
   v
Database
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;41. SignalR Interview Questions&lt;/h1&gt;&lt;h3&gt;What is SignalR?&lt;/h3&gt;&lt;p&gt;SignalR is a real-time communication library for ASP.NET Core applications that allows servers to push messages to connected clients.&lt;/p&gt;&lt;h3&gt;What is a Hub?&lt;/h3&gt;&lt;p&gt;A Hub is a high-level abstraction for communication between clients and the server.&lt;/p&gt;&lt;h3&gt;What is IHubContext?&lt;/h3&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;IHubContext&lt;/code&gt; allows application components outside a Hub to send messages to connected SignalR clients.&lt;/p&gt;&lt;h3&gt;What is Clients.All?&lt;/h3&gt;&lt;p&gt;It sends a message to all connected clients.&lt;/p&gt;&lt;h3&gt;What is Clients.Caller?&lt;/h3&gt;&lt;p&gt;It sends a message only to the client that initiated the Hub call.&lt;/p&gt;&lt;h3&gt;What are SignalR Groups?&lt;/h3&gt;&lt;p&gt;Groups allow connected clients to be logically grouped and targeted collectively.&lt;/p&gt;&lt;h3&gt;Can SignalR work with Angular?&lt;/h3&gt;&lt;p&gt;Yes. Microsoft provides the &lt;code inline=&quot;&quot;&gt;@microsoft/signalr&lt;/code&gt; JavaScript/TypeScript client.&lt;/p&gt;&lt;h3&gt;Does SignalR always use WebSockets?&lt;/h3&gt;&lt;p&gt;No. SignalR can use WebSockets when available and supports fallback transports.&lt;/p&gt;&lt;h3&gt;How do you scale SignalR?&lt;/h3&gt;&lt;p&gt;Depending on the deployment, options include a backplane or a managed service such as Azure SignalR Service.&lt;/p&gt;&lt;h3&gt;Can SignalR be used with microservices?&lt;/h3&gt;&lt;p&gt;Yes. A common pattern is to publish domain/application events through a message broker and have a notification component deliver relevant events to clients through SignalR.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;42. SignalR vs REST API&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;REST API&lt;/th&gt;&lt;th&gt;SignalR&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Communication&lt;/td&gt;&lt;td&gt;Request/Response&lt;/td&gt;&lt;td&gt;Real-time&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Server Push&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Persistent Connection&lt;/td&gt;&lt;td&gt;Usually no&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CRUD&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;td&gt;Not primary purpose&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Notifications&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Chat&lt;/td&gt;&lt;td&gt;Not ideal&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Live Dashboard&lt;/td&gt;&lt;td&gt;Polling required&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Order Tracking&lt;/td&gt;&lt;td&gt;Polling required&lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;WebSockets&lt;/td&gt;&lt;td&gt;Not inherent&lt;/td&gt;&lt;td&gt;Supported&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;SignalR does &lt;strong&gt;not&lt;/strong&gt; replace REST APIs.&lt;/p&gt;&lt;p&gt;A modern application commonly uses both:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;REST API
    |
    +---- CRUD operations

SignalR
    |
    +---- Real-time notifications
    +---- Live status
    +---- Events
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;43. Recommended Enterprise Architecture&lt;/h1&gt;&lt;p&gt;For a large .NET + Angular application, a practical architecture could be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                         Angular
                            |
             +--------------+--------------+
             |                             |
          REST API                      SignalR
             |                             |
             v                             v
       API Management              Azure SignalR
             |                             |
             v                             |
      ASP.NET Core APIs                    |
             |                             |
       +-----+------+                      |
       |            |                      |
       v            v                      |
    Orders       Payments                  |
       |            |                      |
       +-----+------+                      |
             |                             |
             v                             |
       Azure Service Bus ------------------+
                     |
                     v
              Notification Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This architecture provides:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Separation of responsibilities&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Real-time client communication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Event-driven integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Better scalability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Better support for microservices&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reduced polling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Better user experience&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;44. Conclusion&lt;/h1&gt;&lt;p&gt;SignalR is one of the most useful technologies in the ASP.NET Core ecosystem when an application needs &lt;strong&gt;real-time communication&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;It is especially useful for:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;🔔 Notifications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;💬 Chat&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;📊 Live dashboards&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;🚚 Order tracking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;📈 Monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;🏭 IoT applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;👥 Collaboration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;⚡ Real-time enterprise applications&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The key concepts to remember are:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;SignalR
   |
   +-- Hub
   |
   +-- Clients
   |
   +-- IHubContext
   |
   +-- Groups
   |
   +-- Connections
   |
   +-- Authentication
   |
   +-- Automatic Reconnection
   |
   +-- Scaling
   |
   +-- Azure SignalR Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a simple application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
   v
SignalR Hub
   |
   v
ASP.NET Core
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For an enterprise application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Angular
   |
   +------ REST API
   |
   +------ SignalR
             |
             v
      Azure SignalR Service
             |
             v
      Notification Service
             |
             v
   Azure Service Bus / Kafka
             |
             v
       Microservices
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The biggest advantage of SignalR is that the application doesn&#39;t have to continuously ask:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Has anything changed?&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Instead, the server can tell the client immediately when something important happens.&lt;/p&gt;&lt;p&gt;That makes SignalR a strong choice for building responsive, event-driven, real-time .NET applications.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/1338484576340943589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/1338484576340943589' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1338484576340943589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1338484576340943589'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/aspnet-core-signalr-complete-guide-with.html' title='ASP.NET Core SignalR: Complete Guide with Real-Time Examples'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGZlccO08c6WjM9m-ucqC8aDpuZC_fNvL4Qn6qaD9YuJPhakDuV1ktkvO6optEGvHNnUCtMNegPROPUSV2WebNzJpqkgtMUphy30c5kg-eNfai14PEZTZpX3o6M_T3jIMJ3UNz_ZDc4BSAyyx1ePoJ5o8mwg5KUwoS_n3f6SyKpnbQX5JUIzZEL2Cq0uA/s72-w478-h264-c/SignalR.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-6988365932720679805</id><published>2026-08-07T12:20:27.999+05:30</published><updated>2026-08-07T19:32:44.616+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="AI -2026"/><category scheme="http://www.blogger.com/atom/ns#" term="AI tools"/><title type='text'>The Ultimate Guide to AI Tools (2026)</title><content type='html'>&lt;style&gt;
.ai-table{
    width:100%;
    border-collapse:collapse;
    font-family:&#39;Segoe UI&#39;, Arial, sans-serif;
    font-size:14px;
    border:1px solid #dcdcdc;
}

.ai-table th,
.ai-table td{
    border:1px solid #dcdcdc;
    padding:10px;
}

.ai-table th{
    background:#0d6efd;
    color:#ffffff;
    font-weight:bold;
    text-align:center;
}

.ai-table td{
    text-align:left;
}

.ai-table tbody tr:nth-child(even){
    background:#f5f5f5;
}

.ai-table tbody tr:hover{
    background:#e8f4ff;
}
&lt;/style&gt;&lt;h1 style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIjxbJvnpijjg3umrRdbbH5E3d_pWSw6eNf78rSIQG26um2IjLlkYCfsJp98kn69YksIVFaIxp4X7td4Ewemz-bKdkQYjcmNzlQf6Z09O3gOkN9vw78h6jC_dI_Wz-6jl_4BsOfIJHxjAvZR5HL9pcsgqyI9YLQEneXZmt9E1sEQvLIdc1eWv1PiA9a0A/s1026/AITools_TN.png&quot; style=&quot;font-size: medium; font-weight: 400; margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;344&quot; data-original-width=&quot;1026&quot; height=&quot;214&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIjxbJvnpijjg3umrRdbbH5E3d_pWSw6eNf78rSIQG26um2IjLlkYCfsJp98kn69YksIVFaIxp4X7td4Ewemz-bKdkQYjcmNzlQf6Z09O3gOkN9vw78h6jC_dI_Wz-6jl_4BsOfIJHxjAvZR5HL9pcsgqyI9YLQEneXZmt9E1sEQvLIdc1eWv1PiA9a0A/w674-h214/AITools_TN.png&quot; width=&quot;674&quot; /&gt;&lt;/a&gt;&lt;/h1&gt;&lt;h1 style=&quot;text-align: left;&quot;&gt;The Ultimate Guide to AI Tools (2026)&lt;/h1&gt;&lt;h2&gt;Complete Comparison of 50+ AI Tools, Features, Pricing, Industry Use Cases, Owners, Download Links &amp;amp; Expert Recommendations&lt;/h2&gt;&lt;hr /&gt;&lt;h1&gt;Introduction&lt;/h1&gt;&lt;p&gt;Artificial Intelligence (AI) has rapidly evolved from an experimental technology into an essential business tool. Today, organizations across software development, healthcare, banking, education, marketing, manufacturing, and entertainment rely on AI to improve productivity, automate repetitive tasks, generate insights, and create innovative products.&lt;/p&gt;&lt;p&gt;Whether you&#39;re a software engineer, solution architect, technical lead, business analyst, content creator, or entrepreneur, selecting the right AI tool can significantly improve efficiency and reduce costs.&lt;/p&gt;&lt;p&gt;This guide provides an overview of the most popular AI tools available in 2026, their owners, release dates, pricing models, industry applications, and key advantages.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Why AI Matters&lt;/h1&gt;&lt;p&gt;Organizations are adopting AI because it helps them:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Increase employee productivity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automate repetitive work&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Improve customer experience&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reduce operational costs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generate software code faster&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create images, videos, and presentations&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Analyze large amounts of data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Make better business decisions&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Top AI Tools Comparison&lt;/h1&gt;&lt;table class=&quot;ai-table&quot;&gt;&lt;thead&gt;
  &lt;tr&gt;&lt;th&gt;AI Tool&lt;/th&gt;&lt;th&gt;Owner&lt;/th&gt;&lt;th&gt;Released&lt;/th&gt;&lt;th&gt;Free Version&lt;/th&gt;&lt;th&gt;Primary Use&lt;/th&gt;&lt;th&gt;Best Industry&lt;/th&gt;&lt;th&gt;Major Advantage&lt;/th&gt;&lt;th&gt;Official Website&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;ChatGPT&lt;/td&gt;&lt;td&gt;OpenAI&lt;/td&gt;&lt;td&gt;Nov 2022&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;AI Assistant&lt;/td&gt;&lt;td&gt;Software, Education&lt;/td&gt;&lt;td&gt;Best all-round AI assistant&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://chat.openai.com/&quot;&gt;https://chat.openai.com&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Claude&lt;/td&gt;&lt;td&gt;Anthropic&lt;/td&gt;&lt;td&gt;Mar 2023&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;AI Assistant&lt;/td&gt;&lt;td&gt;Enterprise, Legal&lt;/td&gt;&lt;td&gt;Excellent reasoning&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://claude.ai/&quot;&gt;https://claude.ai&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Gemini&lt;/td&gt;&lt;td&gt;Google&lt;/td&gt;&lt;td&gt;Dec 2023&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;AI Assistant&lt;/td&gt;&lt;td&gt;Google Workspace&lt;/td&gt;&lt;td&gt;Deep Google integration&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://gemini.google.com/&quot;&gt;https://gemini.google.com&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Microsoft Copilot&lt;/td&gt;&lt;td&gt;Microsoft&lt;/td&gt;&lt;td&gt;2023&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Productivity&lt;/td&gt;&lt;td&gt;Microsoft 365&lt;/td&gt;&lt;td&gt;Office integration&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://copilot.microsoft.com/&quot;&gt;https://copilot.microsoft.com&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;GitHub Copilot&lt;/td&gt;&lt;td&gt;GitHub (Microsoft)&lt;/td&gt;&lt;td&gt;2021&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Coding&lt;/td&gt;&lt;td&gt;Software Development&lt;/td&gt;&lt;td&gt;AI pair programmer&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://github.com/features/copilot&quot;&gt;https://github.com/features/copilot&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Cursor AI&lt;/td&gt;&lt;td&gt;Anysphere&lt;/td&gt;&lt;td&gt;2023&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Coding IDE&lt;/td&gt;&lt;td&gt;Software Engineering&lt;/td&gt;&lt;td&gt;Understands entire codebase&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://cursor.com/&quot;&gt;https://cursor.com&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Perplexity AI&lt;/td&gt;&lt;td&gt;Perplexity&lt;/td&gt;&lt;td&gt;2022&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Research&lt;/td&gt;&lt;td&gt;Research&lt;/td&gt;&lt;td&gt;Live web citations&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://perplexity.ai/&quot;&gt;https://perplexity.ai&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;NotebookLM&lt;/td&gt;&lt;td&gt;Google&lt;/td&gt;&lt;td&gt;2023&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Knowledge Management&lt;/td&gt;&lt;td&gt;Education&lt;/td&gt;&lt;td&gt;Works with your own documents&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://notebooklm.google/&quot;&gt;https://notebooklm.google&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Midjourney&lt;/td&gt;&lt;td&gt;Midjourney&lt;/td&gt;&lt;td&gt;2022&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Image Generation&lt;/td&gt;&lt;td&gt;Design&lt;/td&gt;&lt;td&gt;Premium artistic images&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://midjourney.com/&quot;&gt;https://midjourney.com&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Adobe Firefly&lt;/td&gt;&lt;td&gt;Adobe&lt;/td&gt;&lt;td&gt;2023&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Image Generation&lt;/td&gt;&lt;td&gt;Marketing&lt;/td&gt;&lt;td&gt;Commercial-safe AI images&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://firefly.adobe.com/&quot;&gt;https://firefly.adobe.com&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Canva AI&lt;/td&gt;&lt;td&gt;Canva&lt;/td&gt;&lt;td&gt;2023&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Design&lt;/td&gt;&lt;td&gt;Marketing&lt;/td&gt;&lt;td&gt;Easy graphics &amp;amp; presentations&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://canva.com/&quot;&gt;https://canva.com&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Runway ML&lt;/td&gt;&lt;td&gt;Runway&lt;/td&gt;&lt;td&gt;2022&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Video Generation&lt;/td&gt;&lt;td&gt;Media&lt;/td&gt;&lt;td&gt;AI video creation&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://runwayml.com/&quot;&gt;https://runwayml.com&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ElevenLabs&lt;/td&gt;&lt;td&gt;ElevenLabs&lt;/td&gt;&lt;td&gt;2022&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Voice AI&lt;/td&gt;&lt;td&gt;Podcasts&lt;/td&gt;&lt;td&gt;Natural voice generation&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://elevenlabs.io/&quot;&gt;https://elevenlabs.io&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Gamma&lt;/td&gt;&lt;td&gt;Gamma&lt;/td&gt;&lt;td&gt;2023&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Presentations&lt;/td&gt;&lt;td&gt;Business&lt;/td&gt;&lt;td&gt;AI slide generation&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://gamma.app/&quot;&gt;https://gamma.app&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Zapier AI&lt;/td&gt;&lt;td&gt;Zapier&lt;/td&gt;&lt;td&gt;2023&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Automation&lt;/td&gt;&lt;td&gt;Enterprise&lt;/td&gt;&lt;td&gt;Workflow automation&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://zapier.com/&quot;&gt;https://zapier.com&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;Industry-wise Best AI Tools&lt;/h1&gt;&lt;h2&gt;Software Development&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;ChatGPT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;GitHub Copilot&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cursor AI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Claude&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DeepSeek&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Benefits&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Code generation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Debugging&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Unit testing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API development&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Documentation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Banking &amp;amp; Finance&lt;/h2&gt;&lt;p&gt;Recommended Tools:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Claude&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ChatGPT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Microsoft Copilot&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Used For:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Financial analysis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Compliance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fraud detection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Customer support&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Healthcare&lt;/h2&gt;&lt;p&gt;Recommended Tools:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;ChatGPT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Claude&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Microsoft Copilot&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Applications:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Clinical documentation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Medical research&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Patient assistance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Knowledge management&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Education&lt;/h2&gt;&lt;p&gt;Recommended Tools:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;ChatGPT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Gemini&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;NotebookLM&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Canva AI&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Applications:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Lesson planning&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Student learning&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Research&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Content generation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Digital Marketing&lt;/h2&gt;&lt;p&gt;Recommended Tools:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;ChatGPT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Canva AI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Midjourney&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Adobe Firefly&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ideogram&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Applications:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Blog writing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Social media&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SEO&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Image creation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Campaign planning&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Video Production&lt;/h2&gt;&lt;p&gt;Recommended Tools:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Runway ML&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pika&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Synthesia&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;HeyGen&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Applications:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;AI videos&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Marketing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Corporate training&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;YouTube content&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Free vs Paid AI Tools&lt;/h1&gt;&lt;h3&gt;Completely Free (Basic Plans)&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;ChatGPT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Claude&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Gemini&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Perplexity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;NotebookLM&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ElevenLabs (limited)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DeepSeek&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Limited Free Tier&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;GitHub Copilot&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cursor AI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Microsoft Copilot&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Canva AI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Gamma&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Zapier AI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Runway ML&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Paid Only or Mostly Paid&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Midjourney&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Synthesia&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Where Each AI Tool Fits in the Enterprise&lt;/h1&gt;&lt;h2&gt;User Interface Layer&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;ChatGPT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Gemini&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Claude&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Copilot&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Development Layer&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;GitHub Copilot&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cursor AI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DeepSeek&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Creative Layer&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Midjourney&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Canva AI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Firefly&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Runway ML&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Knowledge Layer&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;NotebookLM&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Perplexity AI&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Automation Layer&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Zapier AI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Make AI&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;How to Choose the Right AI Tool&lt;/h1&gt;&lt;p&gt;Before selecting an AI platform, ask these questions:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;What problem am I solving?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Is a free version sufficient?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Does it integrate with my existing tools?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Is my data secure?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Can it scale as my business grows?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is the total cost of ownership?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Does it provide enterprise support?&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr /&gt;&lt;h1&gt;Major Advantages of AI Tools&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Increase productivity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Save development time&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reduce operational costs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Improve customer experience&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generate high-quality content&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automate repetitive tasks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enhance software quality&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Improve decision making&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enable 24×7 availability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Accelerate innovation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Future of AI (2027 and Beyond)&lt;/h1&gt;&lt;p&gt;The next generation of AI will focus on:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;AI Agents performing complete business workflows&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Multi-modal AI (text, image, voice, video)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Industry-specific foundation models&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Autonomous software development&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;AI-assisted decision making&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Hyper-personalized customer experiences&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secure enterprise AI platforms&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Responsible and explainable AI&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Artificial Intelligence is no longer optional—it is becoming a fundamental capability for modern organizations. The right AI tool depends on your goals, industry, budget, and workflow.&lt;/p&gt;&lt;p&gt;For software professionals, a combination of &lt;strong&gt;ChatGPT, GitHub Copilot, Cursor AI, Claude, and Microsoft Copilot&lt;/strong&gt; provides an excellent productivity stack. Creative professionals benefit from tools such as &lt;strong&gt;Midjourney, Canva AI, Adobe Firefly, Runway ML, and ElevenLabs&lt;/strong&gt;, while researchers and analysts can leverage &lt;strong&gt;Perplexity AI&lt;/strong&gt; and &lt;strong&gt;NotebookLM&lt;/strong&gt; for trusted information retrieval and knowledge management.&lt;/p&gt;&lt;p&gt;Start by exploring the free versions, evaluate how each tool fits your workflow, and gradually adopt those that deliver the greatest value.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/6988365932720679805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/6988365932720679805' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/6988365932720679805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/6988365932720679805'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/the-ultimate-guide-to-ai-tools-2026.html' title='The Ultimate Guide to AI Tools (2026)'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIjxbJvnpijjg3umrRdbbH5E3d_pWSw6eNf78rSIQG26um2IjLlkYCfsJp98kn69YksIVFaIxp4X7td4Ewemz-bKdkQYjcmNzlQf6Z09O3gOkN9vw78h6jC_dI_Wz-6jl_4BsOfIJHxjAvZR5HL9pcsgqyI9YLQEneXZmt9E1sEQvLIdc1eWv1PiA9a0A/s72-w674-h214-c/AITools_TN.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-1136771544235177271</id><published>2026-08-06T20:38:06.331+05:30</published><updated>2026-08-06T20:38:47.122+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="SonarQube"/><title type='text'>SonarQube: The Complete Guide for .NET Developers (2026)</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3gNS9YpGxziNSglO1sX6tNhpcQ7mIm0Ix7K35cxUCghF0LfFa0-1k38yTjgTBtv75Le3XbnBZLyStbFieRMjyqPJ4kS9RJFNd-EIx6puLDhy3-uz3Uyf0CJ75xTfDk5r-ygXFRky3uZCMLucvtxs8gq7GkumiLFlk4NWoPTO3sr7xCb0s2U4rBX9WsMc/s1536/SonarQube.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3gNS9YpGxziNSglO1sX6tNhpcQ7mIm0Ix7K35cxUCghF0LfFa0-1k38yTjgTBtv75Le3XbnBZLyStbFieRMjyqPJ4kS9RJFNd-EIx6puLDhy3-uz3Uyf0CJ75xTfDk5r-ygXFRky3uZCMLucvtxs8gq7GkumiLFlk4NWoPTO3sr7xCb0s2U4rBX9WsMc/s320/SonarQube.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h1&gt;Working with SonarQube: The Complete Guide for .NET Developers (2026)&lt;/h1&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Learn how to integrate SonarQube with .NET, Azure DevOps, GitHub, Jenkins, and CI/CD pipelines to improve code quality, security, and maintainability.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;Table of Contents&lt;/h1&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Introduction to SonarQube&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Why SonarQube?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SonarQube Architecture&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Editions of SonarQube&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Installation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dashboard Overview&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Core Concepts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Quality Gates&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Quality Profiles&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Code Smells&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Bugs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Vulnerabilities&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security Hotspots&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Technical Debt&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Code Coverage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Duplicated Code&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Static Code Analysis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Analyzing .NET Applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integration with Visual Studio&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SonarScanner for .NET&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure DevOps Integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;GitHub Actions Integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Jenkins Integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pull Request Analysis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Branch Analysis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enterprise Best Practices&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Real-Time Enterprise Example&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Interview Questions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Best Practices&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Common Mistakes&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr /&gt;&lt;h1&gt;What is SonarQube?&lt;/h1&gt;&lt;p&gt;SonarQube is an &lt;strong&gt;automated code quality inspection platform&lt;/strong&gt; that continuously analyzes your source code.&lt;/p&gt;&lt;p&gt;It identifies:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Bugs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security vulnerabilities&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Code smells&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Duplicated code&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Code coverage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Maintainability issues&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Think of SonarQube as a &lt;strong&gt;code reviewer that never sleeps.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Instead of waiting for senior developers to review code manually, SonarQube automatically checks thousands of coding rules.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Why SonarQube?&lt;/h1&gt;&lt;p&gt;Without SonarQube&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Developer
     |
     V

Writes Code

     |

Code Review

     |

Deployment

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Problems:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Bugs reach production&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Duplicate code&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security issues&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Low code coverage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Poor maintainability&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;p&gt;With SonarQube&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Developer

     |

Writes Code

     |

SonarQube Analysis

     |

Quality Gate

     |

Deploy

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Bad code never reaches Production.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Real Enterprise Example&lt;/h1&gt;&lt;p&gt;Suppose Amazon has 500 developers.&lt;/p&gt;&lt;p&gt;Every day&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;250 Pull Requests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;80 Projects&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Millions of Lines of Code&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Manual review is impossible.&lt;/p&gt;&lt;p&gt;Instead&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Developer

↓

Push Code

↓

Azure DevOps

↓

Build

↓

SonarQube Scan

↓

Quality Gate

↓

Deploy
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Coverage &amp;lt;80%

OR

New Bugs &amp;gt;0

OR

Critical Vulnerability Exists

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Deployment is blocked.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;SonarQube Architecture&lt;/h1&gt;&lt;pre&gt;&lt;code&gt;                 Developers
                     |
                     |
             SonarScanner
                     |
                     |
              SonarQube Server
                     |
        -------------------------
        |                       |
 Elasticsearch             PostgreSQL
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Components&lt;/p&gt;&lt;h3&gt;SonarScanner&lt;/h3&gt;&lt;p&gt;Collects source code.&lt;/p&gt;&lt;h3&gt;SonarQube Server&lt;/h3&gt;&lt;p&gt;Analyzes the code.&lt;/p&gt;&lt;h3&gt;Database&lt;/h3&gt;&lt;p&gt;Stores&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Reports&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Issues&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Quality Gates&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;History&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Elasticsearch&lt;/h3&gt;&lt;p&gt;Provides fast searching.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Editions&lt;/h1&gt;&lt;h2&gt;Community&lt;/h2&gt;&lt;p&gt;Free&lt;/p&gt;&lt;p&gt;Supports&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;C#&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Java&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JavaScript&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Python&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Developer&lt;/h2&gt;&lt;p&gt;Adds&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Branch analysis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pull Request Analysis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security Reports&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Enterprise&lt;/h2&gt;&lt;p&gt;Adds&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Portfolio&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Governance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Advanced Security&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Data Center&lt;/h2&gt;&lt;p&gt;Large organizations.&lt;/p&gt;&lt;p&gt;Supports clustering.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Installing SonarQube&lt;/h1&gt;&lt;p&gt;Requirements&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Java 21&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;PostgreSQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SonarQube ZIP&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SonarScanner&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Extract&lt;/p&gt;&lt;pre&gt;&lt;code&gt;sonarqube/

bin/

conf/

logs/

extensions/

data/
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Start&lt;/p&gt;&lt;p&gt;Windows&lt;/p&gt;&lt;pre&gt;&lt;code&gt;StartSonar.bat
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Linux&lt;/p&gt;&lt;pre&gt;&lt;code&gt;./sonar.sh start
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Default URL&lt;/p&gt;&lt;pre&gt;&lt;code&gt;http://localhost:9000
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Dashboard&lt;/h1&gt;&lt;p&gt;After login&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Project

Coverage

Security

Maintainability

Reliability

Duplications

Technical Debt

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Everything is visible in one dashboard.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;What is a Quality Gate?&lt;/h1&gt;&lt;p&gt;Quality Gate decides&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Can this code be released?&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Condition&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Bugs&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Vulnerabilities&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Coverage&lt;/td&gt;&lt;td&gt;&amp;gt;80%&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Duplicates&lt;/td&gt;&lt;td&gt;&amp;lt;3%&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Code Smells&lt;/td&gt;&lt;td&gt;&amp;lt;10&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;If any condition fails&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Quality Gate = Failed
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Deployment stops.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Quality Profile&lt;/h1&gt;&lt;p&gt;Quality Profile contains coding rules.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Avoid Empty Catch

No Hardcoded Password

Dispose IDisposable

Avoid SQL Injection

Avoid Null Reference

Naming Convention

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each language has its own profile.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Bugs&lt;/h1&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;string s = null;

Console.WriteLine(s.Length);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;SonarQube&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Bug

Possible NullReferenceException
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Code Smells&lt;/h1&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;if(a==true)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Better&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;if(a)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Another example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public void Method()
{
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Unused methods are reported.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Vulnerabilities&lt;/h1&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;string sql =
&quot;SELECT * FROM Users WHERE Name=&#39;&quot; + user + &quot;&#39;&quot;;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;SonarQube reports&lt;/p&gt;&lt;pre&gt;&lt;code&gt;SQL Injection
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Better&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;command.Parameters.Add(&quot;@Name&quot;, user);
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Security Hotspots&lt;/h1&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;SHA1.Create();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Not always vulnerable.&lt;/p&gt;&lt;p&gt;But&lt;/p&gt;&lt;p&gt;Needs developer review.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Code Coverage&lt;/h1&gt;&lt;p&gt;Coverage tells&lt;/p&gt;&lt;p&gt;How much code is tested.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Total Lines =1000

Covered =850

Coverage =85%
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Higher coverage means better confidence.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Duplicate Code&lt;/h1&gt;&lt;p&gt;Bad&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;CalculateTax()

CalculateTax()

CalculateTax()
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Repeated everywhere.&lt;/p&gt;&lt;p&gt;SonarQube detects duplication.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Technical Debt&lt;/h1&gt;&lt;p&gt;Suppose&lt;/p&gt;&lt;pre&gt;&lt;code&gt;100 Code Smells

Estimated Fix Time

18 Hours
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Technical Debt&lt;/p&gt;&lt;pre&gt;&lt;code&gt;18 Hours
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Reliability Rating&lt;/h1&gt;&lt;pre&gt;&lt;code&gt;A

B

C

D

E
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A is best.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Maintainability Rating&lt;/h1&gt;&lt;p&gt;Measures&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Complexity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Duplication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Readability&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Security Rating&lt;/h1&gt;&lt;p&gt;Measures&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Vulnerabilities&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security Hotspots&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Cyclomatic Complexity&lt;/h1&gt;&lt;p&gt;Bad&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;if()
{
 if()
 {
   while()
   {
      switch()
      {
      }
 }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Complexity increases.&lt;/p&gt;&lt;p&gt;Keep methods simple.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Cognitive Complexity&lt;/h1&gt;&lt;p&gt;Measures&lt;/p&gt;&lt;p&gt;How difficult the code is to understand.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;if()

foreach()

while()

switch()

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Higher nesting&lt;/p&gt;&lt;p&gt;Higher complexity.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;SonarScanner for .NET&lt;/h1&gt;&lt;p&gt;Install&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet tool install --global dotnet-sonarscanner
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Begin Analysis&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet sonarscanner begin \
/k:&quot;EmployeeAPI&quot; \
/d:sonar.host.url=&quot;http://localhost:9000&quot; \
/d:sonar.token=&quot;TOKEN&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Build&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet build
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;End&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet sonarscanner end \
/d:sonar.token=&quot;TOKEN&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Dashboard updates automatically.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Visual Studio Integration&lt;/h1&gt;&lt;p&gt;Install&lt;/p&gt;&lt;p&gt;&lt;strong&gt;SonarLint&lt;/strong&gt; extension.&lt;/p&gt;&lt;p&gt;Benefits&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Live issue detection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Coding suggestions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security warnings&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Connected Mode with SonarQube&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Developers can fix issues before committing code.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Azure DevOps Integration&lt;/h1&gt;&lt;p&gt;Pipeline&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;trigger:
- main

pool:
  vmImage: windows-latest

steps:

- task: SonarQubePrepare@7
  inputs:
    SonarQube: &#39;SonarQube&#39;
    scannerMode: &#39;dotnet&#39;
    projectKey: &#39;EmployeeAPI&#39;

- task: DotNetCoreCLI@2
  inputs:
    command: build
    projects: &#39;**/*.csproj&#39;

- task: SonarQubeAnalyze@7

- task: SonarQubePublish@7
  inputs:
    pollingTimeoutSec: &#39;300&#39;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If the Quality Gate fails, configure the pipeline to stop the release or deployment stage.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;GitHub Actions Integration&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;name: Build

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: windows-latest

    steps:

    - uses: actions/checkout@v4

    - uses: actions/setup-dotnet@v4
      with:
        dotnet-version: &#39;9.0.x&#39;

    - run: dotnet tool install --global dotnet-sonarscanner

    - run: |
        dotnet sonarscanner begin /k:&quot;EmployeeAPI&quot; /d:sonar.host.url=&quot;${{ secrets.SONAR_HOST_URL }}&quot; /d:sonar.token=&quot;${{ secrets.SONAR_TOKEN }}&quot;
        dotnet build
        dotnet sonarscanner end /d:sonar.token=&quot;${{ secrets.SONAR_TOKEN }}&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Jenkins Integration&lt;/h1&gt;&lt;p&gt;Pipeline&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Checkout

↓

Restore Packages

↓

Build

↓

Run Unit Tests

↓

Sonar Scanner

↓

Quality Gate

↓

Deploy
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Pull Request Analysis&lt;/h1&gt;&lt;p&gt;Every PR receives&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Bugs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security Issues&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Code Coverage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Duplication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;New Code Quality&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Reviewers see issues before merging.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Branch Analysis&lt;/h1&gt;&lt;p&gt;Analyze&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Main

Develop

Release

Feature

Hotfix
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each branch has its own quality metrics (supported in commercial editions).&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Enterprise Workflow&lt;/h1&gt;&lt;pre&gt;&lt;code&gt;Developer

↓

Git

↓

Azure DevOps

↓

Build

↓

Unit Test

↓

SonarQube

↓

Quality Gate

↓

Container Build

↓

Docker

↓

AKS

↓

Production
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This helps ensure only quality-checked builds are deployed.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Best Practices&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Analyze every Pull Request.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enforce a Quality Gate in CI/CD.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Aim for at least 80% unit test coverage (adjust based on project needs).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fix new issues before addressing legacy issues.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Keep Quality Profiles consistent across projects.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use Connected Mode with SonarLint.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Review Security Hotspots rather than ignoring them.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Track technical debt regularly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Customize rules to match your team&#39;s coding standards.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Treat critical vulnerabilities as release blockers.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Common Mistakes&lt;/h1&gt;&lt;p&gt;❌ Ignoring Quality Gate failures&lt;/p&gt;&lt;p&gt;❌ Disabling important rules&lt;/p&gt;&lt;p&gt;❌ Running analysis only before releases&lt;/p&gt;&lt;p&gt;❌ Ignoring code duplication&lt;/p&gt;&lt;p&gt;❌ Not writing unit tests&lt;/p&gt;&lt;p&gt;❌ Using outdated Quality Profiles&lt;/p&gt;&lt;p&gt;❌ Hardcoding secrets in source code&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Top Interview Questions&lt;/h1&gt;&lt;h3&gt;1. What is SonarQube?&lt;/h3&gt;&lt;p&gt;A static code analysis platform used to improve code quality, maintainability, and security.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;2. Difference between SonarQube and SonarLint?&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;SonarLint:&lt;/strong&gt; Runs inside the IDE and provides instant feedback while coding.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;SonarQube:&lt;/strong&gt; Central server that analyzes projects, tracks history, and enforces quality gates across teams.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h3&gt;3. What is a Quality Gate?&lt;/h3&gt;&lt;p&gt;A configurable set of conditions that determines whether code meets the required quality standards before it can proceed in the delivery pipeline.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;4. What is Technical Debt?&lt;/h3&gt;&lt;p&gt;An estimate of the effort required to fix maintainability issues and code smells in the codebase.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;5. What is a Security Hotspot?&lt;/h3&gt;&lt;p&gt;Code that requires a developer or security reviewer to determine whether it represents an actual security risk.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;6. Does SonarQube compile the application?&lt;/h3&gt;&lt;p&gt;No. It analyzes the project during or after the build process but is not a compiler.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;7. Can SonarQube analyze Microservices?&lt;/h3&gt;&lt;p&gt;Yes. Each microservice can be analyzed independently, with its own project key, quality profile, and quality gate.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;8. Can SonarQube block deployments?&lt;/h3&gt;&lt;p&gt;Yes. When integrated into a CI/CD pipeline, a failed Quality Gate can be used to stop subsequent deployment stages.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;SonarQube is an essential component of modern DevSecOps practices. By integrating it with .NET applications and CI/CD platforms such as Azure DevOps, GitHub Actions, and Jenkins, teams can continuously detect bugs, security vulnerabilities, code smells, and maintainability issues before they reach production. Combined with unit testing and code reviews, SonarQube helps deliver more reliable, secure, and maintainable enterprise software.&lt;/p&gt;&lt;h3&gt;Articles coming in this blog series&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;SonarQube + Azure DevOps: Complete CI/CD Integration&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;SonarQube with .NET 9 Web API: Step-by-Step Guide&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Top 100 SonarQube Interview Questions and Answers&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;SonarLint vs SonarQube: What&#39;s the Difference?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improving Code Quality with SonarQube Rules and Quality Profiles&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enterprise DevSecOps Pipeline with SonarQube, Docker, AKS, and Azure DevOps&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/1136771544235177271/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/1136771544235177271' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1136771544235177271'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1136771544235177271'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/sonarqube.html' title='SonarQube: The Complete Guide for .NET Developers (2026)'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3gNS9YpGxziNSglO1sX6tNhpcQ7mIm0Ix7K35cxUCghF0LfFa0-1k38yTjgTBtv75Le3XbnBZLyStbFieRMjyqPJ4kS9RJFNd-EIx6puLDhy3-uz3Uyf0CJ75xTfDk5r-ygXFRky3uZCMLucvtxs8gq7GkumiLFlk4NWoPTO3sr7xCb0s2U4rBX9WsMc/s72-c/SonarQube.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-3355302448010061912</id><published>2026-08-06T16:32:45.785+05:30</published><updated>2026-08-06T16:32:45.785+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure Data Factory Connectors"/><title type='text'>Azure Data Factory Connectors</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgobldmsB1mKdABmA9Q1oC47MI1580uQT4K7kxUX0J8ytREQLqLq9A1SgYzO2JkSY7rMgh5to-0bW0IvDLDGuzh1rMnA9r8ZtNxFR3b0YclxqRCQl5sgmf948c1yieC8LyHzBqaLYk_B_ziwY8bCPwI2nr0pazOOJXDUDnkzz5tyM8b43nCfsf1C4T9F18/s1536/AzureDataFactory.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgobldmsB1mKdABmA9Q1oC47MI1580uQT4K7kxUX0J8ytREQLqLq9A1SgYzO2JkSY7rMgh5to-0bW0IvDLDGuzh1rMnA9r8ZtNxFR3b0YclxqRCQl5sgmf948c1yieC8LyHzBqaLYk_B_ziwY8bCPwI2nr0pazOOJXDUDnkzz5tyM8b43nCfsf1C4T9F18/s320/AzureDataFactory.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h1&gt;Azure Data Factory Connectors: A Complete Guide with Real-Time Examples&lt;/h1&gt;&lt;h2&gt;Introduction&lt;/h2&gt;&lt;p&gt;One of the biggest strengths of &lt;strong&gt;Azure Data Factory (ADF)&lt;/strong&gt; is its ability to connect to hundreds of different data sources without requiring custom integration code.&lt;/p&gt;&lt;p&gt;Whether your data is stored in:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SQL Server&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Oracle&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SAP&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;AWS S3&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Salesforce&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;REST APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Snowflake&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;MongoDB&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;PostgreSQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;MySQL&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Azure Data Factory provides built-in &lt;strong&gt;Connectors&lt;/strong&gt; that make it easy to move and transform data.&lt;/p&gt;&lt;p&gt;Think of a connector as a &lt;strong&gt;bridge&lt;/strong&gt; between Azure Data Factory and an external data source or destination.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;What is an Azure Data Factory Connector?&lt;/h1&gt;&lt;p&gt;A connector is a built-in component that enables Azure Data Factory to communicate with external systems.&lt;/p&gt;&lt;p&gt;Without connectors, developers would have to write custom code to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Authenticate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Read data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Write data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Handle errors&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Manage connections&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;ADF connectors eliminate this complexity by providing a standardized way to access data.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;How Connectors Work&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;          Azure Data Factory
                 │
      ------------------------
      │                      │
 Source Connector      Destination Connector
      │                      │
 SQL Server            Azure SQL Database
 Oracle                Azure Blob Storage
 REST API              Azure Data Lake
 SAP                   Synapse Analytics
 Salesforce            Snowflake
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A connector can act as both a &lt;strong&gt;Source&lt;/strong&gt; (reading data) and a &lt;strong&gt;Sink&lt;/strong&gt; (writing data), depending on the service.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Types of Connectors&lt;/h1&gt;&lt;p&gt;Azure Data Factory categorizes connectors into several groups.&lt;/p&gt;&lt;h2&gt;1. Azure Connectors&lt;/h2&gt;&lt;p&gt;These connect to Azure-native services.&lt;/p&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure SQL Database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Blob Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Data Lake Storage Gen2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Synapse Analytics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Cosmos DB&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Table Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Files&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure SQL Managed Instance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Database for PostgreSQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Database for MySQL&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;A retail company stores invoices in Azure Blob Storage.&lt;/p&gt;&lt;p&gt;ADF reads invoice files from Blob Storage and loads them into Azure SQL Database for reporting.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;2. Database Connectors&lt;/h2&gt;&lt;p&gt;Used to connect to relational databases.&lt;/p&gt;&lt;p&gt;Supported databases include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SQL Server&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Oracle&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;MySQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;PostgreSQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;IBM DB2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SAP HANA&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;MariaDB&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Teradata&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Vertica&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Informix&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sybase&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;A bank stores customer accounts in Oracle.&lt;/p&gt;&lt;p&gt;ADF copies customer information every night into Azure Synapse Analytics.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;3. File-Based Connectors&lt;/h2&gt;&lt;p&gt;Used for files stored on-premises or in the cloud.&lt;/p&gt;&lt;p&gt;Supported formats include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;CSV&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Excel&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JSON&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;XML&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Parquet&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avro&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ORC&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Text files&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Storage Locations&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Local File System&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Blob Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ADLS Gen2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Amazon S3&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Google Cloud Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;FTP&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SFTP&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;Every hour, an SFTP server receives supplier CSV files.&lt;/p&gt;&lt;p&gt;ADF automatically:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Reads the files.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validates the data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Loads it into Azure SQL Database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Archives the processed files.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr /&gt;&lt;h2&gt;4. Cloud Storage Connectors&lt;/h2&gt;&lt;p&gt;ADF integrates with multiple cloud storage providers.&lt;/p&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Blob Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Data Lake Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Amazon S3&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Google Cloud Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Oracle Cloud Storage&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;A company migrating from AWS to Azure uses ADF to copy files from Amazon S3 to Azure Data Lake Storage.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;5. SaaS Application Connectors&lt;/h2&gt;&lt;p&gt;ADF supports popular Software-as-a-Service applications.&lt;/p&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Salesforce&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dynamics 365&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ServiceNow&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;HubSpot&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Marketo&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Shopify&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;A sales organization pulls Salesforce opportunity data every night into Azure Synapse for executive dashboards.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;6. ERP Connectors&lt;/h2&gt;&lt;p&gt;Enterprise Resource Planning systems are common in large organizations.&lt;/p&gt;&lt;p&gt;Supported systems include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SAP ECC&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SAP S/4HANA&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SAP BW&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SAP HANA&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;A manufacturing company extracts purchase orders from SAP every hour and loads them into a data warehouse for analytics.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;7. CRM Connectors&lt;/h2&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Dynamics 365&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Salesforce&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Zoho CRM&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;Marketing teams synchronize customer information from Dynamics 365 into Azure SQL for campaign analysis.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;8. Big Data Connectors&lt;/h2&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Apache Hive&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Apache HBase&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Apache Spark&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Databricks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Snowflake&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;ADF orchestrates a pipeline that copies raw IoT data to Azure Data Lake, triggers an Azure Databricks notebook for processing, and stores the results in Snowflake.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;9. API Connectors&lt;/h2&gt;&lt;p&gt;ADF can integrate with RESTful web services.&lt;/p&gt;&lt;p&gt;Supported APIs:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;REST APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;OData&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;HTTP endpoints&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;GraphQL (through HTTP/REST patterns)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;An e-commerce application exposes order data through a REST API.&lt;/p&gt;&lt;p&gt;ADF retrieves new orders every 30 minutes and stores them in Azure SQL Database.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;10. Messaging Connectors&lt;/h2&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Service Bus&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Event Hubs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kafka (typically integrated through compatible services or custom approaches)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;An online shopping application sends order events to Azure Event Hubs. ADF orchestrates downstream processing and stores aggregated data for reporting.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Commonly Used Enterprise Connectors&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Connector&lt;/th&gt;&lt;th&gt;Source&lt;/th&gt;&lt;th&gt;Destination&lt;/th&gt;&lt;th&gt;Common Use Case&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;SQL Server&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Transactional databases&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure SQL Database&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Cloud relational data&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Oracle&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Banking and ERP systems&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure Blob Storage&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;File storage&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ADLS Gen2&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Data lakes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Amazon S3&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Multi-cloud migration&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Salesforce&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;CRM data&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;REST API&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Third-party integrations&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SAP&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Enterprise ERP&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Snowflake&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Cloud data warehouse&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;PostgreSQL&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Open-source databases&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;MySQL&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;✔&lt;/td&gt;&lt;td&gt;Web applications&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;How ADF Uses a Connector&lt;/h1&gt;&lt;p&gt;Suppose you need to move customer data from SQL Server to Azure SQL Database.&lt;/p&gt;&lt;h3&gt;Step 1: Create a Linked Service&lt;/h3&gt;&lt;p&gt;Source:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;SQL Server
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Destination:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Azure SQL Database
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Step 2: Create Datasets&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;Customer Table

↓

Azure SQL Customer Table
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Step 3: Create a Copy Activity&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;Source Dataset

↓

Copy Activity

↓

Destination Dataset
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Step 4: Publish and Run&lt;/h3&gt;&lt;p&gt;ADF automatically:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Connects to SQL Server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reads the customer records.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Transfers the data securely.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Writes the data to Azure SQL Database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Logs execution details for monitoring.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;No custom coding is required for the data movement.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Authentication Methods Supported by Connectors&lt;/h1&gt;&lt;p&gt;Different connectors support different authentication mechanisms, including:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SQL Authentication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Windows Authentication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Active Directory (Microsoft Entra ID)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Managed Identity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Service Principal&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Shared Access Signature (SAS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Storage Account Keys&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;OAuth 2.0&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Anonymous Access (where applicable)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Use &lt;strong&gt;Managed Identity&lt;/strong&gt; or &lt;strong&gt;Microsoft Entra ID&lt;/strong&gt; whenever possible, and store secrets securely in &lt;strong&gt;Azure Key Vault&lt;/strong&gt; instead of embedding credentials.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Best Practices for Using Connectors&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use parameterized Linked Services to avoid duplication.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Store secrets in Azure Key Vault.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use Self-hosted Integration Runtime for on-premises systems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Prefer Managed Identity for Azure resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configure retries for transient network failures.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enable monitoring and alerting for production pipelines.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose Incremental Loads over Full Loads for large datasets.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validate connectivity before deploying to production.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Real Enterprise Scenario&lt;/h1&gt;&lt;p&gt;A multinational retail company needs to integrate data from several systems:&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;System&lt;/th&gt;&lt;th&gt;Connector&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;SQL Server&lt;/td&gt;&lt;td&gt;SQL Server Connector&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SAP&lt;/td&gt;&lt;td&gt;SAP Connector&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Salesforce&lt;/td&gt;&lt;td&gt;Salesforce Connector&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Oracle&lt;/td&gt;&lt;td&gt;Oracle Connector&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Amazon S3&lt;/td&gt;&lt;td&gt;Amazon S3 Connector&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure Blob Storage&lt;/td&gt;&lt;td&gt;Azure Blob Connector&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;REST APIs&lt;/td&gt;&lt;td&gt;REST Connector&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Azure Synapse Analytics&lt;/td&gt;&lt;td&gt;Synapse Connector&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;strong&gt;Workflow:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code&gt;SQL Server
     │
Oracle
     │
SAP
     │
Salesforce
     │
Amazon S3
     │
REST APIs
     │
Azure Data Factory
     │
Data Validation
     │
Azure Data Lake
     │
Azure Synapse Analytics
     │
Power BI Dashboard
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This architecture enables a single, automated data integration platform that powers enterprise reporting, analytics, and machine learning while reducing manual effort and improving reliability.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Azure Data Factory connectors are the backbone of modern cloud data integration. They allow organizations to connect to a wide variety of on-premises, cloud, SaaS, and enterprise systems without writing complex integration code. By combining connectors with pipelines, activities, and Integration Runtime, organizations can build secure, scalable, and automated data workflows that support business intelligence, analytics, and AI initiatives.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/3355302448010061912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/3355302448010061912' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/3355302448010061912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/3355302448010061912'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/azure-data-factory-connectors.html' title='Azure Data Factory Connectors'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgobldmsB1mKdABmA9Q1oC47MI1580uQT4K7kxUX0J8ytREQLqLq9A1SgYzO2JkSY7rMgh5to-0bW0IvDLDGuzh1rMnA9r8ZtNxFR3b0YclxqRCQl5sgmf948c1yieC8LyHzBqaLYk_B_ziwY8bCPwI2nr0pazOOJXDUDnkzz5tyM8b43nCfsf1C4T9F18/s72-c/AzureDataFactory.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-4811782388804276796</id><published>2026-08-06T16:25:57.007+05:30</published><updated>2026-08-06T16:34:03.986+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ADF"/><category scheme="http://www.blogger.com/atom/ns#" term="Azure Data Factory"/><title type='text'>Azure Data Factory (ADF) : A Complete Guide with Real-Time Examples</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqY-hyZed69a_cftdDjOQNW54KGvcu88U68ue13iha6bdPcnbysOCLlOMZq_51Zoh09lvprJh-ZJsb3_92PBsIEtvd4Lm_tEzqWuxf81uacMKZ6Aqxu7bqe0eInJjnm_G9xsIlGSg5cxU-XAubaNl8pmm-RagCtT8ObtBG-c6hbEV-sHJRnfUnPJFpwXg/s1536/AzureDataFactory.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqY-hyZed69a_cftdDjOQNW54KGvcu88U68ue13iha6bdPcnbysOCLlOMZq_51Zoh09lvprJh-ZJsb3_92PBsIEtvd4Lm_tEzqWuxf81uacMKZ6Aqxu7bqe0eInJjnm_G9xsIlGSg5cxU-XAubaNl8pmm-RagCtT8ObtBG-c6hbEV-sHJRnfUnPJFpwXg/s320/AzureDataFactory.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h1&gt;Working with Azure Data Factory (ADF): A Complete Guide with Real-Time Examples&lt;/h1&gt;&lt;h2&gt;Introduction&lt;/h2&gt;&lt;p&gt;In today&#39;s data-driven world, organizations collect data from multiple sources such as SQL databases, ERP systems, CRM applications, APIs, IoT devices, cloud storage, and third-party applications. However, collecting data is only the first step. The real challenge is moving, transforming, validating, and loading that data into a centralized repository for reporting, analytics, and machine learning.&lt;/p&gt;&lt;p&gt;This is where &lt;strong&gt;Azure Data Factory (ADF)&lt;/strong&gt; comes into the picture.&lt;/p&gt;&lt;p&gt;Azure Data Factory is Microsoft&#39;s cloud-based data integration service that enables you to create, schedule, automate, and monitor data pipelines without writing large amounts of custom code.&lt;/p&gt;&lt;p&gt;In this article, we&#39;ll explore Azure Data Factory in detail, understand its architecture, components, and work through real-world enterprise examples.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;What is Azure Data Factory?&lt;/h1&gt;&lt;p&gt;Azure Data Factory (ADF) is a cloud ETL (Extract, Transform, Load) and ELT (Extract, Load, Transform) service provided by Microsoft Azure.&lt;/p&gt;&lt;p&gt;It allows organizations to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Move data between systems&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Transform data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Schedule workflows&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automate data processing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integrate on-premises and cloud data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Build enterprise-grade data pipelines&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Think of Azure Data Factory as the &lt;strong&gt;orchestrator&lt;/strong&gt; of your data ecosystem.&lt;/p&gt;&lt;p&gt;Instead of manually copying files every day, ADF automates everything.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Why Do We Need Azure Data Factory?&lt;/h1&gt;&lt;p&gt;Consider a retail company.&lt;/p&gt;&lt;p&gt;Every day data is generated from:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Sales Database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Inventory Database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SAP ERP&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;CRM&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Excel Files&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;CSV Files&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Blob Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Amazon S3&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Oracle Database&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Management wants a dashboard every morning.&lt;/p&gt;&lt;p&gt;Without ADF:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Developers manually write scripts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Jobs fail frequently&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;No monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Difficult maintenance&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With ADF:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Automated pipelines&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Error handling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Alerts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Scheduling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Scalability&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Azure Data Factory Architecture&lt;/h1&gt;&lt;pre&gt;&lt;code&gt;                SQL Server
                     |
                Oracle DB
                     |
                REST APIs
                     |
             Azure Blob Storage
                     |
             Amazon S3 Storage
                     |
          ------------------------
          | Azure Data Factory |
          ------------------------
             /      |       \
      Copy Data  Transform  Monitor
           |         |         |
        Azure SQL  Databricks  Logs
           |
     Power BI Reports
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ADF acts as the central orchestrator.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Core Components of Azure Data Factory&lt;/h1&gt;&lt;h2&gt;1. Pipeline&lt;/h2&gt;&lt;p&gt;A Pipeline is a logical grouping of activities.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Read CSV

Validate Data

Transform Data

Load into Azure SQL

Send Email
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;All these activities together form one pipeline.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;2. Activity&lt;/h2&gt;&lt;p&gt;Activities are individual tasks.&lt;/p&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Copy Activity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Lookup Activity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Stored Procedure Activity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Data Flow Activity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Execute Pipeline&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Web Activity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Function Activity&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Think of activities as individual functions inside a program.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;3. Linked Service&lt;/h2&gt;&lt;p&gt;Linked Service stores connection information.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Azure SQL Connection

Server:
company.database.windows.net

Database:
SalesDB

Username

Password
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ADF uses Linked Services to connect to data sources.&lt;/p&gt;&lt;p&gt;Supported sources include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure SQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL Server&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Oracle&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SAP&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Blob Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ADLS&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Snowflake&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Amazon S3&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;REST APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;MySQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;PostgreSQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;MongoDB&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;4. Dataset&lt;/h2&gt;&lt;p&gt;Dataset represents the data you want to use.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Sales.csv

Customer Table

Blob Folder

Excel File
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Linked Service = Connection&lt;/p&gt;&lt;p&gt;Dataset = Actual Data&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;5. Integration Runtime (IR)&lt;/h2&gt;&lt;p&gt;Integration Runtime is the compute engine that moves data.&lt;/p&gt;&lt;p&gt;Three types:&lt;/p&gt;&lt;h3&gt;Azure Integration Runtime&lt;/h3&gt;&lt;p&gt;For cloud-to-cloud data movement.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;p&gt;Azure Blob → Azure SQL&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Self-hosted Integration Runtime&lt;/h3&gt;&lt;p&gt;Used when data is inside your company network.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;p&gt;On-Prem SQL Server → Azure SQL&lt;/p&gt;&lt;p&gt;Install Self-hosted IR on a local server.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Azure SSIS Integration Runtime&lt;/h3&gt;&lt;p&gt;Used for running existing SSIS packages in Azure.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;ETL vs ELT&lt;/h1&gt;&lt;h2&gt;ETL&lt;/h2&gt;&lt;pre&gt;&lt;code&gt;Extract

↓

Transform

↓

Load
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Transformation happens before loading.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;ELT&lt;/h2&gt;&lt;pre&gt;&lt;code&gt;Extract

↓

Load

↓

Transform
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Transformation happens after loading.&lt;/p&gt;&lt;p&gt;Azure Data Factory supports both.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Real-Time Example 1&lt;/h1&gt;&lt;h2&gt;Daily Sales Data Migration&lt;/h2&gt;&lt;p&gt;Company:&lt;/p&gt;&lt;p&gt;ABC Retail&lt;/p&gt;&lt;p&gt;Requirement:&lt;/p&gt;&lt;p&gt;Every night:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Read Sales data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Remove duplicates&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Load into Data Warehouse&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Pipeline:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Trigger

↓

Copy Sales Data

↓

Data Flow

↓

Remove Duplicates

↓

Load Azure SQL

↓

Success Email
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Result:&lt;/p&gt;&lt;p&gt;Automated daily process.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Real-Time Example 2&lt;/h1&gt;&lt;h2&gt;Banking Industry&lt;/h2&gt;&lt;p&gt;Every night:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Customer Accounts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Transactions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Loan Data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Credit Card Data&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Need to move into Data Warehouse.&lt;/p&gt;&lt;p&gt;Pipeline:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Oracle

↓

ADF Copy

↓

Azure Data Lake

↓

Databricks

↓

Azure Synapse

↓

Power BI
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Real-Time Example 3&lt;/h1&gt;&lt;h2&gt;Healthcare&lt;/h2&gt;&lt;p&gt;Hospitals receive:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Patient Records&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Laboratory Results&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pharmacy Data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Insurance Data&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;ADF:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;SQL Server

↓

Validate

↓

Encrypt Sensitive Columns

↓

Store in Data Lake

↓

Analytics
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Real-Time Example 4&lt;/h1&gt;&lt;h2&gt;E-Commerce&lt;/h2&gt;&lt;p&gt;Every hour:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Orders&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Payments&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Delivery Status&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Pipeline:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;REST API

↓

ADF

↓

Blob Storage

↓

Azure SQL

↓

Dashboard
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Copy Activity&lt;/h1&gt;&lt;p&gt;Most commonly used activity.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;p&gt;Source:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;SQL Server
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Destination:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Azure Blob Storage
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ADF copies data without writing code.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Data Flow&lt;/h1&gt;&lt;p&gt;Data Flow performs transformations visually.&lt;/p&gt;&lt;p&gt;Operations include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Filter&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sort&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Join&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Aggregate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Derived Columns&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Lookup&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Union&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pivot&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Unpivot&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Conditional Split&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Window Functions&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;No coding required.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Parameters in Pipeline&lt;/h1&gt;&lt;p&gt;Instead of hardcoding values:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Customer2025.csv
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;@pipeline().parameters.FileName
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the same pipeline works for:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Customer2024.csv

Customer2025.csv

Customer2026.csv
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Variables&lt;/h1&gt;&lt;p&gt;Variables store temporary values.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;CurrentDate

FileCount

Status

RowCount
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Control Flow Activities&lt;/h1&gt;&lt;p&gt;ADF provides many workflow activities:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;If Condition&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Switch&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Until&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ForEach&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Wait&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Execute Pipeline&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fail&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;If File Exists

↓

Copy

Else

Send Email
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Triggers&lt;/h1&gt;&lt;p&gt;Pipelines can execute automatically.&lt;/p&gt;&lt;p&gt;Types:&lt;/p&gt;&lt;h3&gt;Schedule Trigger&lt;/h3&gt;&lt;p&gt;Run every day.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Daily 2 AM
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Tumbling Window&lt;/h3&gt;&lt;p&gt;Useful for time-series processing.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Event Trigger&lt;/h3&gt;&lt;p&gt;Automatically executes when a new file arrives.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Customer.csv uploaded

↓

Pipeline Starts
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Monitoring&lt;/h1&gt;&lt;p&gt;ADF provides monitoring dashboards showing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Running Pipelines&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Failed Pipelines&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Duration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Success Rate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Retry Count&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Error Messages&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Alerts can be integrated with Azure Monitor.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Security&lt;/h1&gt;&lt;p&gt;ADF supports enterprise-grade security:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Managed Identity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;RBAC&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Private Endpoints&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Encryption at Rest&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Encryption in Transit&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Avoid storing passwords directly in Linked Services. Use Azure Key Vault whenever possible.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Best Practices&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use parameterized pipelines.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Separate development, testing, and production environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Store secrets in Azure Key Vault.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement retry policies for transient failures.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enable monitoring and alerts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use naming conventions for pipelines and datasets.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Optimize parallelism for large data loads.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use Incremental Loading instead of Full Loading whenever possible.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Real Enterprise Scenario&lt;/h1&gt;&lt;p&gt;A multinational retail company receives:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;500 CSV files daily&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SAP data every hour&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Oracle data every night&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;CRM data through REST APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQL Server transactions every 30 minutes&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;ADF orchestrates the process:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Blob Storage
        │
Oracle DB
        │
SQL Server
        │
REST API
        │
SAP
        │
   Azure Data Factory
        │
    Validation
        │
 Azure Data Lake
        │
 Azure Databricks
        │
 Azure Synapse Analytics
        │
     Power BI
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Business users start their day with up-to-date dashboards, while data engineers benefit from automated, monitored, and scalable pipelines.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Advantages of Azure Data Factory&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Fully managed cloud service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;No infrastructure maintenance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Visual pipeline designer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Supports 100+ connectors&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Highly scalable&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enterprise-grade security&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Built-in scheduling and monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Easy integration with Azure services&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Supports hybrid cloud environments&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Common Interview Questions&lt;/h1&gt;&lt;h3&gt;What is Azure Data Factory?&lt;/h3&gt;&lt;p&gt;Azure Data Factory is a cloud-based data integration service that automates data movement and transformation across cloud and on-premises systems.&lt;/p&gt;&lt;h3&gt;What is a Pipeline?&lt;/h3&gt;&lt;p&gt;A pipeline is a logical container that groups one or more activities into a complete workflow.&lt;/p&gt;&lt;h3&gt;What is the difference between Linked Service and Dataset?&lt;/h3&gt;&lt;p&gt;A Linked Service defines the connection to a data source, while a Dataset represents the specific data (such as a table, file, or folder) within that source.&lt;/p&gt;&lt;h3&gt;What is Integration Runtime?&lt;/h3&gt;&lt;p&gt;Integration Runtime is the compute infrastructure used by Azure Data Factory to move and transform data. It is available as Azure Integration Runtime, Self-hosted Integration Runtime, and Azure SSIS Integration Runtime.&lt;/p&gt;&lt;h3&gt;What is the difference between ETL and ELT?&lt;/h3&gt;&lt;p&gt;ETL transforms data before loading it into the destination. ELT loads raw data first and performs transformations afterward, typically using the compute capabilities of the target system.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Azure Data Factory is one of the most powerful cloud-native data integration services available today. It enables organizations to build secure, scalable, and automated data pipelines that connect virtually any data source to modern analytics platforms. Whether you&#39;re migrating on-premises databases, orchestrating enterprise ETL workflows, integrating SaaS applications, or feeding business intelligence dashboards, ADF simplifies the entire process with minimal code and rich monitoring capabilities.&lt;/p&gt;&lt;p&gt;For modern data engineering teams working in Azure, Azure Data Factory is a foundational service that plays a key role in building reliable and enterprise-ready data platforms.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://umamaheswarb.blogspot.com/2026/08/azure-data-factory-connectors.html&quot; target=&quot;_blank&quot;&gt;Azure Data Factory Connectors&lt;/a&gt;&lt;/h2&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/4811782388804276796/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/4811782388804276796' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/4811782388804276796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/4811782388804276796'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/azure-data-factory.html' title='Azure Data Factory (ADF) : A Complete Guide with Real-Time Examples'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqY-hyZed69a_cftdDjOQNW54KGvcu88U68ue13iha6bdPcnbysOCLlOMZq_51Zoh09lvprJh-ZJsb3_92PBsIEtvd4Lm_tEzqWuxf81uacMKZ6Aqxu7bqe0eInJjnm_G9xsIlGSg5cxU-XAubaNl8pmm-RagCtT8ObtBG-c6hbEV-sHJRnfUnPJFpwXg/s72-c/AzureDataFactory.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-7830851850344560553</id><published>2026-08-06T10:35:49.080+05:30</published><updated>2026-08-06T10:35:49.081+05:30</updated><title type='text'>How to Remove Duplicate Values from an Array in C#</title><content type='html'>&lt;h1 style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/h1&gt;&lt;h1 style=&quot;text-align: left;&quot;&gt;How to Remove Duplicate Values from an Array in C# – 6 Best Approaches with Examples&lt;/h1&gt;&lt;p&gt;Removing duplicate values from an array is one of the most common tasks in C# programming. Whether you&#39;re processing user input, reading data from a database, or preparing data for reports, eliminating duplicate values improves data quality and application performance.&lt;/p&gt;&lt;p&gt;In this article, we&#39;ll explore multiple ways to remove duplicate values from an array in C#, ranging from beginner-friendly approaches to optimized solutions suitable for production applications and technical interviews.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Problem Statement&lt;/h1&gt;&lt;p&gt;Suppose we have the following array:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;int[] iArray = new int[] { 1, 1, 2, 2, 3, 3, 4, 5, 6, 6 };
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Expected Output&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1, 2, 3, 4, 5, 6
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Method 1: Using LINQ Distinct() (Recommended)&lt;/h1&gt;&lt;p&gt;The easiest and most readable approach is to use LINQ&#39;s &lt;code inline=&quot;&quot;&gt;Distinct()&lt;/code&gt; method.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] iArray = { 1, 1, 2, 2, 3, 3, 4, 5, 6, 6 };

        int[] uniqueArray = iArray.Distinct().ToArray();

        Console.WriteLine(string.Join(&quot;, &quot;, uniqueArray));
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Output&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1, 2, 3, 4, 5, 6
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Advantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Very easy to write&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Highly readable&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Excellent for production code&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Preserves the first occurrence order&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Disadvantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Requires LINQ&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Slightly more memory usage than in-place algorithms&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n)&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Space Complexity:&lt;/strong&gt; O(n)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Method 2: Using HashSet (Fastest)&lt;/h1&gt;&lt;p&gt;A &lt;code inline=&quot;&quot;&gt;HashSet&amp;lt;T&amp;gt;&lt;/code&gt; stores only unique values. Any duplicate values are automatically ignored.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] iArray = { 1, 1, 2, 2, 3, 3, 4, 5, 6, 6 };

        HashSet&amp;lt;int&amp;gt; uniqueNumbers = new HashSet&amp;lt;int&amp;gt;(iArray);

        foreach (int item in uniqueNumbers)
        {
            Console.Write(item + &quot; &quot;);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Output&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1 2 3 4 5 6
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Advantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Extremely fast&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automatically removes duplicates&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Excellent for large collections&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Disadvantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Uses additional memory&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Order is not guaranteed in all scenarios&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n)&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Space Complexity:&lt;/strong&gt; O(n)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Method 3: Using List Without LINQ&lt;/h1&gt;&lt;p&gt;This approach is useful for beginners or interview situations where LINQ is not allowed.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] iArray = { 1, 1, 2, 2, 3, 3, 4, 5, 6, 6 };

        List&amp;lt;int&amp;gt; result = new List&amp;lt;int&amp;gt;();

        foreach (int item in iArray)
        {
            if (!result.Contains(item))
            {
                result.Add(item);
            }
        }

        Console.WriteLine(string.Join(&quot;, &quot;, result));
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Advantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Easy to understand&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;No LINQ dependency&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Disadvantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;Contains()&lt;/code&gt; performs a linear search&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Not suitable for large datasets&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n²)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Method 4: Using Dictionary&lt;/h1&gt;&lt;p&gt;A dictionary can also be used to keep track of values that have already been processed.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] iArray = { 1, 1, 2, 2, 3, 3, 4, 5, 6, 6 };

        Dictionary&amp;lt;int, bool&amp;gt; dictionary = new Dictionary&amp;lt;int, bool&amp;gt;();

        foreach (int item in iArray)
        {
            if (!dictionary.ContainsKey(item))
            {
                dictionary.Add(item, true);
            }
        }

        foreach (var item in dictionary.Keys)
        {
            Console.Write(item + &quot; &quot;);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Advantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Fast lookup&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Good alternative to &lt;code inline=&quot;&quot;&gt;HashSet&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Disadvantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Stores unnecessary values (&lt;code inline=&quot;&quot;&gt;bool&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;More verbose than &lt;code inline=&quot;&quot;&gt;HashSet&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Method 5: Using Nested Loops (Without Collections)&lt;/h1&gt;&lt;p&gt;This method is frequently asked during coding interviews because it demonstrates your understanding of the logic without relying on built-in collection classes.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System;

class Program
{
    static void Main()
    {
        int[] iArray = { 1, 1, 2, 2, 3, 3, 4, 5, 6, 6 };

        for (int i = 0; i &amp;lt; iArray.Length; i++)
        {
            bool duplicate = false;

            for (int j = 0; j &amp;lt; i; j++)
            {
                if (iArray[i] == iArray[j])
                {
                    duplicate = true;
                    break;
                }
            }

            if (!duplicate)
            {
                Console.Write(iArray[i] + &quot; &quot;);
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Advantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;No LINQ&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;No collections&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Demonstrates algorithmic thinking&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Disadvantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Slow for large datasets&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n²)&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Space Complexity:&lt;/strong&gt; O(1)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Method 6: Remove Consecutive Duplicates from a Sorted Array&lt;/h1&gt;&lt;p&gt;If the array is already sorted, you only need to compare each element with the previous one.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] iArray = { 1, 1, 2, 2, 3, 3, 4, 5, 6, 6 };

        List&amp;lt;int&amp;gt; result = new List&amp;lt;int&amp;gt;();

        if (iArray.Length &amp;gt; 0)
        {
            result.Add(iArray[0]);

            for (int i = 1; i &amp;lt; iArray.Length; i++)
            {
                if (iArray[i] != iArray[i - 1])
                {
                    result.Add(iArray[i]);
                }
            }
        }

        Console.WriteLine(string.Join(&quot;, &quot;, result));
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Advantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Very fast for sorted arrays&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Simple implementation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Disadvantages&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Works correctly only when duplicates are adjacent&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n)&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Performance Comparison&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;Time Complexity&lt;/th&gt;&lt;th&gt;Space Complexity&lt;/th&gt;&lt;th&gt;Best Use Case&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;LINQ Distinct()&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;General-purpose applications&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;HashSet&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;Large datasets and high performance&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;List + Contains()&lt;/td&gt;&lt;td&gt;O(n²)&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;Learning and small datasets&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Dictionary&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;Alternative to HashSet&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Nested Loops&lt;/td&gt;&lt;td&gt;O(n²)&lt;/td&gt;&lt;td&gt;O(1)&lt;/td&gt;&lt;td&gt;Coding interviews&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Sorted Array Comparison&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;Already sorted arrays&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;Real-World Use Cases&lt;/h1&gt;&lt;p&gt;Removing duplicates is useful in many real-world applications, including:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Removing duplicate customer IDs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Eliminating repeated product codes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cleaning imported CSV or Excel data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Processing unique email addresses&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generating distinct reports&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Removing duplicate API response records&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Preparing analytics data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Data migration and ETL processes&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Interview Questions&lt;/h1&gt;&lt;h3&gt;1. What is the easiest way to remove duplicates from an array in C#?&lt;/h3&gt;&lt;p&gt;Use &lt;code inline=&quot;&quot;&gt;Distinct()&lt;/code&gt; from LINQ.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;2. Which collection automatically removes duplicates?&lt;/h3&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;HashSet&amp;lt;T&amp;gt;&lt;/code&gt;.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;3. What is the complexity of &lt;code inline=&quot;&quot;&gt;Distinct()&lt;/code&gt;?&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Time Complexity: &lt;strong&gt;O(n)&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Space Complexity: &lt;strong&gt;O(n)&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h3&gt;4. Can we remove duplicates without using LINQ?&lt;/h3&gt;&lt;p&gt;Yes. We can use:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;HashSet&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dictionary&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;List&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Nested loops&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h3&gt;5. Which approach is preferred in production?&lt;/h3&gt;&lt;p&gt;For most applications:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;Distinct()&lt;/code&gt; for readability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code inline=&quot;&quot;&gt;HashSet&amp;lt;T&amp;gt;&lt;/code&gt; for maximum performance&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h3&gt;6. Which approach is commonly asked in coding interviews?&lt;/h3&gt;&lt;p&gt;The nested-loop solution is a popular interview question because it tests your understanding of algorithms without relying on built-in methods.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Best Practices&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use &lt;code inline=&quot;&quot;&gt;Distinct()&lt;/code&gt; for clean, readable, and maintainable code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use &lt;code inline=&quot;&quot;&gt;HashSet&amp;lt;T&amp;gt;&lt;/code&gt; when performance is critical.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid &lt;code inline=&quot;&quot;&gt;List.Contains()&lt;/code&gt; for large datasets because it results in quadratic time complexity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Understand the manual nested-loop solution for coding interviews.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose the approach that best matches your application&#39;s performance and readability requirements.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Removing duplicate values from an array is a common programming task in C#. The language offers several approaches, each with its own strengths.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use &lt;code inline=&quot;&quot;&gt;Distinct()&lt;/code&gt;&lt;/strong&gt; for simplicity and maintainability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use &lt;code inline=&quot;&quot;&gt;HashSet&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/strong&gt; for the best performance with large collections.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Learn the nested-loop solution&lt;/strong&gt; to strengthen your problem-solving skills for interviews.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Select the right approach&lt;/strong&gt; based on your application&#39;s size, performance requirements, and coding standards.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Mastering these techniques will help you write cleaner, more efficient C# code and prepare you for technical interviews with confidence.&lt;/p&gt;&lt;p&gt;If you&#39;d like, I can also create:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;an SEO-optimized version (targeting keywords like &lt;strong&gt;&quot;Remove Duplicates from Array in C#&quot;&lt;/strong&gt;),&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;a professional feature image/thumbnail,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;and schema-ready FAQ markup to improve your blog&#39;s Google search visibility.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/7830851850344560553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/7830851850344560553' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/7830851850344560553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/7830851850344560553'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/how-to-remove-duplicate-values-from.html' title='How to Remove Duplicate Values from an Array in C#'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-7935879653681456469</id><published>2026-08-05T20:07:42.853+05:30</published><updated>2026-08-05T20:07:42.853+05:30</updated><title type='text'>ROW_NUMBER(),  RANK(), DENSE_RANK(), NTILE(), PERCENT_RANK(), CUME_DIST() In Sql</title><content type='html'>&lt;h3 style=&quot;text-align: left;&quot;&gt;&amp;nbsp;SQL Window Ranking Functions – ROW_NUMBER(), RANK(), DENSE_RANK(), NTILE(), PERCENT_RANK(), CUME_DIST()&lt;/h3&gt;&lt;p&gt;These are &lt;strong&gt;Window Functions (Analytic Functions)&lt;/strong&gt; introduced in SQL Server to perform calculations across a set of rows without grouping them.&lt;/p&gt;&lt;p&gt;Unlike &lt;code inline=&quot;&quot;&gt;GROUP BY&lt;/code&gt;, window functions &lt;strong&gt;do not reduce the number of rows&lt;/strong&gt;. Every row remains in the result.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Why do we need Ranking Functions?&lt;/h1&gt;&lt;p&gt;Suppose you have an Employee table.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;Employee
-------------------------------------
EmpId | Name   | Department | Salary
-------------------------------------
1     | John   | IT         | 80000
2     | David  | IT         | 90000
3     | Smith  | IT         | 90000
4     | Alice  | HR         | 60000
5     | Bob    | HR         | 70000
6     | Mike   | HR         | 70000
7     | Tom    | Sales      | 50000
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Suppose interviewer asks&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Find highest salary employee.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Easy.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT *
FROM Employee
ORDER BY Salary DESC;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But what if interviewer asks&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Highest salary employee in each department&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Top 3 salaries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Second highest salary&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Remove duplicate records&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pagination&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Rank employees&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;That&#39;s where ranking functions are used.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Syntax&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;FunctionName()
OVER
(
    PARTITION BY column
    ORDER BY column
)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There are two important clauses.&lt;/p&gt;&lt;h2&gt;ORDER BY&lt;/h2&gt;&lt;p&gt;Mandatory.&lt;/p&gt;&lt;p&gt;Determines ranking order.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;ORDER BY Salary DESC
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;PARTITION BY&lt;/h2&gt;&lt;p&gt;Optional.&lt;/p&gt;&lt;p&gt;Splits data into groups before assigning ranks.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;PARTITION BY Department
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Means every department ranking starts from 1.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;1. ROW_NUMBER()&lt;/h1&gt;&lt;p&gt;Assigns a unique sequential number to every row.&lt;/p&gt;&lt;p&gt;Even if salaries are equal,&lt;br /&gt;numbers are different.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
Name,
Salary,
ROW_NUMBER() OVER(ORDER BY Salary DESC) AS RowNum
FROM Employee;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Output&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Salary&lt;/th&gt;&lt;th&gt;ROW_NUMBER&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;David&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Smith&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;John&lt;/td&gt;&lt;td&gt;80000&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Bob&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Mike&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Alice&lt;/td&gt;&lt;td&gt;60000&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Tom&lt;/td&gt;&lt;td&gt;50000&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Notice&lt;/p&gt;&lt;p&gt;David and Smith have same salary.&lt;/p&gt;&lt;p&gt;Still&lt;/p&gt;&lt;pre&gt;&lt;code&gt;1
2
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;No ties.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Real-world use&lt;/h2&gt;&lt;h3&gt;Pagination&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH CTE AS
(
SELECT *,
ROW_NUMBER() OVER(ORDER BY EmpId) RN
FROM Employee
)

SELECT *
FROM CTE
WHERE RN BETWEEN 11 AND 20;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This returns page 2.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Remove duplicates&lt;/h3&gt;&lt;p&gt;Suppose duplicate emails exist.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH CTE AS
(
SELECT *,
ROW_NUMBER()
OVER(PARTITION BY Email ORDER BY EmpId) RN
FROM Customer
)

DELETE FROM CTE
WHERE RN&amp;gt;1;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Very common interview question.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. RANK()&lt;/h1&gt;&lt;p&gt;Assigns same rank to equal values.&lt;/p&gt;&lt;p&gt;But skips next rank.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
Name,
Salary,
RANK() OVER(ORDER BY Salary DESC) RankNo
FROM Employee;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Output&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Salary&lt;/th&gt;&lt;th&gt;Rank&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;David&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Smith&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;John&lt;/td&gt;&lt;td&gt;80000&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Bob&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Mike&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Alice&lt;/td&gt;&lt;td&gt;60000&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Tom&lt;/td&gt;&lt;td&gt;50000&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Notice&lt;/p&gt;&lt;pre&gt;&lt;code&gt;1
1
3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Rank 2 is skipped.&lt;/p&gt;&lt;p&gt;Because two employees share rank 1.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Visualization&lt;/h2&gt;&lt;pre&gt;&lt;code&gt;90000
David     Rank 1

90000
Smith     Rank 1

80000
John      Rank 3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Rank 2 missing.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Use Case&lt;/h2&gt;&lt;p&gt;Sports Competition&lt;/p&gt;&lt;pre&gt;&lt;code&gt;100 Marks
Student A

100 Marks
Student B

95 Marks
Student C
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Ranks&lt;/p&gt;&lt;pre&gt;&lt;code&gt;1
1
3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Exactly like Olympics.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. DENSE_RANK()&lt;/h1&gt;&lt;p&gt;Similar to RANK()&lt;/p&gt;&lt;p&gt;But&lt;/p&gt;&lt;p&gt;No gaps.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
Name,
Salary,
DENSE_RANK()
OVER(ORDER BY Salary DESC)
AS DenseRank
FROM Employee;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Output&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Salary&lt;/th&gt;&lt;th&gt;Dense Rank&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;David&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Smith&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;John&lt;/td&gt;&lt;td&gt;80000&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Bob&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Mike&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Alice&lt;/td&gt;&lt;td&gt;60000&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Tom&lt;/td&gt;&lt;td&gt;50000&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Notice&lt;/p&gt;&lt;pre&gt;&lt;code&gt;1
1
2
3
3
4
5
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;No skipped numbers.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Visualization&lt;/h2&gt;&lt;pre&gt;&lt;code&gt;90000
David     1

90000
Smith     1

80000
John      2

70000
Bob       3

70000
Mike      3
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Difference between ROW_NUMBER(), RANK(), DENSE_RANK()&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Salary&lt;/th&gt;&lt;th&gt;ROW_NUMBER&lt;/th&gt;&lt;th&gt;RANK&lt;/th&gt;&lt;th&gt;DENSE_RANK&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;80000&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;60000&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;Visual Difference&lt;/h1&gt;&lt;pre&gt;&lt;code&gt;ROW_NUMBER()

90000   1
90000   2
80000   3
70000   4
70000   5
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;pre&gt;&lt;code&gt;RANK()

90000   1
90000   1
80000   3
70000   4
70000   4
60000   6
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;pre&gt;&lt;code&gt;DENSE_RANK()

90000   1
90000   1
80000   2
70000   3
70000   3
60000   4
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Which one should you use?&lt;/h1&gt;&lt;h3&gt;Need unique row number?&lt;/h3&gt;&lt;p&gt;Use&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;ROW_NUMBER()
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Examples&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Pagination&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Duplicate removal&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Unique numbering&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;p&gt;Need competition ranking?&lt;/p&gt;&lt;p&gt;Use&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;RANK()
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Examples&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Sports&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Exam Ranking&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;p&gt;Need consecutive ranking?&lt;/p&gt;&lt;p&gt;Use&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;DENSE_RANK()
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Examples&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Top N salaries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Product Ranking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Customer Ranking&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;PARTITION BY Example&lt;/h1&gt;&lt;p&gt;Suppose&lt;/p&gt;&lt;pre&gt;&lt;code&gt;IT

John    80000
David   90000
Smith   90000

HR

Alice   60000
Bob     70000
Mike    70000
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
Department,
Name,
Salary,
DENSE_RANK()
OVER
(
PARTITION BY Department
ORDER BY Salary DESC
)
AS Rank
FROM Employee;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Output&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Dept&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Salary&lt;/th&gt;&lt;th&gt;Rank&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;IT&lt;/td&gt;&lt;td&gt;David&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;IT&lt;/td&gt;&lt;td&gt;Smith&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;IT&lt;/td&gt;&lt;td&gt;John&lt;/td&gt;&lt;td&gt;80000&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;HR&lt;/td&gt;&lt;td&gt;Bob&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;HR&lt;/td&gt;&lt;td&gt;Mike&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;HR&lt;/td&gt;&lt;td&gt;Alice&lt;/td&gt;&lt;td&gt;60000&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Notice ranking restarts for every department.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;4. NTILE()&lt;/h1&gt;&lt;p&gt;Splits rows into equal-sized groups (buckets).&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
Name,
Salary,
NTILE(4)
OVER(ORDER BY Salary DESC)
AS Quartile
FROM Employee;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If there are 20 rows,&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Quartile 1

Top 25%

Quartile 2

Next 25%

Quartile 3

Next

Quartile 4

Lowest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Used in&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Salary bands&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Performance categories&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Customer segmentation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;5. PERCENT_RANK()&lt;/h1&gt;&lt;p&gt;Returns the relative rank of a row as a value between &lt;strong&gt;0 and 1&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Formula:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;(RANK - 1) / (TotalRows - 1)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
Name,
Salary,
PERCENT_RANK() OVER(ORDER BY Salary DESC) AS PercentRank
FROM Employee;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Sample output&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Salary&lt;/th&gt;&lt;th&gt;PercentRank&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;David&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;0.00&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Smith&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;0.00&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;John&lt;/td&gt;&lt;td&gt;80000&lt;/td&gt;&lt;td&gt;0.33&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Bob&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;0.50&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Mike&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;0.50&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Alice&lt;/td&gt;&lt;td&gt;60000&lt;/td&gt;&lt;td&gt;0.83&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Tom&lt;/td&gt;&lt;td&gt;50000&lt;/td&gt;&lt;td&gt;1.00&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;strong&gt;Use cases:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Percentile analysis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Academic grading&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sales performance evaluation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;6. CUME_DIST()&lt;/h1&gt;&lt;p&gt;Returns the cumulative distribution, i.e., the proportion of rows with values less than or equal to the current row.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
Name,
Salary,
CUME_DIST() OVER(ORDER BY Salary DESC) AS CumulativeDist
FROM Employee;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Sample output&lt;/p&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Salary&lt;/th&gt;&lt;th&gt;CUME_DIST&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;David&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;0.29&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Smith&lt;/td&gt;&lt;td&gt;90000&lt;/td&gt;&lt;td&gt;0.29&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;John&lt;/td&gt;&lt;td&gt;80000&lt;/td&gt;&lt;td&gt;0.43&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Bob&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;0.71&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Mike&lt;/td&gt;&lt;td&gt;70000&lt;/td&gt;&lt;td&gt;0.71&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Alice&lt;/td&gt;&lt;td&gt;60000&lt;/td&gt;&lt;td&gt;0.86&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Tom&lt;/td&gt;&lt;td&gt;50000&lt;/td&gt;&lt;td&gt;1.00&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;strong&gt;Use cases:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Finding top performers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Statistical analysis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Distribution reporting&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Common Interview Questions&lt;/h1&gt;&lt;h3&gt;1. Find the second highest salary.&lt;/h3&gt;&lt;p&gt;Using &lt;code inline=&quot;&quot;&gt;DENSE_RANK()&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH SalaryRank AS
(
    SELECT *,
           DENSE_RANK() OVER(ORDER BY Salary DESC) AS SalaryRank
    FROM Employee
)
SELECT *
FROM SalaryRank
WHERE SalaryRank = 2;
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;2. Find the top 3 highest salaries.&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH SalaryRank AS
(
    SELECT *,
           DENSE_RANK() OVER(ORDER BY Salary DESC) AS SalaryRank
    FROM Employee
)
SELECT *
FROM SalaryRank
WHERE SalaryRank &amp;lt;= 3;
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;3. Find the highest-paid employee in each department.&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH DeptRank AS
(
    SELECT *,
           DENSE_RANK() OVER(
               PARTITION BY Department
               ORDER BY Salary DESC
           ) AS DeptRank
    FROM Employee
)
SELECT *
FROM DeptRank
WHERE DeptRank = 1;
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;4. Remove duplicate rows.&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH DuplicateRows AS
(
    SELECT *,
           ROW_NUMBER() OVER(
               PARTITION BY Email
               ORDER BY EmpId
           ) AS RN
    FROM Customer
)
DELETE FROM DuplicateRows
WHERE RN &amp;gt; 1;
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;5. Implement pagination (rows 21–30).&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH OrderedEmployees AS
(
    SELECT *,
           ROW_NUMBER() OVER(ORDER BY EmpId) AS RN
    FROM Employee
)
SELECT *
FROM OrderedEmployees
WHERE RN BETWEEN 21 AND 30;
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Quick Summary&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Duplicates Get Same Rank?&lt;/th&gt;&lt;th&gt;Gaps in Ranking?&lt;/th&gt;&lt;th&gt;Common Use Cases&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;ROW_NUMBER()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;❌ No&lt;/td&gt;&lt;td&gt;❌ No&lt;/td&gt;&lt;td&gt;Pagination, duplicate removal, unique sequencing&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;RANK()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;✅ Yes&lt;/td&gt;&lt;td&gt;✅ Yes&lt;/td&gt;&lt;td&gt;Competition ranking, exam results&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;DENSE_RANK()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;✅ Yes&lt;/td&gt;&lt;td&gt;❌ No&lt;/td&gt;&lt;td&gt;Top N salaries, leaderboards&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;NTILE(n)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;N/A&lt;/td&gt;&lt;td&gt;N/A&lt;/td&gt;&lt;td&gt;Divide rows into equal groups or quartiles&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;PERCENT_RANK()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Based on &lt;code inline=&quot;&quot;&gt;RANK()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;May reflect rank gaps&lt;/td&gt;&lt;td&gt;Percentile calculations&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code inline=&quot;&quot;&gt;CUME_DIST()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Includes ties together&lt;/td&gt;&lt;td&gt;N/A&lt;/td&gt;&lt;td&gt;Cumulative distribution and statistical reporting&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;h2&gt;Interview Tip&lt;/h2&gt;&lt;p&gt;A very common interview question is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;&quot;What is the difference between &lt;code inline=&quot;&quot;&gt;ROW_NUMBER()&lt;/code&gt;, &lt;code inline=&quot;&quot;&gt;RANK()&lt;/code&gt;, and &lt;code inline=&quot;&quot;&gt;DENSE_RANK()&lt;/code&gt;?&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;A concise answer:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code inline=&quot;&quot;&gt;ROW_NUMBER()&lt;/code&gt;&lt;/strong&gt; gives every row a unique sequential number, even when values are tied.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code inline=&quot;&quot;&gt;RANK()&lt;/code&gt;&lt;/strong&gt; assigns the same rank to tied rows but skips the next rank(s).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code inline=&quot;&quot;&gt;DENSE_RANK()&lt;/code&gt;&lt;/strong&gt; assigns the same rank to tied rows without leaving gaps.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Understanding these differences, along with &lt;code inline=&quot;&quot;&gt;PARTITION BY&lt;/code&gt; and &lt;code inline=&quot;&quot;&gt;ORDER BY&lt;/code&gt;, is essential for solving real-world SQL problems such as pagination, leaderboards, Top-N queries, duplicate removal, and departmental rankings.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/7935879653681456469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/7935879653681456469' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/7935879653681456469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/7935879653681456469'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/rownumber-rank-denserank-ntile.html' title='ROW_NUMBER(),  RANK(), DENSE_RANK(), NTILE(), PERCENT_RANK(), CUME_DIST() In Sql'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-9077135462544904829</id><published>2026-08-05T20:07:20.136+05:30</published><updated>2026-08-05T20:07:20.136+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Technical Lead Interview Questions and Answers"/><title type='text'>Technical Lead Scenario-Based Interview Questions &amp; Answers (.NET Core + Azure)</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;h1&gt;Technical Lead Scenario-Based Interview Questions &amp;amp; Answers (.NET Core + Azure)&lt;/h1&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 1: Designing a New Enterprise Application&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Your company wants to build a Loan Management System used by 500,000 customers. How would you design the architecture?&lt;/p&gt;&lt;h3&gt;Expected Answer&lt;/h3&gt;&lt;p&gt;First I gather functional and non-functional requirements.&lt;/p&gt;&lt;p&gt;Functional:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Customer Registration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Loan Application&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Approval Workflow&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Payment&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Notifications&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Non-functional:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;High Availability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Scalability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Performance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Disaster Recovery&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Architecture:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Angular

      |

API Gateway (Azure APIM)

      |

-----------------------------

Identity Service

Loan Service

Payment Service

Notification Service

Document Service

-----------------------------

Azure Service Bus

Azure SQL

Blob Storage

Redis Cache

Application Insights
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Patterns:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Clean Architecture&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DDD&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;CQRS&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Repository&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Unit of Work&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Event Driven&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Azure Services&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure App Service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure SQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Service Bus&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Monitor&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Application Insights&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This architecture supports independent deployment and scaling.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 2: Microservice Communication&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Service A needs customer details from Service B.&lt;/p&gt;&lt;p&gt;Would you call it synchronously or asynchronously?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Depends on business requirement.&lt;/p&gt;&lt;p&gt;If immediate response required&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Order Service

↓

Customer Service (REST API)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;REST&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;gRPC&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If eventual consistency acceptable&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Order Created

↓

Azure Service Bus

↓

Customer Service

↓

Notification Service

↓

Audit Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Benefits&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Loose coupling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Retry&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;High availability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Independent scaling&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 3: API Performance Issue&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;One API takes 18 seconds.&lt;/p&gt;&lt;p&gt;How will you investigate?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;My investigation sequence:&lt;/p&gt;&lt;p&gt;Step 1&lt;/p&gt;&lt;p&gt;Application Insights&lt;/p&gt;&lt;p&gt;Check&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Dependency calls&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Exceptions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Slow SQL&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Step 2&lt;/p&gt;&lt;p&gt;Database&lt;/p&gt;&lt;p&gt;Check&lt;/p&gt;&lt;p&gt;Execution Plan&lt;/p&gt;&lt;p&gt;Missing Index&lt;/p&gt;&lt;p&gt;Blocking&lt;/p&gt;&lt;p&gt;Deadlock&lt;/p&gt;&lt;p&gt;Step 3&lt;/p&gt;&lt;p&gt;Code&lt;/p&gt;&lt;p&gt;Look for&lt;/p&gt;&lt;pre&gt;&lt;code&gt;foreach(...)
{
   await repository.GetById();
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;N+1 problem.&lt;/p&gt;&lt;p&gt;Instead&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Single Query
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Step 4&lt;/p&gt;&lt;p&gt;Caching&lt;/p&gt;&lt;p&gt;Redis&lt;/p&gt;&lt;p&gt;Memory Cache&lt;/p&gt;&lt;p&gt;Step 5&lt;/p&gt;&lt;p&gt;Load Testing&lt;/p&gt;&lt;p&gt;Azure Load Test&lt;/p&gt;&lt;p&gt;JMeter&lt;/p&gt;&lt;p&gt;Finally optimize.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 4: Production is Down&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Production suddenly becomes unavailable.&lt;/p&gt;&lt;p&gt;What do you do?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Never panic.&lt;/p&gt;&lt;p&gt;Follow Incident Process.&lt;/p&gt;&lt;p&gt;Step 1&lt;/p&gt;&lt;p&gt;Verify&lt;/p&gt;&lt;p&gt;Azure Health&lt;/p&gt;&lt;p&gt;App Service&lt;/p&gt;&lt;p&gt;SQL&lt;/p&gt;&lt;p&gt;Service Bus&lt;/p&gt;&lt;p&gt;Step 2&lt;/p&gt;&lt;p&gt;Rollback if deployment caused issue.&lt;/p&gt;&lt;p&gt;Step 3&lt;/p&gt;&lt;p&gt;Collect Logs&lt;/p&gt;&lt;p&gt;Application Insights&lt;/p&gt;&lt;p&gt;Azure Monitor&lt;/p&gt;&lt;p&gt;Step 4&lt;/p&gt;&lt;p&gt;Temporary Fix&lt;/p&gt;&lt;p&gt;Scale Out&lt;/p&gt;&lt;p&gt;Restart unhealthy instances&lt;/p&gt;&lt;p&gt;Disable problematic feature&lt;/p&gt;&lt;p&gt;Step 5&lt;/p&gt;&lt;p&gt;Root Cause Analysis&lt;/p&gt;&lt;p&gt;Document&lt;/p&gt;&lt;p&gt;Prevent recurrence.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 5: Azure SQL Database Reaches 100% CPU&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Users complain application is slow.&lt;/p&gt;&lt;p&gt;Azure SQL CPU is 100%.&lt;/p&gt;&lt;p&gt;How do you solve it?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Check&lt;/p&gt;&lt;p&gt;Top Queries&lt;/p&gt;&lt;p&gt;Execution Plans&lt;/p&gt;&lt;p&gt;Missing Indexes&lt;/p&gt;&lt;p&gt;Deadlocks&lt;/p&gt;&lt;p&gt;Blocking Sessions&lt;/p&gt;&lt;p&gt;Large Table Scan&lt;/p&gt;&lt;p&gt;Optimize&lt;/p&gt;&lt;p&gt;Indexes&lt;/p&gt;&lt;p&gt;Pagination&lt;/p&gt;&lt;p&gt;Caching&lt;/p&gt;&lt;p&gt;Read-only replicas&lt;/p&gt;&lt;p&gt;Partitioning&lt;/p&gt;&lt;p&gt;Increase DTU/vCore only if required.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 6: Team Writes Duplicate Logic&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Every developer writes validation differently.&lt;/p&gt;&lt;p&gt;What will you do?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;As Technical Lead&lt;/p&gt;&lt;p&gt;I introduce&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Coding Standards&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Common Validation Library&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reusable NuGet Package&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Static Code Analysis&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pull Request Guidelines&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Every PR goes through review.&lt;/p&gt;&lt;p&gt;Consistency improves.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 7: Security Review&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Security team found secrets inside appsettings.json.&lt;/p&gt;&lt;p&gt;How do you fix it?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Never store secrets.&lt;/p&gt;&lt;p&gt;Move&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Connection String

API Keys

Certificates

Passwords
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To&lt;/p&gt;&lt;p&gt;Azure Key Vault&lt;/p&gt;&lt;p&gt;Use&lt;/p&gt;&lt;p&gt;Managed Identity&lt;/p&gt;&lt;p&gt;Benefits&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Secret Rotation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Encryption&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Audit Trail&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 8: API Authentication&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;How do you secure APIs?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Authentication&lt;/p&gt;&lt;p&gt;Azure AD&lt;/p&gt;&lt;p&gt;JWT&lt;/p&gt;&lt;p&gt;Authorization&lt;/p&gt;&lt;p&gt;Role Based Access&lt;/p&gt;&lt;p&gt;Policy Based Authorization&lt;/p&gt;&lt;p&gt;Claims&lt;/p&gt;&lt;p&gt;Other security&lt;/p&gt;&lt;p&gt;HTTPS&lt;/p&gt;&lt;p&gt;Rate Limiting&lt;/p&gt;&lt;p&gt;Input Validation&lt;/p&gt;&lt;p&gt;OWASP&lt;/p&gt;&lt;p&gt;Key Vault&lt;/p&gt;&lt;p&gt;APIM&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 9: Scaling&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Traffic increases 20 times during Black Friday.&lt;/p&gt;&lt;p&gt;How will your application survive?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Use&lt;/p&gt;&lt;p&gt;Stateless APIs&lt;/p&gt;&lt;p&gt;Redis Cache&lt;/p&gt;&lt;p&gt;Autoscaling&lt;/p&gt;&lt;p&gt;Azure App Service Scale Out&lt;/p&gt;&lt;p&gt;Azure SQL Elastic Pool&lt;/p&gt;&lt;p&gt;Azure Service Bus&lt;/p&gt;&lt;p&gt;CDN&lt;/p&gt;&lt;p&gt;Blob Storage&lt;/p&gt;&lt;p&gt;Horizontal scaling.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 10: Event Driven Architecture&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Customer places an order.&lt;/p&gt;&lt;p&gt;Five services need notification.&lt;/p&gt;&lt;p&gt;How will you design?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Instead of&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Order

↓

Inventory

↓

Payment

↓

Email

↓

Analytics

↓

CRM
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Order Service

↓

Publish Event

↓

Azure Service Bus Topic

↓

Inventory

↓

Payment

↓

Email

↓

Analytics

↓

CRM
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Much more scalable.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 11: Code Review&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;What do you check during code review?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;I check&lt;/p&gt;&lt;p&gt;✔ SOLID&lt;/p&gt;&lt;p&gt;✔ Naming&lt;/p&gt;&lt;p&gt;✔ Security&lt;/p&gt;&lt;p&gt;✔ Performance&lt;/p&gt;&lt;p&gt;✔ Exception Handling&lt;/p&gt;&lt;p&gt;✔ Logging&lt;/p&gt;&lt;p&gt;✔ Unit Tests&lt;/p&gt;&lt;p&gt;✔ Async&lt;/p&gt;&lt;p&gt;✔ Disposal&lt;/p&gt;&lt;p&gt;✔ SQL Injection&lt;/p&gt;&lt;p&gt;✔ Reusability&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 12: Logging Strategy&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;How do you implement logging?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Levels&lt;/p&gt;&lt;p&gt;Information&lt;/p&gt;&lt;p&gt;Warning&lt;/p&gt;&lt;p&gt;Error&lt;/p&gt;&lt;p&gt;Critical&lt;/p&gt;&lt;p&gt;Use&lt;/p&gt;&lt;p&gt;ILogger&lt;/p&gt;&lt;p&gt;Serilog&lt;/p&gt;&lt;p&gt;Application Insights&lt;/p&gt;&lt;p&gt;Correlation ID&lt;/p&gt;&lt;p&gt;Never log passwords.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 13: Production Bug&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;A bug exists only in Production.&lt;/p&gt;&lt;p&gt;Not reproducible locally.&lt;/p&gt;&lt;p&gt;How do you investigate?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Check&lt;/p&gt;&lt;p&gt;Logs&lt;/p&gt;&lt;p&gt;Telemetry&lt;/p&gt;&lt;p&gt;Configuration&lt;/p&gt;&lt;p&gt;Environment Variables&lt;/p&gt;&lt;p&gt;Version&lt;/p&gt;&lt;p&gt;Feature Flags&lt;/p&gt;&lt;p&gt;Data Differences&lt;/p&gt;&lt;p&gt;Database&lt;/p&gt;&lt;p&gt;Application Insights Transaction Search.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 14: API Versioning&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Old clients still use v1.&lt;/p&gt;&lt;p&gt;New features in v2.&lt;/p&gt;&lt;p&gt;How do you support both?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;api/v1/customer

api/v2/customer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Deprecate older versions gradually.&lt;/p&gt;&lt;p&gt;Communicate timeline.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 15: CI/CD&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Explain your deployment pipeline.&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Developer&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Git&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Pull Request&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Build&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Unit Test&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;SonarQube&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Publish Artifact&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Deploy Dev&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;QA&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;UAT&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Production Approval&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Production&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 16: Production Deployment Failed&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Half deployment completed.&lt;/p&gt;&lt;p&gt;Users affected.&lt;/p&gt;&lt;p&gt;Now what?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Blue-Green Deployment&lt;/p&gt;&lt;p&gt;Rollback&lt;/p&gt;&lt;p&gt;Database backward compatibility&lt;/p&gt;&lt;p&gt;Feature Flags&lt;/p&gt;&lt;p&gt;Health Check&lt;/p&gt;&lt;p&gt;Smoke Test&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 17: Team Conflict&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Two senior developers disagree on architecture.&lt;/p&gt;&lt;p&gt;What do you do?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Arrange technical discussion.&lt;/p&gt;&lt;p&gt;Compare&lt;/p&gt;&lt;p&gt;Performance&lt;/p&gt;&lt;p&gt;Maintainability&lt;/p&gt;&lt;p&gt;Scalability&lt;/p&gt;&lt;p&gt;Security&lt;/p&gt;&lt;p&gt;Development effort&lt;/p&gt;&lt;p&gt;Prototype if needed.&lt;/p&gt;&lt;p&gt;Decision based on facts.&lt;/p&gt;&lt;p&gt;Not opinions.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 18: Slow Microservice&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;One service delays every request.&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Check&lt;/p&gt;&lt;p&gt;Dependency Calls&lt;/p&gt;&lt;p&gt;Database&lt;/p&gt;&lt;p&gt;Redis&lt;/p&gt;&lt;p&gt;Thread Pool&lt;/p&gt;&lt;p&gt;Memory&lt;/p&gt;&lt;p&gt;GC&lt;/p&gt;&lt;p&gt;CPU&lt;/p&gt;&lt;p&gt;Distributed Tracing&lt;/p&gt;&lt;p&gt;Application Insights&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 19: Legacy Monolith Migration&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Company wants Microservices.&lt;/p&gt;&lt;p&gt;How will you migrate?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Use&lt;/p&gt;&lt;p&gt;Strangler Pattern&lt;/p&gt;&lt;p&gt;Extract modules one by one&lt;/p&gt;&lt;p&gt;Customer&lt;/p&gt;&lt;p&gt;Order&lt;/p&gt;&lt;p&gt;Payment&lt;/p&gt;&lt;p&gt;Notification&lt;/p&gt;&lt;p&gt;Eventually retire monolith.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 20: Observability&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;How do you monitor application health?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Metrics&lt;/p&gt;&lt;p&gt;CPU&lt;/p&gt;&lt;p&gt;Memory&lt;/p&gt;&lt;p&gt;Response Time&lt;/p&gt;&lt;p&gt;Availability&lt;/p&gt;&lt;p&gt;Dependency Failures&lt;/p&gt;&lt;p&gt;Exception Rate&lt;/p&gt;&lt;p&gt;Dashboard&lt;/p&gt;&lt;p&gt;Azure Monitor&lt;/p&gt;&lt;p&gt;Application Insights&lt;/p&gt;&lt;p&gt;Alerts&lt;/p&gt;&lt;p&gt;Teams&lt;/p&gt;&lt;p&gt;Email&lt;/p&gt;&lt;p&gt;SMS&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 21: Handling High Traffic During a Flash Sale&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Your e-commerce site receives 10x normal traffic during a flash sale. Checkout APIs start timing out. What immediate and long-term actions would you take?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Immediate actions:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Scale out Azure App Service instances.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Increase Azure SQL compute if it&#39;s the bottleneck.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enable/verify Redis caching for frequently accessed data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Queue non-critical operations (emails, analytics) using Azure Service Bus.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitor live metrics in Application Insights.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Long-term improvements:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Optimize slow database queries and indexing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement autoscaling rules.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use CDN for static content.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add load testing to CI/CD.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Introduce asynchronous processing where appropriate.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 22: Production Memory Leak&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;After a few days of uptime, your API becomes slow and eventually crashes with OutOfMemoryException. How do you investigate?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Check Application Insights memory metrics.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Capture memory dumps.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Analyze with Visual Studio Diagnostic Tools or dotMemory.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Look for:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Undisposed &lt;code inline=&quot;&quot;&gt;IDisposable&lt;/code&gt; objects.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Static collections growing indefinitely.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Event handler leaks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Large object allocations.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fix resource disposal and validate with load testing.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 23: Breaking Database Schema Changes&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;A database schema change is required, but older application versions are still running during deployment. How do you avoid downtime?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Follow backward-compatible database changes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add new columns before removing old ones.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deploy application changes that support both schemas.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Migrate data in the background.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Remove deprecated schema only after all instances are updated.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 24: Third-Party API Failure&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;Your payment provider is intermittently unavailable. How do you prevent your application from failing?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;p&gt;Use resilience patterns:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Retry with exponential backoff.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Circuit Breaker.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Timeout policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fallback responses where appropriate.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Queue requests if business rules allow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitor failures and alert operations.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Common implementation: Polly in .NET.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Scenario 25: Mentoring a Junior Team&lt;/h1&gt;&lt;h3&gt;Interviewer&lt;/h3&gt;&lt;p&gt;A junior developer repeatedly introduces bugs. As a Technical Lead, how do you handle it?&lt;/p&gt;&lt;h3&gt;Answer&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Review the code together instead of only rejecting PRs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Explain the reasoning behind feedback.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pair program on complex features.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Recommend learning resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Gradually increase responsibility.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Track improvement through regular one-on-one sessions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This approach improves both code quality and team growth.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Technical Lead Interview Tips&lt;/h2&gt;&lt;p&gt;Interviewers also evaluate how you think, not just what you know. When answering scenario questions:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Clarify assumptions before proposing a solution.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Consider scalability, security, performance, and maintainability together.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Mention trade-offs and why you chose a particular approach.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Include Azure services, design patterns, and DevOps practices where relevant.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Explain how you would communicate with stakeholders and lead the team during incidents.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;These scenarios closely reflect the responsibilities you listed and are typical of Technical Lead interviews for enterprise .NET and Azure roles.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/9077135462544904829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/9077135462544904829' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/9077135462544904829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/9077135462544904829'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/technical-lead-scenario-based-interview.html' title='Technical Lead Scenario-Based Interview Questions &amp; Answers (.NET Core + Azure)'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-5945620437994559179</id><published>2026-08-02T17:40:39.762+05:30</published><updated>2026-08-02T17:40:39.762+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Apache Kafka Interview Questions &amp; Answers"/><title type='text'>Apache Kafka Interview Questions &amp; Answers</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFvCHg5Teo9Xw12TrkKMk9i4nWD4YGhUws45tAIGVx3prwiDoTN_-0mM3woODKbwj3PCyv8uem0jJBWqD1hugeZ7oBgqTPmUy8-kAUjIz4tzPX485jf-KlonL14rjom8xoBOSDmiXMHcMhtxdjJW6960lzAJAClpZepPBdQeX4lXvBac2wG-c_1Co-00Q/s1536/KafkaTutorials.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFvCHg5Teo9Xw12TrkKMk9i4nWD4YGhUws45tAIGVx3prwiDoTN_-0mM3woODKbwj3PCyv8uem0jJBWqD1hugeZ7oBgqTPmUy8-kAUjIz4tzPX485jf-KlonL14rjom8xoBOSDmiXMHcMhtxdjJW6960lzAJAClpZepPBdQeX4lXvBac2wG-c_1Co-00Q/s320/KafkaTutorials.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h1&gt;Apache Kafka Interview Questions &amp;amp; Answers (Lead/Architect Level)&lt;/h1&gt;&lt;h1&gt;1. What is Apache Kafka?&lt;/h1&gt;&lt;h3&gt;Interview Answer&lt;/h3&gt;&lt;p&gt;Apache Kafka is a &lt;strong&gt;distributed event streaming platform&lt;/strong&gt; designed for &lt;strong&gt;high-throughput, fault-tolerant, scalable, and real-time data streaming&lt;/strong&gt;. It allows applications to publish, store, and consume streams of events asynchronously.&lt;/p&gt;&lt;p&gt;Unlike traditional messaging systems that remove messages after they are consumed, Kafka stores messages for a configurable retention period, enabling multiple consumers to read the same events independently.&lt;/p&gt;&lt;p&gt;Kafka is widely used in:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Microservices&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Event-Driven Architecture (EDA)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Real-time analytics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Log aggregation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;IoT applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Financial systems&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;E-commerce platforms&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h3&gt;Real-Time Example&lt;/h3&gt;&lt;p&gt;Amazon Order Processing&lt;/p&gt;&lt;p&gt;When a customer places an order:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Customer

↓

Order Service

↓

Kafka

↓

Payment Service

↓

Inventory Service

↓

Email Service

↓

Analytics Service

↓

Shipping Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Every service receives the event independently.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Key Features&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;High Throughput&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fault Tolerance&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Horizontal Scalability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Message Persistence&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Event Replay&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Distributed Architecture&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h3&gt;Interview Tip&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;Kafka is an Event Streaming Platform, not just a Message Queue.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;2. Explain Kafka Architecture&lt;/h1&gt;&lt;p&gt;Kafka follows a distributed architecture.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;                Producer

                    │

                    ▼

             Kafka Cluster

      ----------------------------

      Broker1

      Broker2

      Broker3

      ----------------------------

                    │

               Orders Topic

      ----------------------------

      Partition0

      Partition1

      Partition2

      ----------------------------

                    │

          Consumer Group

       Inventory Service

       Email Service

       Analytics Service
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Components&lt;/h3&gt;&lt;p&gt;Producer&lt;/p&gt;&lt;p&gt;Creates messages.&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Topic&lt;/p&gt;&lt;p&gt;Stores messages logically.&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Partition&lt;/p&gt;&lt;p&gt;Splits topic into multiple logs.&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Broker&lt;/p&gt;&lt;p&gt;Stores partitions.&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Consumer&lt;/p&gt;&lt;p&gt;Reads messages.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Flow&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;Angular

↓

.NET API

↓

Producer

↓

Topic

↓

Broker

↓

Consumer

↓

Database
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Why Distributed?&lt;/h3&gt;&lt;p&gt;If one broker crashes,&lt;/p&gt;&lt;p&gt;Other brokers continue serving requests.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. What is a Broker?&lt;/h1&gt;&lt;p&gt;A Broker is a Kafka server responsible for storing topic partitions and serving producer and consumer requests.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Kafka Cluster

Broker1

Broker2

Broker3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each broker stores part of the data.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Responsibilities&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Store messages&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Handle producer requests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Serve consumers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Replicate data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Leader election&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Offset management&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h3&gt;Real Example&lt;/h3&gt;&lt;p&gt;Topic has 6 partitions&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Broker1

P0

P1

Broker2

P2

P3

Broker3

P4

P5
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Interview Tip&lt;/h3&gt;&lt;p&gt;Kafka Cluster = Collection of Brokers.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;4. What is a Topic?&lt;/h1&gt;&lt;p&gt;Topic is a logical category where messages are stored.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Orders

Payments

Customers

Notifications
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Producer writes&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Orders Topic
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Consumer reads&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Orders Topic
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Real Example&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;OrderCreated

↓

Orders Topic
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Consumers&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Inventory&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Billing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Email&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Analytics&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;All subscribe to the same topic.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Important&lt;/h3&gt;&lt;p&gt;A Topic contains multiple partitions.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;5. What is a Partition?&lt;/h1&gt;&lt;p&gt;A partition is a physical subdivision of a topic.&lt;/p&gt;&lt;p&gt;Instead of&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Orders
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Kafka stores&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Orders

Partition0

Partition1

Partition2
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Why?&lt;/h3&gt;&lt;p&gt;Allows parallel processing.&lt;/p&gt;&lt;p&gt;Suppose&lt;/p&gt;&lt;p&gt;1 Million Orders.&lt;/p&gt;&lt;p&gt;One partition&lt;/p&gt;&lt;pre&gt;&lt;code&gt;One Consumer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Slow.&lt;/p&gt;&lt;p&gt;Ten partitions&lt;/p&gt;&lt;pre&gt;&lt;code&gt;10 Consumers
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Much faster.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Real Example&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;Partition0

Order1

Order4

Order7

Partition1

Order2

Order5

Order8

Partition2

Order3

Order6

Order9
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Benefits&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Scalability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Parallelism&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Load balancing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;6. What is an Offset?&lt;/h1&gt;&lt;p&gt;Offset is the unique position of a message inside a partition.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Partition0

Offset0

Offset1

Offset2

Offset3

Offset4
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Consumer stores&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Current Offset = 4
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After restart,&lt;/p&gt;&lt;p&gt;Reads from Offset5.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Why Important?&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Resume processing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Replay events&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fault recovery&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h3&gt;Interview Tip&lt;/h3&gt;&lt;p&gt;Offset is unique only within a partition, not across the entire topic.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;7. Explain Consumer Groups&lt;/h1&gt;&lt;p&gt;Consumer Group is a collection of consumers working together.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Inventory Group

Consumer1

Consumer2

Consumer3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Topic&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Partition0

Partition1

Partition2
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Assignment&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Consumer1 → Partition0

Consumer2 → Partition1

Consumer3 → Partition2
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;No duplicate processing occurs within the same group.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Multiple Groups&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;Orders Topic

↓

Inventory Group

↓

Email Group

↓

Analytics Group
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Every group receives the same event independently.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Benefits&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Scalability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Load balancing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fault tolerance&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;8. Difference between Queue and Topic&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Queue&lt;/th&gt;&lt;th&gt;Kafka Topic&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Point-to-Point&lt;/td&gt;&lt;td&gt;Publish-Subscribe&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;One consumer receives a message&lt;/td&gt;&lt;td&gt;Multiple consumer groups receive the same message&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Message is typically removed after processing&lt;/td&gt;&lt;td&gt;Message is retained for a configured period&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Limited replay&lt;/td&gt;&lt;td&gt;Replay supported&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Suitable for task distribution&lt;/td&gt;&lt;td&gt;Suitable for event streaming&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h3&gt;Queue Example&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;Producer

↓

Queue

↓

Consumer A
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Consumer B never receives the message.&lt;/p&gt;&lt;hr /&gt;&lt;h3&gt;Kafka Topic Example&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;Producer

↓

Orders Topic

↓

Inventory Group

↓

Email Group

↓

Analytics Group
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Every group processes the event.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. Kafka vs RabbitMQ&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Kafka&lt;/th&gt;&lt;th&gt;RabbitMQ&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Distributed Event Streaming&lt;/td&gt;&lt;td&gt;Traditional Message Broker&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Stores messages in logs&lt;/td&gt;&lt;td&gt;Stores messages in queues&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Very high throughput&lt;/td&gt;&lt;td&gt;Moderate throughput&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Supports replay&lt;/td&gt;&lt;td&gt;Replay is limited&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Excellent for analytics and streaming&lt;/td&gt;&lt;td&gt;Excellent for task queues and request/response&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Partition-based scaling&lt;/td&gt;&lt;td&gt;Queue-based scaling&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h3&gt;Real Use Cases&lt;/h3&gt;&lt;p&gt;Kafka&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Banking events&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;IoT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Real-time analytics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Clickstream processing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;RabbitMQ&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Email queues&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Background jobs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Order processing tasks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;RPC-style messaging&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;10. Why are partitions needed?&lt;/h1&gt;&lt;p&gt;Partitions allow Kafka to scale horizontally.&lt;/p&gt;&lt;p&gt;Without partitions&lt;/p&gt;&lt;pre&gt;&lt;code&gt;1 Topic

↓

1 Consumer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With partitions&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Partition0

Partition1

Partition2

↓

Consumer1

Consumer2

Consumer3
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Benefits&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Higher throughput&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Better CPU utilization&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Parallel processing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Horizontal scaling&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;11. How does Kafka guarantee ordering?&lt;/h1&gt;&lt;p&gt;Kafka guarantees ordering only within a single partition.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Partition0

Offset0 OrderCreated

Offset1 PaymentCompleted

Offset2 OrderShipped
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Consumers read in offset order.&lt;/p&gt;&lt;p&gt;Across multiple partitions, there is no global ordering guarantee.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Best practice:&lt;/strong&gt; If ordering is important for a business entity (for example, an order), use the same message key (&lt;code inline=&quot;&quot;&gt;OrderId&lt;/code&gt;) so Kafka routes all events for that key to the same partition.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. What happens when a broker fails?&lt;/h1&gt;&lt;p&gt;Kafka uses replication to maintain availability.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Broker1

Leader

↓

Broker2

Follower

↓

Broker3

Follower
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If Broker1 fails:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Kafka elects a new leader from the in-sync replicas (ISR).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Producers and consumers continue working with the new leader.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;When the failed broker comes back, it catches up and rejoins as a follower.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This minimizes downtime and prevents data loss when configured correctly.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. What is replication factor?&lt;/h1&gt;&lt;p&gt;The replication factor defines how many copies of each partition Kafka maintains.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Replication Factor = 3

Partition0

Leader → Broker1

Replica → Broker2

Replica → Broker3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If one broker fails, the replicas are available for leader election.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Trade-off:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Higher replication = better availability and durability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Higher replication also requires more storage and network bandwidth.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;14. What are producer acknowledgements (acks)?&lt;/h1&gt;&lt;p&gt;The &lt;code inline=&quot;&quot;&gt;acks&lt;/code&gt; setting determines how many brokers must acknowledge a write before the producer considers it successful.&lt;/p&gt;&lt;h3&gt;acks = 0&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Producer does not wait.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fastest.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Messages may be lost.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;acks = 1&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Waits for the leader broker only.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Good balance of speed and reliability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Most common configuration.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;acks = all (or -1)&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Waits for all in-sync replicas.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Highest durability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Slightly higher latency.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;15. What is consumer lag?&lt;/h1&gt;&lt;p&gt;Consumer lag is the difference between:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;the latest offset written to a partition, and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;the last offset processed by a consumer.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Latest Offset = 1000

Consumer Offset = 900

Lag = 100
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;High lag may indicate:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Slow consumers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Insufficient consumer instances&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Long-running processing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Resource bottlenecks&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Monitoring consumer lag is essential in production systems.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. What is an idempotent producer?&lt;/h1&gt;&lt;p&gt;An idempotent producer ensures that retrying a message does not create duplicates.&lt;/p&gt;&lt;p&gt;Without idempotence:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Send Message

↓

Network Failure

↓

Retry

↓

Duplicate Message
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With idempotence enabled:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Retry

↓

Kafka recognizes the duplicate

↓

Stores only one copy
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the .NET &lt;code inline=&quot;&quot;&gt;Confluent.Kafka&lt;/code&gt; client, this is enabled using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var config = new ProducerConfig
{
    BootstrapServers = &quot;localhost:9092&quot;,
    EnableIdempotence = true
};
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is especially important in payment and financial systems.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;17. What is exactly-once processing?&lt;/h1&gt;&lt;p&gt;Exactly-once processing (EOS) ensures that each event is processed only once, even in the presence of retries or failures.&lt;/p&gt;&lt;p&gt;Kafka achieves this through:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Idempotent producers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Transactions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Transaction-aware consumers&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Transfer ₹100

↓

Kafka Event

↓

Retry

↓

Still processed only once
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is critical in banking, inventory, and billing systems where duplicate processing is unacceptable.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;18. What is the role of Schema Registry?&lt;/h1&gt;&lt;p&gt;Schema Registry centrally manages event schemas, commonly using Avro, Protobuf, or JSON Schema.&lt;/p&gt;&lt;p&gt;Benefits:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Producers and consumers agree on the event structure.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Supports schema evolution while maintaining compatibility.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reduces message size (especially with Avro).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Prevents incompatible changes.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;OrderCreated

OrderId

CustomerId

Amount
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If a new field is added later, compatibility rules determine whether older consumers can still process the event.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;19. How do you scale Kafka consumers?&lt;/h1&gt;&lt;p&gt;Consumers scale through:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Increasing the number of partitions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Adding more consumer instances to the same consumer group.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Topic

6 Partitions

↓

Consumer Group

Consumer1

Consumer2

Consumer3

Consumer4

Consumer5

Consumer6
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each consumer processes one partition.&lt;/p&gt;&lt;p&gt;Important rules:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;A consumer group cannot process more partitions concurrently than the number of partitions available.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If there are more consumers than partitions, the extra consumers remain idle.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;20. How do you integrate Kafka with .NET Core?&lt;/h1&gt;&lt;p&gt;A common architecture is:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Angular

↓

ASP.NET Core Web API

↓

Kafka Producer

↓

Orders Topic

↓

Kafka Cluster

↓

Inventory Service

↓

Payment Service

↓

Email Service

↓

Analytics Service
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 1: Install the Kafka client&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Confluent.Kafka
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 2: Configure the producer&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var config = new ProducerConfig
{
    BootstrapServers = &quot;localhost:9092&quot;
};

using var producer =
    new ProducerBuilder&amp;lt;string, string&amp;gt;(config).Build();
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 3: Publish an event&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await producer.ProduceAsync(
    &quot;orders&quot;,
    new Message&amp;lt;string, string&amp;gt;
    {
        Key = &quot;1001&quot;,
        Value = JsonSerializer.Serialize(order)
    });
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Step 4: Create a consumer&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var config = new ConsumerConfig
{
    BootstrapServers = &quot;localhost:9092&quot;,
    GroupId = &quot;inventory-group&quot;,
    AutoOffsetReset = AutoOffsetReset.Earliest
};

using var consumer =
    new ConsumerBuilder&amp;lt;string, string&amp;gt;(config).Build();

consumer.Subscribe(&quot;orders&quot;);

while (true)
{
    var result = consumer.Consume();
    Console.WriteLine(result.Message.Value);
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Angular Integration&lt;/h3&gt;&lt;p&gt;Angular should &lt;strong&gt;not&lt;/strong&gt; connect directly to Kafka.&lt;/p&gt;&lt;p&gt;Instead:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Angular

↓

HTTP POST

↓

ASP.NET Core Web API

↓

Kafka Producer

↓

Kafka Topic
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Web API validates the request, persists business data if needed, and publishes the event to Kafka.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Interview Summary (30-Second Answer)&lt;/h1&gt;&lt;blockquote&gt;&lt;p&gt;&quot;Apache Kafka is a distributed event-streaming platform used to build scalable, fault-tolerant, and asynchronous systems. Producers publish events to topics, which are split into partitions for parallel processing. Brokers store these partitions and replicate them for high availability. Consumer groups process events independently, while offsets track processing progress. In .NET Core, we typically use the Confluent.Kafka library to publish and consume events, exposing HTTP APIs for Angular clients while Kafka handles communication between backend microservices. This architecture improves scalability, resiliency, and loose coupling compared to direct service-to-service communication.&quot;&lt;/p&gt;&lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/5945620437994559179/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/5945620437994559179' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/5945620437994559179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/5945620437994559179'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/apache-kafka-interview-questions-answers.html' title='Apache Kafka Interview Questions &amp; Answers'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFvCHg5Teo9Xw12TrkKMk9i4nWD4YGhUws45tAIGVx3prwiDoTN_-0mM3woODKbwj3PCyv8uem0jJBWqD1hugeZ7oBgqTPmUy8-kAUjIz4tzPX485jf-KlonL14rjom8xoBOSDmiXMHcMhtxdjJW6960lzAJAClpZepPBdQeX4lXvBac2wG-c_1Co-00Q/s72-c/KafkaTutorials.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-1236074523445752150</id><published>2026-08-02T17:36:31.180+05:30</published><updated>2026-08-03T06:58:17.427+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Apache Kafka"/><title type='text'>Apache Kafka</title><content type='html'>&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6aZTN8hQO5tvYNNIy0cPUobnhTrHqkDDDXUwfoWM8bDza2nO9o3x4uMq83OBo0UmUY_eXB-hb_6eUz3wV3ILLx0Q6SA6cX2qMFy6gkT3BJe7Q-kb2SY9z09JfdcmVyz1rVJwgqoR7M91yhL02eeIZjtCua0v2T-gerdLS4LNvokGJgBRprQqkPlmIDAk/s1536/KafkaTutorials.png&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6aZTN8hQO5tvYNNIy0cPUobnhTrHqkDDDXUwfoWM8bDza2nO9o3x4uMq83OBo0UmUY_eXB-hb_6eUz3wV3ILLx0Q6SA6cX2qMFy6gkT3BJe7Q-kb2SY9z09JfdcmVyz1rVJwgqoR7M91yhL02eeIZjtCua0v2T-gerdLS4LNvokGJgBRprQqkPlmIDAk/s320/KafkaTutorials.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;h1&gt;Apache Kafka Complete Tutorial for .NET Core &amp;amp; Angular Developers (Lead/Architect Level)&lt;/h1&gt;&lt;p&gt;This tutorial is designed for &lt;strong&gt;Senior .NET Developers, Technical Leads, Architects, and Microservices Developers&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;By the end of this guide, you&#39;ll understand:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;What is Kafka?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Why Kafka was created?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kafka Architecture&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kafka Components&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Topics vs Queue&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Producers &amp;amp; Consumers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Consumer Groups&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Partitions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Replication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Offset&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Broker&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ZooKeeper vs KRaft&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Event Driven Architecture&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integrating Kafka with .NET Core&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integrating Angular with Kafka using Web API&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Real-time Microservices Example&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deployment in Docker&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Best Practices&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Interview Questions&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Chapter 1 - Why Kafka?&lt;/h1&gt;&lt;p&gt;Imagine Amazon.&lt;/p&gt;&lt;p&gt;Thousands of events happen every second.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Customer places order
↓

Payment Completed
↓

Inventory Updated
↓

Invoice Generated
↓

Email Sent
↓

SMS Sent
↓

Loyalty Points Added
↓

Analytics Updated
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If every service directly called another service,&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Order Service
      ↓
Payment Service
      ↓
Inventory Service
      ↓
Email Service
      ↓
Notification Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Problems&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Tight Coupling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Slow&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Difficult to Scale&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Single Point Failure&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Instead&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Order Service

↓

Kafka

↓

Payment

Inventory

Shipping

Analytics

Email

Notification
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Everything becomes independent.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Chapter 2 - What is Kafka?&lt;/h1&gt;&lt;p&gt;Kafka is&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A Distributed Event Streaming Platform&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Think of Kafka as&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Post Office
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Producer&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Post Office (Kafka)&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Consumer&lt;/p&gt;&lt;p&gt;Producer doesn&#39;t know who receives.&lt;/p&gt;&lt;p&gt;Consumer doesn&#39;t know producer.&lt;/p&gt;&lt;p&gt;Everything is asynchronous.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Chapter 3 - Kafka Architecture&lt;/h1&gt;&lt;pre&gt;&lt;code&gt;               Producer

                  |

                  |

           Kafka Cluster

         -----------------

         Broker 1

         Broker 2

         Broker 3

         -----------------

          Topic

      Orders

     Partition-0

     Partition-1

     Partition-2

          |

          |

 Consumer Group
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Kafka Components&lt;/h1&gt;&lt;h2&gt;Producer&lt;/h2&gt;&lt;p&gt;Produces Message.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;p&gt;Order API&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Order Created
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Producer sends&lt;/p&gt;&lt;pre&gt;&lt;code&gt;OrderCreated Event
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Broker&lt;/h2&gt;&lt;p&gt;Kafka Server.&lt;/p&gt;&lt;p&gt;Stores all messages.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Broker 1

Broker 2

Broker 3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Kafka Cluster = Collection of Brokers.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Topic&lt;/h2&gt;&lt;p&gt;Topic is a category.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Orders

Payments

Inventory

Shipping

Notification
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each topic contains messages.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Partition&lt;/h2&gt;&lt;p&gt;A Topic is divided into multiple partitions.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Orders Topic

---------------------

Partition 0

Partition 1

Partition 2

Partition 3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Partitions enable&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Parallel Processing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Scalability&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;High Throughput&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Offset&lt;/h2&gt;&lt;p&gt;Each message has an ID.&lt;/p&gt;&lt;p&gt;Kafka calls it Offset.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Offset

0

1

2

3

4

5
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Consumer remembers&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Last Offset = 5
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If application crashes&lt;/p&gt;&lt;p&gt;Restart&lt;/p&gt;&lt;p&gt;Continue from Offset 6.&lt;/p&gt;&lt;hr /&gt;&lt;h2&gt;Consumer&lt;/h2&gt;&lt;p&gt;Reads messages.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Inventory Service

Email Service

Analytics Service

Notification Service
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Consumer Group&lt;/h2&gt;&lt;p&gt;Multiple consumers work together.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Consumer Group

Inventory-1

Inventory-2

Inventory-3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Kafka distributes partitions.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Partition0 → Consumer1

Partition1 → Consumer2

Partition2 → Consumer3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;No duplication.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Queue vs Topic&lt;/h1&gt;&lt;p&gt;This is one of the most asked interview questions.&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;Traditional Queue&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Producer

↓

Queue

↓

Consumer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Only ONE consumer gets message.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Queue

Message

↓

Consumer A

Consumer B

Consumer C
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Only Consumer A receives.&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;Kafka Topic&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Producer

↓

Topic

↓

Consumer Group A

Consumer Group B

Consumer Group C
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;All groups receive same message.&lt;/p&gt;&lt;p&gt;Inside a group,&lt;/p&gt;&lt;p&gt;only one consumer receives.&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;Example&lt;/p&gt;&lt;p&gt;Order Created&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Orders Topic&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Inventory Group&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Email Group&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Analytics Group&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Shipping Group&lt;/p&gt;&lt;p&gt;Everyone gets copy.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Real Example&lt;/h1&gt;&lt;p&gt;Customer Orders Mobile.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Order API

↓

Kafka Topic

↓

Payment

↓

Inventory

↓

Email

↓

SMS

↓

Analytics

↓

Recommendation Engine
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Single Event&lt;/p&gt;&lt;p&gt;Many Consumers.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Queue vs Topic Comparison&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Queue&lt;/th&gt;&lt;th&gt;Kafka Topic&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;One Consumer&lt;/td&gt;&lt;td&gt;Multiple Consumer Groups&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Message Removed&lt;/td&gt;&lt;td&gt;Message Retained&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Point-to-Point&lt;/td&gt;&lt;td&gt;Publish Subscribe&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Low Scalability&lt;/td&gt;&lt;td&gt;Very High&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Low Throughput&lt;/td&gt;&lt;td&gt;Millions/sec&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;Message Flow&lt;/h1&gt;&lt;pre&gt;&lt;code&gt;Customer

↓

Angular

↓

.NET API

↓

Kafka Producer

↓

Orders Topic

↓

Broker

↓

Partition

↓

Consumer Group

↓

Inventory Service

↓

SQL

↓

Notification

↓

Email
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Kafka Storage&lt;/h1&gt;&lt;p&gt;Many developers ask&lt;/p&gt;&lt;p&gt;Where does Kafka save messages?&lt;/p&gt;&lt;p&gt;Kafka stores messages&lt;/p&gt;&lt;p&gt;Inside&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Topic

↓

Partition

↓

Log Files
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;orders-0.log

orders-1.log

orders-2.log
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Messages are appended.&lt;/p&gt;&lt;p&gt;Kafka never inserts in middle.&lt;/p&gt;&lt;p&gt;Only append.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Offset 0

Offset 1

Offset 2

Offset 3
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Kafka Message Format&lt;/h1&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Key

OrderId=1001

Value

{
OrderId:1001,
Customer:&quot;John&quot;,
Amount:2500
}
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Replication&lt;/h1&gt;&lt;p&gt;Suppose&lt;/p&gt;&lt;p&gt;Broker1 crashes.&lt;/p&gt;&lt;p&gt;Without replication&lt;/p&gt;&lt;p&gt;Data Lost.&lt;/p&gt;&lt;p&gt;With replication&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Broker1

Leader

↓

Broker2

Follower

↓

Broker3

Follower
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If Leader dies&lt;/p&gt;&lt;p&gt;Follower becomes Leader.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Producer Acknowledgement&lt;/h1&gt;&lt;p&gt;acks=0&lt;/p&gt;&lt;p&gt;Fire and Forget&lt;/p&gt;&lt;p&gt;Fastest&lt;/p&gt;&lt;p&gt;Risky&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;acks=1&lt;/p&gt;&lt;p&gt;Leader confirms.&lt;/p&gt;&lt;p&gt;Most common.&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;acks=all&lt;/p&gt;&lt;p&gt;All replicas confirm.&lt;/p&gt;&lt;p&gt;Safest.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Delivery Guarantee&lt;/h1&gt;&lt;p&gt;At Most Once&lt;/p&gt;&lt;p&gt;No Retry&lt;/p&gt;&lt;p&gt;May Lose.&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;At Least Once&lt;/p&gt;&lt;p&gt;Retry Enabled&lt;/p&gt;&lt;p&gt;Duplicate Possible.&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;Exactly Once&lt;/p&gt;&lt;p&gt;No Duplicate&lt;/p&gt;&lt;p&gt;No Loss&lt;/p&gt;&lt;p&gt;Used for Banking.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Kafka Ordering&lt;/h1&gt;&lt;p&gt;Ordering guaranteed only&lt;/p&gt;&lt;p&gt;within a partition.&lt;/p&gt;&lt;p&gt;Example&lt;/p&gt;&lt;p&gt;Partition0&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Order1

Order2

Order3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Always maintained.&lt;/p&gt;&lt;p&gt;Across partitions&lt;/p&gt;&lt;p&gt;No guarantee.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Why Partitions?&lt;/h1&gt;&lt;p&gt;Imagine&lt;/p&gt;&lt;p&gt;10 Million Orders.&lt;/p&gt;&lt;p&gt;One partition&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Single Consumer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Slow.&lt;/p&gt;&lt;p&gt;10 partitions&lt;/p&gt;&lt;pre&gt;&lt;code&gt;10 Consumers
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;10x faster.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;.NET Core Integration&lt;/h1&gt;&lt;p&gt;Architecture&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Angular

↓

.NET API

↓

Kafka Producer

↓

Kafka Broker

↓

Inventory Service

↓

SQL Server
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Install Package&lt;/h2&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Confluent.Kafka
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Producer Example&lt;/h2&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Confluent.Kafka;

var config = new ProducerConfig
{
    BootstrapServers=&quot;localhost:9092&quot;
};

using var producer =
new ProducerBuilder&amp;lt;string,string&amp;gt;(config)
.Build();

await producer.ProduceAsync(
&quot;orders&quot;,
new Message&amp;lt;string,string&amp;gt;
{
    Key=&quot;1001&quot;,
    Value=&quot;{OrderId:1001}&quot;
});
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Producer sends&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Topic

orders
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Consumer Example&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var config =
new ConsumerConfig
{
BootstrapServers=&quot;localhost:9092&quot;,
GroupId=&quot;inventory-group&quot;,
AutoOffsetReset=AutoOffsetReset.Earliest
};

using var consumer =
new ConsumerBuilder&amp;lt;string,string&amp;gt;(config)
.Build();

consumer.Subscribe(&quot;orders&quot;);

while(true)
{
var result=consumer.Consume();

Console.WriteLine(result.Message.Value);
}
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;ASP.NET Core Web API&lt;/h1&gt;&lt;p&gt;Angular&lt;/p&gt;&lt;pre&gt;&lt;code&gt;POST

/api/orders
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Controller&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[HttpPost]
public async Task&amp;lt;IActionResult&amp;gt; Create(OrderDto order)
{
await producer.Publish(order);

return Ok();
}
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;p&gt;Producer Service&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await _producer.ProduceAsync(
&quot;orders&quot;,
message);
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Angular&lt;/h1&gt;&lt;p&gt;Order Service&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;createOrder(order:any){

return this.http.post(
&quot;/api/orders&quot;,
order);

}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Component&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;submit(){

this.orderService
.createOrder(this.order)
.subscribe();
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Angular never talks directly to Kafka.&lt;/p&gt;&lt;p&gt;Reason&lt;/p&gt;&lt;p&gt;Kafka is backend infrastructure.&lt;/p&gt;&lt;p&gt;Angular&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Web API&lt;/p&gt;&lt;p&gt;↓&lt;/p&gt;&lt;p&gt;Kafka&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Complete Flow&lt;/h1&gt;&lt;pre&gt;&lt;code&gt;Angular

↓

Web API

↓

Kafka Producer

↓

Orders Topic

↓

Broker

↓

Partition

↓

Consumer Group

↓

Inventory Service

↓

Database

↓

Notification

↓

Email
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Kafka vs RabbitMQ&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Kafka&lt;/th&gt;&lt;th&gt;RabbitMQ&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Event Streaming&lt;/td&gt;&lt;td&gt;Message Queue&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Huge Throughput&lt;/td&gt;&lt;td&gt;Moderate&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Log Based&lt;/td&gt;&lt;td&gt;Queue Based&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Message Retention&lt;/td&gt;&lt;td&gt;Message Deleted&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Replay Possible&lt;/td&gt;&lt;td&gt;Difficult&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Analytics&lt;/td&gt;&lt;td&gt;Task Processing&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;hr /&gt;&lt;h1&gt;Kafka in Microservices&lt;/h1&gt;&lt;p&gt;Example&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Customer Created

↓

customer-created topic

↓

Billing

↓

CRM

↓

Analytics

↓

Notification

↓

Search Index
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;No service depends on another.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Docker&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;version: &#39;3&#39;

services:

  kafka:

    image: bitnami/kafka
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Run&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;docker compose up
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;Azure Integration&lt;/h1&gt;&lt;p&gt;Kafka can integrate with&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Event Hubs (Kafka-compatible endpoint)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Kubernetes Service (AKS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Container Apps&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Virtual Machines&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Monitor&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Key Vault (Secrets)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure DevOps (CI/CD)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Best Practices&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use meaningful topic names (e.g., &lt;code inline=&quot;&quot;&gt;orders.created.v1&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Keep events immutable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Prefer Avro or Protobuf with a Schema Registry over raw JSON for large systems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use keys that preserve ordering (for example, &lt;code inline=&quot;&quot;&gt;OrderId&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid very large messages; store large files externally and publish references.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configure retry, idempotent producers, and dead-letter handling where appropriate.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitor consumer lag and broker health.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Plan partition counts based on expected throughput and consumer parallelism.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;Common Interview Questions&lt;/h1&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;What is Apache Kafka?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Explain Kafka architecture.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is a Broker?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is a Topic?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is a Partition?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is an Offset?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Explain Consumer Groups.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Difference between Queue and Topic.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kafka vs RabbitMQ.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Why are partitions needed?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How does Kafka guarantee ordering?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What happens when a broker fails?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is replication factor?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What are producer acknowledgements (&lt;code inline=&quot;&quot;&gt;acks&lt;/code&gt;)?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is consumer lag?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is idempotent producer?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is exactly-once processing?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is the role of Schema Registry?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How do you scale Kafka consumers?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How do you integrate Kafka with .NET Core?&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;Complete E-Commerce Example&lt;/h2&gt;&lt;pre&gt;&lt;code&gt;                Angular UI
                     │
                     ▼
         ASP.NET Core Web API
                     │
                     ▼
            Kafka Producer Service
                     │
                     ▼
         ┌──────────────────────────┐
         │      Orders Topic         │
         └──────────────────────────┘
            │       │        │
            ▼       ▼        ▼
     Inventory   Payment   Analytics
       Service    Service     Service
            │       │        │
            ▼       ▼        ▼
      SQL Server  Email   Data Warehouse
                     │
                     ▼
              Notification Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A customer clicks &lt;strong&gt;Place Order&lt;/strong&gt; in Angular. The Angular app calls the ASP.NET Core API. The API validates the request, stores the order (if following the Outbox pattern), and publishes an &lt;code inline=&quot;&quot;&gt;OrderCreated&lt;/code&gt; event to Kafka. Kafka persists the event in the &lt;code inline=&quot;&quot;&gt;orders&lt;/code&gt; topic, making it available to multiple consumer groups. Inventory reserves stock, Payment charges the customer, Analytics records the event, and Notification sends an email—all independently and asynchronously.&lt;/p&gt;&lt;p&gt;This decoupled architecture improves scalability, resilience, and maintainability because producers and consumers evolve independently.&lt;/p&gt;&lt;p&gt;For a production-grade implementation, the next topics to master are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Kafka internals (segments, ISR, leader election, page cache)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;KRaft architecture (ZooKeeper-free Kafka)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Schema Registry with Avro/Protobuf&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Outbox Pattern with .NET and Entity Framework Core&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Saga Pattern with Kafka&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Retry topics and Dead Letter Topics (DLT)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Idempotent consumers and exactly-once semantics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring with Prometheus and Grafana&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deploying Kafka on Docker, Kubernetes, and Azure&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;End-to-end .NET 9 microservices with Angular 20 and Kafka using Clean Architecture and CQRS&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These advanced topics are commonly expected in senior .NET Lead and Technical Architect interviews.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Interview Questions And Answers :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://umamaheswarb.blogspot.com/2026/08/apache-kafka-interview-questions-answers.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;Apache Kafka Interview Questions And Answers&lt;/b&gt;&lt;/a&gt;&lt;/h4&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/1236074523445752150/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/1236074523445752150' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1236074523445752150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/1236074523445752150'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/apache-kafka.html' title='Apache Kafka'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6aZTN8hQO5tvYNNIy0cPUobnhTrHqkDDDXUwfoWM8bDza2nO9o3x4uMq83OBo0UmUY_eXB-hb_6eUz3wV3ILLx0Q6SA6cX2qMFy6gkT3BJe7Q-kb2SY9z09JfdcmVyz1rVJwgqoR7M91yhL02eeIZjtCua0v2T-gerdLS4LNvokGJgBRprQqkPlmIDAk/s72-c/KafkaTutorials.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274440498886912486.post-8613112031305954604</id><published>2026-08-02T10:44:17.208+05:30</published><updated>2026-08-02T10:44:17.208+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure API Management"/><title type='text'>Azure API Management</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhU9VXOjjWKhP0hyphenhyphenZiFT2BcxnEF1c6G1EEsvAoqdTb_mR42MYQr9xpj3LQrBl4nEyVWPv3iRHcdXQWtgcLKBORztnjKJL99X_98YX6QfA-xAs2i_L2iAffCUYGQIkA7dVzonfX0PC9zSPi4mmx0H2bdNRAsfa0G92ynXsHhB5gVBdbmyrQPW080exnMlWc/s1536/AzureAPIManagement.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1536&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhU9VXOjjWKhP0hyphenhyphenZiFT2BcxnEF1c6G1EEsvAoqdTb_mR42MYQr9xpj3LQrBl4nEyVWPv3iRHcdXQWtgcLKBORztnjKJL99X_98YX6QfA-xAs2i_L2iAffCUYGQIkA7dVzonfX0PC9zSPi4mmx0H2bdNRAsfa0G92ynXsHhB5gVBdbmyrQPW080exnMlWc/s320/AzureAPIManagement.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;h1&gt;Azure API Management (APIM) — Complete Guide for .NET Lead&lt;/h1&gt;&lt;p&gt;Azure API Management (APIM) is one of the most important Azure services for &lt;strong&gt;.NET Developers, Technical Leads, Solution Architects, and Cloud Engineers&lt;/strong&gt;. It acts as a &lt;strong&gt;central gateway&lt;/strong&gt; between clients and your backend APIs, providing &lt;strong&gt;security, routing, authentication, throttling, monitoring, versioning, transformation, caching, and developer onboarding&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Official Documentation&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/api-management/?utm_source=chatgpt.com&quot;&gt;Azure API Management Documentation&lt;/a&gt;&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;Table of Contents&lt;/h1&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;What is Azure API Management?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Why Do We Need APIM?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;APIM Architecture&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Components of APIM&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Real-Time Enterprise Example&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Request Flow&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Policies&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Authentication &amp;amp; Authorization&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Rate Limiting &amp;amp; Throttling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API Versioning&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API Products &amp;amp; Subscriptions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Portal&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API Transformation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Caching&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure DevOps Integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;C# Web API Example&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Best Practices&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Lead-Level Interview Questions&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr /&gt;&lt;h1&gt;1. What is Azure API Management?&lt;/h1&gt;&lt;p&gt;Azure API Management is a &lt;strong&gt;fully managed API Gateway&lt;/strong&gt; that sits between API consumers and backend services.&lt;/p&gt;&lt;p&gt;Instead of exposing your APIs directly:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Client
   |
ASP.NET Core API
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You expose them through APIM:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Client
    |
Azure API Management
    |
ASP.NET Core API
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;APIM becomes the single entry point for all APIs.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;2. Why Do We Need APIM?&lt;/h1&gt;&lt;p&gt;Imagine an enterprise has:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Mobile App&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Angular Web App&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Partner APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Internal APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Third-party integrations&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Without APIM:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Mobile  ------\
Angular -------\
Partner --------&amp;gt; Order API
Portal --------/
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each client communicates directly with every API.&lt;/p&gt;&lt;p&gt;Problems:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;No centralized security&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Duplicate authentication logic&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;No rate limiting&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Difficult monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Hard API version management&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;p&gt;With APIM:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Clients
    |
Azure API Management
    |
-------------------------------------
| Order API
| Payment API
| Inventory API
| Notification API
-------------------------------------
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Everything is managed centrally.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;3. Real-Time Banking Architecture&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 Mobile App
                      |
                 Internet Banking
                      |
                 Partner Portal
                      |
               Azure API Management
                      |
-------------------------------------------------
| Account API
| Payment API
| Card API
| Loan API
| Notification API
-------------------------------------------------
                      |
Azure SQL | Service Bus | Redis | Key Vault
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;4. APIM Components&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Azure API Management
        |
+----------------------------+
| API Gateway                |
| Policies                   |
| Security                   |
| Analytics                  |
| Developer Portal           |
| Products                   |
| Subscriptions              |
+----------------------------+
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;5. Core Features&lt;/h1&gt;&lt;p&gt;Azure API Management provides:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;API Gateway&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Authentication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Authorization&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Rate Limiting&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Throttling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Caching&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API Versioning&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API Revisions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Request/Response Transformation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring &amp;amp; Analytics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Portal&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Subscription Keys&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;OAuth 2.0 / OpenID Connect integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JWT Validation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;IP Filtering&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Custom Domains&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Certificates&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;6. Request Flow&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Client
   |
HTTPS Request
   |
Azure API Management
   |
Validate JWT
Check Subscription
Apply Policies
Rate Limit
Cache Check
Transform Request
   |
ASP.NET Core API
   |
Azure SQL Database
   |
Response
   |
Transform Response
   |
Client
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;7. Real-Time Insurance Example&lt;/h1&gt;&lt;p&gt;Customer submits claim.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Mobile App

↓

API Management

↓

JWT Validation

↓

Claim API

↓

Azure SQL

↓

Azure Service Bus

↓

Notification Service
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Every request passes through APIM.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;8. API Gateway&lt;/h1&gt;&lt;p&gt;The gateway:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Receives requests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validates security&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Applies policies&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Routes requests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Logs telemetry&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Returns responses&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Without changing backend code.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;9. API Import&lt;/h1&gt;&lt;p&gt;APIs can be imported from:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;OpenAPI (Swagger)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;ASP.NET Core Web API&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Functions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Logic Apps&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;WSDL (SOAP)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Existing HTTP APIs&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;10. Authentication&lt;/h1&gt;&lt;p&gt;Supports:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Microsoft Entra ID&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;OAuth 2.0&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;OpenID Connect&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JWT Tokens&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Subscription Keys&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Client Certificates&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;11. JWT Validation&lt;/h1&gt;&lt;p&gt;Instead of validating JWT inside every API:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Client

↓

JWT

↓

API Management

↓

Valid Token

↓

Backend API
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Invalid tokens are rejected before reaching the backend.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;12. Subscription Keys&lt;/h1&gt;&lt;p&gt;Each client receives:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Primary Key

Secondary Key
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Clients include the subscription key in requests.&lt;/p&gt;&lt;p&gt;APIM validates the key before forwarding the request.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;13. Rate Limiting&lt;/h1&gt;&lt;p&gt;Suppose:&lt;/p&gt;&lt;p&gt;Customer sends&lt;/p&gt;&lt;pre&gt;&lt;code&gt;10,000 requests/sec
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Without APIM:&lt;/p&gt;&lt;p&gt;API crashes.&lt;/p&gt;&lt;p&gt;With APIM:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Allowed

↓

100 requests/minute

↓

429 Too Many Requests
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This protects backend services.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;14. Throttling&lt;/h1&gt;&lt;p&gt;Example Policy:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot;&gt;&amp;lt;rate-limit calls=&quot;100&quot;
            renewal-period=&quot;60&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Meaning:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;100 requests

Every

60 seconds
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;15. API Versioning&lt;/h1&gt;&lt;p&gt;Suppose API evolves.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;v1

/api/customers
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;New version:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;v2

/api/customers
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Both versions can run simultaneously.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;16. Revisions&lt;/h1&gt;&lt;p&gt;Version:&lt;/p&gt;&lt;p&gt;Breaking changes&lt;/p&gt;&lt;p&gt;Revision:&lt;/p&gt;&lt;p&gt;Minor changes&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Version 1

Revision 1

↓

Revision 2

↓

Revision 3
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;17. Products&lt;/h1&gt;&lt;p&gt;A Product groups APIs.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Partner Product

↓

Customer API

Order API

Payment API
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Partners subscribe to products rather than individual APIs.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;18. Developer Portal&lt;/h1&gt;&lt;p&gt;Developers can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Browse APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Read documentation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Test APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generate subscription keys&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Download OpenAPI specs&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;19. Policies&lt;/h1&gt;&lt;p&gt;Policies are XML-based rules executed by APIM.&lt;/p&gt;&lt;p&gt;Examples:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Validate JWT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add Headers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Remove Headers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Rewrite URL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Rate Limit&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;IP Filter&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cache&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Retry&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Mock Response&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot;&gt;&amp;lt;set-header name=&quot;X-App&quot;&amp;gt;
    &amp;lt;value&amp;gt;OneView&amp;lt;/value&amp;gt;
&amp;lt;/set-header&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;20. Request Transformation&lt;/h1&gt;&lt;p&gt;Client sends:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;customer&quot;:&quot;Mahesh&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;APIM transforms:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;CustomerName&quot;:&quot;Mahesh&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;No backend code changes required.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;21. Response Transformation&lt;/h1&gt;&lt;p&gt;Backend returns:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
 &quot;CustomerName&quot;:&quot;Mahesh&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;APIM transforms:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
 &quot;name&quot;:&quot;Mahesh&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;22. Caching&lt;/h1&gt;&lt;p&gt;Without Cache:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Client

↓

API

↓

SQL
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Every request hits SQL.&lt;/p&gt;&lt;p&gt;With Cache:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Client

↓

APIM Cache

↓

Response
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Reduces latency and database load.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;23. Monitoring&lt;/h1&gt;&lt;p&gt;Integrated with:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure Monitor&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Application Insights&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Log Analytics&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Monitor:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Requests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Response Time&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Failures&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Backend Latency&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Subscription Usage&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;24. Azure DevOps Integration&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Developer

↓

Git

↓

Azure DevOps

↓

Build

↓

Deploy API

↓

Azure API Management

↓

Production
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;API definitions and policies can be deployed as part of CI/CD pipelines.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;25. ASP.NET Core API Example&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

var app = builder.Build();

app.MapControllers();

app.Run();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Deploy the API to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Azure App Service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Kubernetes Service (AKS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Container Apps&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Azure Functions&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Then expose it securely through APIM.&lt;/p&gt;&lt;hr /&gt;&lt;h1&gt;26. Enterprise Architecture&lt;/h1&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Users
     |
Azure Front Door
     |
Azure API Management
     |
-----------------------------------------
| Order API
| Payment API
| Customer API
| Inventory API
-----------------------------------------
     |
Azure SQL
Azure Service Bus
Azure Storage
Azure Key Vault
Application Insights
&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h1&gt;27. Best Practices&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Never expose backend APIs directly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use Microsoft Entra ID or OAuth 2.0.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validate JWT at the gateway.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enable rate limiting and quotas.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use API versioning instead of breaking changes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Apply caching for read-heavy endpoints.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secure secrets with Azure Key Vault.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitor with Azure Monitor and Application Insights.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use separate APIM instances or products for different environments when appropriate.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automate deployments with Azure DevOps.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt;&lt;h1&gt;28. Frequently Asked Interview Questions&lt;/h1&gt;&lt;h2&gt;Basic&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;What is Azure API Management?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Why do we use APIM?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is an API Gateway?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What are Products?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What are Subscription Keys?&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr /&gt;&lt;h2&gt;Intermediate&lt;/h2&gt;&lt;ol start=&quot;6&quot;&gt;&lt;li&gt;&lt;p&gt;Explain APIM policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How does JWT validation work?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Difference between Version and Revision?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How does rate limiting work?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is request transformation?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is response transformation?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is API caching?&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr /&gt;&lt;h2&gt;Lead-Level&lt;/h2&gt;&lt;ol start=&quot;13&quot;&gt;&lt;li&gt;&lt;p&gt;Design an enterprise API architecture using APIM.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How would you secure hundreds of APIs?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How would you onboard external partners?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How would you implement zero-downtime API versioning?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How would you monitor API performance?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How would you implement CI/CD for APIM?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How would you integrate APIM with AKS and Azure Functions?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;When would you choose APIM over exposing APIs directly?&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr /&gt;&lt;h1&gt;29. Lead-Level Interview Answer&lt;/h1&gt;&lt;p&gt;&lt;strong&gt;Interviewer:&lt;/strong&gt; &lt;em&gt;&quot;How have you used Azure API Management in your project?&quot;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&quot;In our enterprise .NET microservices platform, Azure API Management served as the single entry point for all client applications, including web, mobile, and partner integrations. We used APIM to enforce JWT authentication with Microsoft Entra ID, apply rate limiting and quotas, transform requests and responses, manage API versions, and expose APIs through Products and Subscription Keys. Backend services were hosted on Azure App Service and AKS, while Azure Monitor and Application Insights provided end-to-end observability. API deployments and policy updates were automated using Azure DevOps pipelines, ensuring secure, consistent, and zero-downtime releases across development, QA, and production environments.&quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr /&gt;&lt;h1&gt;30. APIM vs Azure Application Gateway vs Azure Front Door&lt;/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Azure API Management&lt;/th&gt;&lt;th&gt;Application Gateway&lt;/th&gt;&lt;th&gt;Azure Front Door&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Primary Purpose&lt;/td&gt;&lt;td&gt;API Gateway &amp;amp; API Lifecycle&lt;/td&gt;&lt;td&gt;Layer 7 Web Traffic Load Balancer&lt;/td&gt;&lt;td&gt;Global Entry Point &amp;amp; CDN&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Authentication&lt;/td&gt;&lt;td&gt;✅ Yes&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Rate Limiting&lt;/td&gt;&lt;td&gt;✅ Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Basic WAF/Rules&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;API Versioning&lt;/td&gt;&lt;td&gt;✅ Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Developer Portal&lt;/td&gt;&lt;td&gt;✅ Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Request/Response Transformation&lt;/td&gt;&lt;td&gt;✅ Yes&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Global Routing&lt;/td&gt;&lt;td&gt;Regional (can be combined)&lt;/td&gt;&lt;td&gt;Regional&lt;/td&gt;&lt;td&gt;✅ Global&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Typical Use&lt;/td&gt;&lt;td&gt;Secure and manage APIs&lt;/td&gt;&lt;td&gt;Route web traffic&lt;/td&gt;&lt;td&gt;Global traffic acceleration and failover&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;h3&gt;When to use each&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Azure API Management&lt;/strong&gt;: When you need API security, governance, versioning, throttling, analytics, and developer onboarding.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Azure Application Gateway&lt;/strong&gt;: When you need Layer 7 load balancing, SSL termination, and Web Application Firewall (WAF) for web applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Azure Front Door&lt;/strong&gt;: When you need global load balancing, edge acceleration, CDN capabilities, and multi-region failover.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For large enterprise systems, it&#39;s common to use them together:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Users
   |
Azure Front Door
   |
Application Gateway (optional, depending on architecture)
   |
Azure API Management
   |
ASP.NET Core APIs / Azure Functions / AKS
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This layered approach provides global availability, web protection, and centralized API governance.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://umamaheswarb.blogspot.com/feeds/8613112031305954604/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4274440498886912486/8613112031305954604' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/8613112031305954604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274440498886912486/posts/default/8613112031305954604'/><link rel='alternate' type='text/html' href='http://umamaheswarb.blogspot.com/2026/08/azure-api-management.html' title='Azure API Management'/><author><name>Umaamaheswar rao</name><uri>http://www.blogger.com/profile/14821609593871905916</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhU9VXOjjWKhP0hyphenhyphenZiFT2BcxnEF1c6G1EEsvAoqdTb_mR42MYQr9xpj3LQrBl4nEyVWPv3iRHcdXQWtgcLKBORztnjKJL99X_98YX6QfA-xAs2i_L2iAffCUYGQIkA7dVzonfX0PC9zSPi4mmx0H2bdNRAsfa0G92ynXsHhB5gVBdbmyrQPW080exnMlWc/s72-c/AzureAPIManagement.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>