Tuesday, August 18, 2026

Retrieval-Augmented Generation (RAG): Complete Guide with Architecture, Real-Time Examples and .NET Implementation

Introduction

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:

An LLM does not automatically know your organization's private, frequently changing, or newly created information.

For example, imagine a company has:

  • 10,000 internal documents

  • HR policies

  • Product manuals

  • Customer records

  • Technical documentation

  • Financial reports

  • Support tickets

  • Project documents

  • Frequently changing business data

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.

This is where RAG — Retrieval-Augmented Generation becomes extremely useful.

RAG allows an AI application to:

  1. Receive a user's question.

  2. Search an external knowledge source.

  3. Retrieve the most relevant information.

  4. Give that information to an LLM.

  5. Generate an answer grounded in the retrieved information.

In simple terms:

RAG = Search for relevant knowledge + Give it to the LLM + Generate an answer


1. What is RAG?

RAG stands for:

Retrieval-Augmented Generation

It combines two major capabilities:

Retrieval

Find relevant information from an external knowledge source.

Generation

Use an LLM to generate a natural-language answer using that retrieved information.

A simplified representation is:

User Question
      |
      v
   Retriever
      |
      v
Relevant Documents
      |
      v
   LLM / GPT
      |
      v
Generated Answer

For example:

User asks:

"What is our company's leave policy for employees with more than 5 years of service?"

The LLM itself may not know your company's policy.

A RAG system searches your company's HR documents, finds the relevant policy, and passes it to the LLM.

The LLM then answers:

"According to the company's leave policy, employees with more than five years of service are eligible for ..."

The important part is that the answer is based on your organization's data.


2. Who Invented RAG?

RAG was not created as a commercial product by a single company.

The term and a well-known formal RAG architecture were introduced in the research paper:

"Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks"

published in 2020.

The paper was authored by:

  • Patrick Lewis

  • Ethan Perez

  • Aleksandra Piktus

  • Fabio Petroni

  • Vladimir Karpukhin

  • Naman Goyal

  • Heinrich Küttler

  • Mike Lewis

  • Wen-tau Yih

  • Tim Rocktäschel

  • Sebastian Riedel

  • Douwe Kiela

The paper described RAG models that combine a pretrained sequence-to-sequence model with a dense vector index used as external non-parametric memory.

The original work was associated with the Facebook AI Research ecosystem, now part of Meta AI.

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's REALM research also explored retrieval-augmented language modeling in 2020.

Therefore:

RAG is a research architecture/pattern, not a programming language or a single software product.


3. In Which Programming Language Was RAG Developed?

This is one of the most common misconceptions.

RAG is not a programming language.

It is an AI architecture/pattern.

You can implement RAG using many programming languages.

Common choices include:

LanguageTypical Usage
PythonAI/ML, RAG experimentation, LangChain, LlamaIndex
C#Enterprise .NET applications
JavaEnterprise applications
JavaScript/TypeScriptNode.js applications
GoHigh-performance backend services
C++High-performance AI infrastructure

Python is particularly popular in AI research because of its extensive machine-learning ecosystem.

But a company building an enterprise application using:

  • ASP.NET Core

  • Angular

  • Azure

  • SQL Server

can implement RAG using C#/.NET.


4. Why Was RAG Needed?

Traditional LLM architecture looks like this:

User
 |
 v
LLM
 |
 v
Answer

The model relies primarily on knowledge encoded in its parameters.

This creates several problems.

Problem 1 — Private Data

Suppose your company has:

EmployeePolicy.pdf
ProductManual.pdf
CustomerSupport.pdf
Architecture.docx
ProjectDocumentation.pdf

The public LLM does not automatically know these documents.


Problem 2 — Frequently Changing Data

Imagine asking:

"What is today's product inventory?"

The answer may change every hour.

You don't want to retrain an LLM every time inventory changes.


Problem 3 — Hallucination

An LLM can sometimes generate information that sounds convincing but is incorrect.

RAG can reduce this risk by supplying relevant source information to the model.

However:

RAG does not completely eliminate hallucinations.

Research continues to show that insufficient or poor-quality retrieved context can still cause incorrect answers.


5. Main Purpose of RAG

The primary purpose of RAG is:

To allow an LLM to use external, relevant and potentially up-to-date knowledge while generating an answer.

This provides several benefits:

1. Access private information

Example:

Company HR Documents
Company Technical Documents
Company Product Documents

2. Access frequently changing information

Example:

Inventory
Prices
Policies
News
Tickets
Orders

3. Reduce hallucination

The model can use retrieved evidence instead of relying entirely on its internal knowledge.

4. Provide source references

A well-designed RAG application can show:

Source:
Employee_Leave_Policy.pdf
Page 12

5. Avoid retraining for every document update

Instead of retraining the LLM whenever a document changes:

Update Document
      |
      v
Update Knowledge Index
      |
      v
RAG uses new information

6. RAG Architecture

A typical RAG system looks like this:

                  ┌──────────────────┐
                  │     User         │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ User Question    │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Query Processing │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Embedding Model  │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Vector Database  │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Relevant Chunks  │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Prompt + Context │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │       LLM        │
                  └────────┬─────────┘
                           |
                           v
                  ┌──────────────────┐
                  │ Final Answer     │
                  └──────────────────┘

7. The Two Major Parts of RAG

A RAG system generally has two major workflows:

A. Data Ingestion

This happens before users ask questions.

Documents
   |
   v
Document Extraction
   |
   v
Chunking
   |
   v
Embeddings
   |
   v
Vector Database

B. Query Processing

This happens when the user asks a question.

User Question
   |
   v
Embedding
   |
   v
Vector Search
   |
   v
Relevant Chunks
   |
   v
LLM
   |
   v
Answer

Understanding these two pipelines is essential for understanding RAG.


8. What Is an Embedding?

An embedding converts text into a numerical representation called a vector.

For example:

"How can I reset my password?"

might be represented conceptually as:

[0.21, -0.45, 0.73, 0.11, ...]

Real embedding vectors can contain hundreds or thousands of dimensions depending on the embedding model.

The important concept is:

Similar meanings produce vectors that are close to each other in vector space.

For example:

"How do I change my password?"

and:

"What is the procedure for resetting my password?"

have different words but similar meaning.

Their embeddings should therefore be semantically similar.


9. Why Do We Need a Vector Database?

Suppose you have:

1,000 documents
10,000 documents
1 million documents

Searching all the text directly for every question can become inefficient.

A vector database stores embeddings and allows similarity searches.

Common technologies include:

  • Azure AI Search

  • PostgreSQL with pgvector

  • Elasticsearch

  • OpenSearch

  • Pinecone

  • Weaviate

  • Milvus

  • Qdrant

  • Chroma

  • Redis with vector search capabilities

The exact technology depends on your architecture and requirements.


10. What Is a Vector Database?

A vector database stores data such as:

Document ID
Chunk ID
Text
Embedding
Metadata

Example:

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

11. Document Chunking

One of the most important steps in RAG is chunking.

Suppose a PDF contains 100 pages.

You generally should not send the entire PDF to the LLM for every question.

Instead, divide it into smaller pieces.

For example:

Document
   |
   +---- Chunk 1
   |
   +---- Chunk 2
   |
   +---- Chunk 3
   |
   +---- Chunk 4
   |
   +---- Chunk 5

A chunk might contain:

500–1000 tokens

The exact size should be determined experimentally based on the document type and retrieval quality.


12. Chunk Overlap

Sometimes important information crosses chunk boundaries.

For example:

Chunk 1:
Employees are eligible for annual leave after completing...

Chunk 2:
...one year of continuous service.

If there is no overlap, retrieval may lose context.

Therefore, systems may use overlapping chunks.

Example:

Chunk 1
---------------------
A B C D E F G H

Chunk 2
              E F G H I J K L

The overlap improves the chance that related information remains together.


13. Metadata

Metadata is extremely important in enterprise RAG.

Example:

{
  "documentId": "HR-2026-001",
  "department": "HR",
  "documentType": "LeavePolicy",
  "year": 2026,
  "region": "India"
}

Metadata allows filtering.

For example:

"Search only HR documents from 2026."

Instead of searching the entire knowledge base:

Vector Search
+
Department = HR
+
Year = 2026

This is called metadata filtering.


14. End-to-End RAG Pipeline

Let's understand the complete process.

Step 1 — Upload Documents

Example:

HRPolicy.pdf

Step 2 — Extract Text

The system extracts text from:

PDF
DOCX
TXT
HTML
Web pages
Database

For scanned documents, OCR may be required.


Step 3 — Chunk the Text

Example:

HRPolicy.pdf

       |
       +-- Chunk 1
       +-- Chunk 2
       +-- Chunk 3
       +-- Chunk 4

Step 4 — Generate Embeddings

Each chunk is converted into a vector.

Chunk 1
   |
Embedding Model
   |
Vector

Step 5 — Store in Vector Database

Vector
+
Text
+
Metadata

is stored.


15. Query-Time Process

Now the user asks:

"How many annual leave days can I take?"

The system performs:

Question
   |
   v
Embedding
   |
   v
Vector Search
   |
   v
Top Relevant Chunks

Suppose the database returns:

Chunk 12
Chunk 27
Chunk 31

These are passed to the LLM.


16. Prompt Augmentation

The application creates a prompt similar to:

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?

The LLM then generates:

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

This is the generation part of RAG.


17. RAG vs Traditional LLM

FeatureTraditional LLMRAG
General knowledgeYesYes
Private company dataLimitedYes
Dynamic dataLimitedYes
External documentsNot automaticallyYes
Knowledge updatesModel-dependentUpdate knowledge source/index
Source citationsNot guaranteedCan be implemented
Hallucination riskExistsCan be reduced
Retraining required for every documentNo/dependsUsually no
Enterprise knowledge assistantLimitedExcellent fit

18. RAG vs Fine-Tuning

This is one of the most important concepts.

Fine-Tuning

Fine-tuning changes model behavior/weights using training examples.

Useful for:

Style
Behavior
Task specialization
Output format
Domain-specific behavior

RAG

RAG provides external knowledge at query time.

Useful for:

Private documents
Current information
Frequently changing information
Knowledge bases
Company policies
Product documentation

A simple rule:

Use RAG to give the model knowledge.

Use fine-tuning to change how the model behaves.

Sometimes enterprises use both.


19. Real-Time Example #1 — Company HR Assistant

Imagine a company has:

Employee Handbook
Leave Policy
Travel Policy
Insurance Policy
Work From Home Policy
Salary Policy

An employee asks:

"How many work-from-home days can I take?"

RAG:

User
 |
 v
Question
 |
 v
Embedding
 |
 v
Vector Search
 |
 v
HR Documents
 |
 v
Relevant Policy
 |
 v
LLM
 |
 v
Answer

The employee doesn't need to manually search hundreds of pages.


20. Real-Time Example #2 — Customer Support

Suppose an organization sells networking equipment.

Documents:

Router Manual
Switch Manual
Troubleshooting Guide
Warranty Policy
Installation Guide

Customer asks:

"My router is showing a red status light. What should I check?"

RAG retrieves the troubleshooting section.

The LLM generates a user-friendly answer based on the retrieved manual.

This is much better than asking the model to guess the troubleshooting procedure.


21. Real-Time Example #3 — Banking

A bank may have:

Loan Policy
Credit Card Policy
Interest Rate Policy
KYC Documentation
Account Rules
Product Terms

A customer asks:

"What documents are required for this loan?"

RAG retrieves the relevant policy.

The LLM summarizes it.

The application can also provide:

Source Document
Section
Page
Last Updated Date

This is particularly valuable for regulated environments.


22. Real-Time Example #4 — Software Development

Suppose your organization has:

Architecture Documents
API Documentation
Coding Standards
Database Documentation
Microservice Documentation
Deployment Documentation

A developer asks:

"How does the Customer Service communicate with the Order Service?"

RAG searches the architecture documentation.

It may retrieve:

Customer Service
      |
      v
Azure Service Bus
      |
      v
Order Service

The LLM can then explain the architecture.


23. Real-Time Example #5 — E-Commerce

Suppose an online store has:

Products
Prices
Inventory
Returns
Shipping Policies
Customer Orders

Customer asks:

"Can I return my order?"

RAG can retrieve the applicable return policy.

For dynamic information such as order status, the RAG application may also retrieve information directly from operational APIs or databases.

This leads to an important architecture:

LLM
 |
 +---- Vector Search
 |
 +---- SQL Database
 |
 +---- REST API
 |
 +---- Business Services

This is often more powerful than document-only RAG.


24. RAG With SQL Database

RAG does not mean everything has to be stored in a vector database.

Suppose you ask:

"How many orders did customer 10025 place last month?"

A vector database is not necessarily the right tool.

A better architecture may be:

User Question
      |
      v
Intent Detection
      |
      +------------------+
      |                  |
      v                  v
Document Search       SQL Query
      |                  |
      +--------+---------+
               |
               v
              LLM
               |
               v
            Answer

This is often called a hybrid/agentic architecture.


25. RAG + SQL Example

Question:

"What is our return policy?"

Use:

Vector Search

Question:

"How many orders were placed yesterday?"

Use:

SQL

Question:

"Why was customer 12345's order delayed?"

Potentially use:

SQL
+
Order API
+
Support tickets
+
RAG

The LLM can orchestrate the sources.


26. Semantic Search vs Keyword Search

Traditional search might search:

"password reset"

and look for exact words.

Semantic search understands meaning.

Question:

"I forgot my login credentials. How can I get back into my account?"

It can retrieve:

Password Reset Procedure

even though the exact phrase may not appear.

This is one of the major benefits of embeddings.


27. Hybrid Search

Modern enterprise RAG systems often combine:

Keyword Search
+
Vector Search

For example:

BM25 / keyword search
        +
Semantic vector search
        |
        v
Combined Results

Why?

Keyword search is excellent for exact identifiers such as:

INV-2026-00125
Customer ID 10045
Error E5001
API-123

Vector search is excellent for semantic meaning.

Combining both can improve retrieval quality.


28. Reranking

Retrieving the top 20 documents does not necessarily mean all 20 are equally relevant.

A reranker can evaluate them again.

Query
 |
 v
Retriever
 |
 v
Top 20 documents
 |
 v
Reranker
 |
 v
Top 5 documents
 |
 v
LLM

This can improve the quality of the context provided to the LLM.


29. Basic RAG Architecture for .NET

For your .NET ecosystem, an enterprise architecture could look like:

                    Angular
                       |
                       v
                 ASP.NET Core
                       |
             +---------+---------+
             |                   |
             v                   v
        RAG Service          Business APIs
             |
             v
      Embedding Service
             |
             v
       Azure AI Search
             |
             v
      Enterprise Documents
             |
             v
            LLM

Possible Azure components include:

Angular
   |
Azure App Service / Static Web Apps
   |
ASP.NET Core Web API
   |
Azure AI Search
   |
Azure OpenAI
   |
Blob Storage
   |
SQL Server / Azure SQL

The exact Azure services can vary depending on the application.


30. Simple C# RAG Flow

Conceptually:

public async Task<string> AskAsync(string question)
{
    var queryEmbedding =
        await embeddingService.CreateEmbeddingAsync(question);

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

    var context = string.Join(
        "\n\n",
        documents.Select(x => x.Content));

    var prompt = $"""
        Answer the question using only the context below.

        Context:
        {context}

        Question:
        {question}
        """;

    return await llm.GenerateAsync(prompt);
}

The important flow is:

Question
   ↓
Embedding
   ↓
Vector Search
   ↓
Relevant Documents
   ↓
Prompt
   ↓
LLM
   ↓
Answer

31. Document Ingestion in C#

Conceptually:

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
        });
    }
}

This creates the knowledge base.


32. RAG Application Using Angular + .NET

A practical enterprise solution could be:

                Angular
                   |
                   |
              HTTP / HTTPS
                   |
                   v
          ASP.NET Core Web API
                   |
           +-------+-------+
           |               |
           v               v
      RAG Service       Auth Service
           |
     +-----+------+
     |            |
     v            v
Embedding       Vector DB
Service
     |
     v
     LLM

Angular provides:

Chat UI
Document Upload
Source Display
Conversation History

ASP.NET Core provides:

Authentication
Authorization
RAG orchestration
Document processing
Business logic
API endpoints
Logging

33. Example API

A simple API could be:

POST /api/rag/ask

Request:

{
  "question": "What is the leave policy?"
}

Response:

{
  "answer": "Employees are eligible for annual leave...",
  "sources": [
    {
      "document": "LeavePolicy.pdf",
      "page": 12
    }
  ]
}

Angular can display:

Answer
--------------------------------
Employees are eligible for...

Sources
--------------------------------
LeavePolicy.pdf
Page 12

34. RAG Security

Enterprise RAG must take security seriously.

Suppose:

Employee A

should not access:

Employee B's salary information.

Simply storing everything in one vector index can create security problems.

The system should enforce:

User
 |
 v
Authentication
 |
 v
Authorization
 |
 v
Security Filter
 |
 v
Retrieval

Metadata can help:

{
  "department": "Finance",
  "classification": "Confidential",
  "allowedRoles": [
    "FinanceManager"
  ]
}

The retrieval layer should apply appropriate authorization filters before returning context.


35. RAG and JWT Authentication

In an ASP.NET Core enterprise application:

Angular
   |
   v
JWT
   |
   v
ASP.NET Core
   |
   v
User Claims
   |
   v
RAG Authorization
   |
   v
Filtered Retrieval

For example:

Role = HRManager
Department = HR

could result in:

Department = HR
AND
UserAuthorized = true

during retrieval.


36. RAG and Microservices

RAG fits naturally into microservice architecture.

Example:

                    API Gateway
                         |
          +--------------+--------------+
          |              |              |
          v              v              v
      User Service   Order Service   RAG Service
                                         |
                              +----------+----------+
                              |                     |
                              v                     v
                        Vector Search             LLM
                              |
                              v
                       Document Store

A dedicated RAG service can own:

Document ingestion
Chunking
Embedding
Retrieval
Reranking
Prompt construction
LLM interaction
Citation generation

37. RAG + Azure Service Bus

For large enterprise applications, document processing should not always happen synchronously.

For example:

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

This provides an asynchronous ingestion pipeline.


38. RAG + Blob Storage

A common Azure architecture:

                    Blob Storage
                         |
                         v
                Document Processor
                         |
                    Chunking
                         |
                    Embeddings
                         |
                         v
                  Azure AI Search
                         |
                         v
                    RAG API
                         |
                         v
                    Azure OpenAI

Documents can remain in Blob Storage while searchable chunks and metadata are stored in the search system.


39. RAG Evaluation

Building a RAG application is not just about making it work.

You need to measure it.

Important metrics include:

Retrieval Precision

Did the system retrieve relevant documents?

Retrieval Recall

Did it retrieve the information needed to answer the question?

Faithfulness

Does the generated answer actually follow the retrieved context?

Answer Relevance

Does the answer address the user's question?

Latency

How long does the complete request take?

Cost

How many embedding and LLM tokens are being consumed?


40. Common RAG Problems

Problem 1 — Bad Chunking

If chunks are too large:

Too much irrelevant context

If chunks are too small:

Important context may be lost

Problem 2 — Poor Retrieval

If the retriever returns irrelevant documents:

Wrong Context
     ↓
LLM
     ↓
Poor Answer

Problem 3 — Hallucination

Even with RAG, an LLM may generate information not supported by the context.

Therefore prompts should clearly instruct the model:

Use the provided context.

If the answer cannot be found in
the context, say that the information
is not available.

Problem 4 — Too Much Context

Sending hundreds of irrelevant chunks to the LLM can:

Increase cost
Increase latency
Reduce answer quality

Therefore retrieval and reranking are important.


41. Advanced RAG

Basic RAG:

Question
   ↓
Vector Search
   ↓
LLM

Advanced RAG can look like:

User Question
      |
      v
Query Rewriting
      |
      v
Hybrid Retrieval
      |
      v
Metadata Filtering
      |
      v
Reranking
      |
      v
Context Compression
      |
      v
LLM
      |
      v
Citation / Validation
      |
      v
Answer

42. Agentic RAG

A newer approach is Agentic RAG.

Instead of performing one retrieval operation, an AI agent can determine what information it needs and use multiple tools.

For example:

User:
"Why was customer 10025's order delayed?"

The agent may decide to query:

Customer API
       +
Order Database
       +
Support Tickets
       +
Product Documentation

Then combine the results.

A modern Agentic RAG system may therefore contain:

              AI Agent
                  |
        +---------+---------+
        |         |         |
        v         v         v
      SQL       Search      API
        |         |         |
        +---------+---------+
                  |
                  v
                 LLM

Recent industry research is increasingly exploring agentic RAG architectures that use planning, routing and retrieval to improve grounded responses.


43. RAG vs Agentic RAG

FeatureBasic RAGAgentic RAG
RetrievalUsually fixedDynamic
Decision makingLimitedAgent-driven
Multiple toolsLimitedYes
SQL/API integrationPossibleStrong
Query planningLimitedYes
ComplexityLowerHigher
CostLowerPotentially higher
Enterprise workflowsGoodExcellent for complex workflows

44. RAG Security Architecture

For enterprise applications:

                    User
                     |
                     v
              Authentication
                     |
                     v
              Authorization
                     |
                     v
               RAG API
                     |
              Security Filter
                     |
                     v
               Retrieval
                     |
                     v
                   LLM
                     |
                     v
             Output Validation
                     |
                     v
                  User

Important controls include:

Authentication
Authorization
Tenant isolation
Document-level permissions
Metadata filtering
Encryption
Audit logging
PII protection
Prompt-injection defenses
Output validation

45. Multi-Tenant RAG

Consider a SaaS application with:

Company A
Company B
Company C

The system must prevent:

Company A → Company B documents

A common approach is to include:

TenantId

in document metadata.

Example:

{
  "tenantId": "COMPANY-A",
  "documentId": "DOC-1001"
}

At query time:

WHERE TenantId = CurrentUser.TenantId

This is critical for enterprise SaaS systems.


46. RAG Cost Optimization

RAG does not automatically mean low cost.

Costs may come from:

Embedding generation
Vector search
LLM input tokens
LLM output tokens
Storage
Document processing
OCR
Reranking

Optimization techniques include:

1. Good chunking

Avoid unnecessary context.

2. Top-K optimization

Don't retrieve 100 chunks when 5 are enough.

3. Reranking

Retrieve candidates first, then select the best ones.

4. Cache embeddings

Don't regenerate embeddings unnecessarily.

5. Cache frequent questions

For repeated queries, response caching may help.


47. RAG Complete Architecture for an Enterprise .NET Application

A production architecture could look like:

                         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

Document ingestion:

User/Admin
    |
    v
Blob Storage
    |
    v
Service Bus
    |
    v
Document Processor
    |
    v
Text Extraction
    |
    v
Chunking
    |
    v
Embedding
    |
    v
Search Index

48. Recommended Technology Stack for a .NET Developer

For an enterprise .NET developer, one possible stack is:

LayerTechnology
FrontendAngular
BackendASP.NET Core
AuthenticationMicrosoft Entra ID / OAuth/OIDC
LLMAzure OpenAI or another LLM provider
SearchAzure AI Search
Document StorageAzure Blob Storage
DatabaseAzure SQL
MessagingAzure Service Bus
MonitoringApplication Insights / Azure Monitor
SecretsAzure Key Vault
API GatewayAzure API Management
ContainerizationDocker
OrchestrationAKS
CI/CDAzure DevOps
EmbeddingsEmbedding model
Vector StoreAzure AI Search / another vector-capable store

This is particularly suitable for organizations already invested in Microsoft technologies.


49. RAG Request Flow

Let's follow one request from beginning to end.

User asks:

"What is our refund policy?"

Step 1

Angular sends:

POST /api/rag/ask

Step 2

ASP.NET Core authenticates the user.

Step 3

RAG service creates an embedding.

Step 4

Search system performs semantic/hybrid search.

Step 5

Relevant documents are retrieved.

RefundPolicy.pdf
Section 4
Section 7

Step 6

Reranker selects the best chunks.

Step 7

Application constructs the prompt.

Step 8

LLM generates the answer.

Step 9

Application returns:

{
  "answer": "Customers can request a refund within...",
  "sources": [
    {
      "document": "RefundPolicy.pdf",
      "section": "4"
    }
  ]
}

Step 10

Angular displays the answer and sources.


50. Is RAG a Replacement for an LLM?

No.

RAG normally works with an LLM.

Think of the responsibilities like this:

Vector Search
     |
     | Finds information
     v
Relevant Context
     |
     | Gives context
     v
LLM
     |
     | Understands and generates
     v
Human-readable Answer

The vector database does not replace the LLM.

The LLM does not replace the search engine.

They work together.


51. Is RAG the Same as ChatGPT?

No.

ChatGPT is an AI application/service that can use LLMs and various tools.

RAG is an architectural pattern.

A developer can build:

Custom RAG Application

using:

ASP.NET Core
+
Vector Database
+
Embedding Model
+
LLM

52. When Should You Use RAG?

RAG is a strong choice when:

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

Examples:

HR Assistant
Customer Support Assistant
Legal Document Search
Technical Documentation Assistant
Product Assistant
Knowledge Management
Research Assistant
Enterprise Search

53. When RAG May Not Be the Best Solution

Don't automatically use RAG for everything.

For example:

"Calculate 125 × 75."

You don't need document retrieval.

Similarly:

"Sort this list."

RAG isn't necessary.

For structured business data:

SQL
API
Business Service

may be more appropriate.

The best enterprise architecture often combines:

LLM
+
RAG
+
SQL
+
APIs
+
Business Services
+
Tools

54. RAG vs Search Engine

Traditional search:

Question
   |
   v
Search Engine
   |
   v
10 Results

RAG:

Question
   |
   v
Search
   |
   v
Relevant Documents
   |
   v
LLM
   |
   v
Natural Language Answer

Traditional search gives you documents.

RAG can understand the retrieved information and synthesize an answer.


55. RAG vs Database

A database is designed primarily for structured data.

For example:

CustomerId
Name
OrderId
OrderDate
Amount

RAG is especially useful for unstructured/semi-structured knowledge such as:

PDFs
Manuals
Policies
Documentation
Emails
Knowledge articles
Text

Enterprise systems often use both.


56. Golden Rule for RAG

A very useful way to remember RAG is:

LLM = Brain

Embedding Model = Meaning Representation

Vector Database = Memory/Search

Retriever = Finds Memory

Prompt = Instructions

RAG = Brain + External Memory

This is only an analogy, but it makes the architecture easier to understand.


57. The Future of RAG

RAG is evolving beyond simple:

Search → Prompt → LLM

Modern systems increasingly explore:

Query Planning
+
Hybrid Search
+
Reranking
+
Knowledge Graphs
+
Multimodal Retrieval
+
Agentic Workflows
+
Tool Calling
+
SQL
+
APIs
+
Validation

Research is also exploring techniques for improving RAG efficiency and answer quality, including systems that use multiple retrieved document subsets and verification stages.


58. Complete RAG Mental Model

Remember this architecture:

                 ┌─────────────────┐
                 │      USER       │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │     QUESTION    │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │ QUERY PROCESSOR │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │   EMBEDDING     │
                 └────────┬────────┘
                          |
                          v
              ┌───────────────────────┐
              │ VECTOR / HYBRID SEARCH│
              └───────────┬───────────┘
                          |
                          v
                 ┌─────────────────┐
                 │    RERANKER     │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │ RELEVANT CONTEXT│
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │       LLM       │
                 └────────┬────────┘
                          |
                          v
                 ┌─────────────────┐
                 │ ANSWER + SOURCE │
                 └─────────────────┘

59. Key Takeaways

The most important points are:

  1. RAG stands for Retrieval-Augmented Generation.

  2. RAG is an architecture/pattern, not a programming language.

  3. The well-known RAG architecture was introduced in a 2020 research paper by Patrick Lewis and collaborators.

  4. RAG combines:

    Retrieval + LLM Generation
    
  5. Embeddings convert text into vectors representing semantic meaning.

  6. Vector databases/search engines allow semantic retrieval.

  7. Documents should normally be split into chunks.

  8. Metadata is extremely important for filtering and security.

  9. RAG can use:

    PDFs
    DOCX
    Websites
    Databases
    APIs
    Knowledge Bases
    
  10. RAG can reduce hallucination but cannot guarantee that every answer is correct.

  11. Fine-tuning and RAG solve different problems.

  12. RAG is highly useful for enterprise applications.

  13. .NET developers can build RAG applications using:

Angular
+
ASP.NET Core
+
Embedding Model
+
Vector Search
+
LLM
+
SQL
+
Azure Services
  1. Advanced RAG can include:

Hybrid Search
Reranking
Metadata Filtering
Query Rewriting
Context Compression
Agentic Workflows
SQL
APIs
Knowledge Graphs

60. Final Conclusion

RAG is one of the most important architectural patterns for building practical enterprise generative-AI applications.

An LLM provides the reasoning and language-generation capability, while RAG provides a mechanism for accessing external knowledge.

The basic concept is simple:

             Traditional LLM

Question ──────────> LLM ──────────> Answer


             RAG Application

Question
   |
   v
Retrieve Knowledge
   |
   v
Relevant Context
   |
   v
LLM
   |
   v
Grounded Answer

The real power appears when RAG is combined with enterprise technologies:

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

This combination allows developers to build practical systems such as:

Enterprise Knowledge Assistant
Customer Support AI
HR Assistant
Technical Documentation Assistant
Product Assistant
Financial Document Assistant
Legal Document Search
Developer Copilot
Enterprise Search

The key idea to remember is:

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.

That makes RAG one of the most useful bridges between traditional enterprise data and modern Generative AI.

References

The original RAG research paper is available on arXiv: Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks.

Google's research on REALM provides useful background on retrieval-augmented language modeling and explicit external knowledge retrieval.

Sunday, August 16, 2026

Complete CI/CD Pipeline for .NET 9 Microservices on Azure Using Azure DevOps, Docker, ACR and AKS

 


Complete CI/CD Pipeline for .NET 9 Microservices on Azure Using Azure DevOps, Docker, ACR and AKS

Introduction

Modern enterprise applications require a reliable and automated process for building, testing, packaging, and deploying applications across multiple environments.

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.

This is where CI/CD — Continuous Integration and Continuous Delivery/Deployment — becomes extremely important.

In this article, we will build a complete CI/CD pipeline for the following enterprise architecture:

  • Angular Web Application

  • .NET 9 Web API / Microservices

  • Docker

  • Azure Container Registry (ACR)

  • Azure Kubernetes Service (AKS)

  • Azure SQL Database

  • Azure Service Bus

  • Azure Key Vault

  • Azure DevOps

  • Kubernetes Ingress

  • DEV, QA, UAT and PRODUCTION environments

We will specifically use the Azure DevOps Classic/Visual UI approach, so you can understand how to configure the pipeline directly through the Azure DevOps portal without initially writing an azure-pipelines.yml file.

Note: 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.


1. What Are We Going to Build?

The overall CI/CD architecture will look like this:

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

The basic principle is:

Code → Build → Test → Docker Image → ACR → Deploy → AKS


2. Prerequisites

Before creating the pipeline, we need several Azure and Azure DevOps resources.

Azure Resources

You should have:

  • Azure Subscription

  • Resource Group

  • Azure Container Registry

  • Azure Kubernetes Service

  • Azure SQL Database

  • Azure Service Bus

  • Azure Key Vault

  • Azure Monitor / Application Insights

Azure DevOps

You should have:

  • Azure DevOps Organization

  • Azure DevOps Project

  • Azure Repos

  • Pipeline permissions

  • Microsoft-hosted agent capability

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.


3. Example Enterprise Application

Let's assume our solution has the following structure:

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

For our first example, we will deploy:

OrderService

Once the process is understood, the same approach can be applied to:

  • CustomerService

  • ProductService

  • InventoryService

  • PaymentService

  • NotificationService

  • Other microservices


4. Step 1 — Create an Azure DevOps Project

Open your Azure DevOps organization and create a project.

For example:

Organization
    |
    └── EnterpriseProject

Inside the project, Azure DevOps provides services such as:

Boards
Repos
Pipelines
Test Plans
Artifacts

For our CI/CD implementation, the most important areas are:

Repos
Pipelines
Project Settings

5. Step 2 — Add Source Code to Azure Repos

Navigate to:

Repos
    |
    └── Files

Create or import your Git repository.

For example:

EnterpriseApp

The repository might contain:

EnterpriseApp.sln

src/
    CustomerService/
    OrderService/
    ProductService/

tests/
    OrderService.Tests/

Dockerfile

k8s/

Developers can then work with the repository using Git:

git clone <repository>

After making changes:

git add .
git commit -m "Update order validation"
git push

This Git push can eventually trigger the CI pipeline automatically.


6. Step 3 — Create Azure Container Registry

The Azure Container Registry (ACR) stores the Docker images generated by the CI pipeline.

In the Azure Portal:

Create a resource
        ↓
Container Registry

For example:

Registry Name:
enterpriseacr

The registry endpoint could be:

enterpriseacr.azurecr.io

Our Docker image can then be tagged as:

enterpriseacr.azurecr.io/order-service:1.0

or, preferably, with a unique build number:

enterpriseacr.azurecr.io/order-service:1234

Using a unique build identifier makes it easier to identify exactly which source version produced a container image.


7. Step 4 — Create Azure Kubernetes Service

Create an AKS cluster from the Azure Portal or Azure CLI.

For example:

EnterpriseAKS

An AKS cluster contains:

AKS Cluster
    |
    ├── Node Pools
    |
    ├── Kubernetes Control Plane
    |
    └── Workloads

After connecting your local environment to the cluster, you can verify the nodes:

kubectl get nodes

8. Step 5 — Connect ACR with AKS

AKS needs permission to pull Docker images from Azure Container Registry.

A common Azure CLI approach is:

az aks update \
  --resource-group EnterpriseRG \
  --name EnterpriseAKS \
  --attach-acr enterpriseacr

The relationship becomes:

Azure Container Registry
          |
          | Pull Docker Image
          v
         AKS

This is important because the CI pipeline pushes the image into ACR, while AKS pulls that image when deploying the application.


9. Step 6 — Create Azure DevOps Service Connection

Azure DevOps needs permission to access Azure resources.

Navigate to:

Azure DevOps
    ↓
Project Settings
    ↓
Service connections
    ↓
New service connection

Select:

Azure Resource Manager

Configure the connection according to your organization's authentication and security requirements.

For example:

Service Connection Name:

Azure-Enterprise-Connection

Conceptually:

Azure DevOps
       |
       | Service Connection
       v
Azure Subscription
       |
       +---- ACR
       +---- AKS
       +---- Other Azure Resources

Service connections are a critical security boundary, so they should be granted only the permissions required by the pipeline.


10. Step 7 — Create the CI Build Pipeline

Now we can create the Continuous Integration pipeline.

Navigate to:

Pipelines
    ↓
Builds

Depending on your Azure DevOps UI, select the option to create a new pipeline and choose the Classic editor.

The Classic editor allows you to configure the build process using the Azure DevOps UI rather than writing YAML.

Select:

Azure Repos Git

Then select:

Project:
EnterpriseProject

Repository:
EnterpriseApp

Branch:
main

Click:

Continue

11. Step 8 — Select Empty Job

Instead of allowing Azure DevOps to automatically create all the tasks, select:

Empty Job

You should now see something similar to:

Agent Job 1

This approach is useful when learning CI/CD because you can understand each pipeline task individually.


12. Step 9 — Configure the Build Agent

Select:

Agent Job 1

Choose an agent specification.

For example:

ubuntu-latest

or:

windows-latest

For Docker and Linux-based containers, Ubuntu is commonly convenient.

Our pipeline now starts with:

Agent Job
     |
     v
Use .NET SDK

13. Step 10 — Install / Select .NET SDK

Add a task:

+

Search for the .NET SDK task.

Configure the required .NET version.

For example:

SDK Version:

9.x

This ensures that the build agent uses the expected .NET SDK version.


14. Step 11 — Restore NuGet Packages

Add a .NET Core task.

Configure:

Command:

restore

For example:

Path to project:

EnterpriseApp.sln

The pipeline becomes:

Use .NET SDK
      |
      v
Restore

This downloads the NuGet dependencies required by the solution.


15. Step 12 — Build the Application

Add another .NET task.

Configure:

Command:

build

Project:

EnterpriseApp.sln

Arguments:

--configuration Release --no-restore

The pipeline is now:

Use .NET SDK
      |
      v
Restore
      |
      v
Build

The equivalent .NET CLI operation is:

dotnet build EnterpriseApp.sln \
    --configuration Release \
    --no-restore

16. Step 13 — Execute Unit Tests

Add another .NET task.

Configure:

Command:

test

Project:

tests/**/*.csproj

Arguments:

--configuration Release --no-build

The pipeline becomes:

Restore
   |
   v
Build
   |
   v
Unit Tests

If the unit tests fail:

Build ❌

the pipeline should stop.

This is an important CI principle:

Code should not progress toward deployment if automated tests are failing.


17. Step 14 — Publish the .NET Application

Add another .NET task.

Configure:

Command:

publish

Project:

src/OrderService/OrderService.csproj

Configuration:

Release

Output:

$(Build.ArtifactStagingDirectory)/order-service

The flow becomes:

Build
  |
  v
Test
  |
  v
Publish
  |
  v
Build Artifact

18. Step 15 — Build the Docker Image

Now we move from application build to containerization.

Add a Docker task.

Select:

Docker

Command:

Build

Configure the Azure Container Registry connection.

Repository:

order-service

Dockerfile:

$(Build.SourcesDirectory)/src/OrderService/Dockerfile

Tag:

$(Build.BuildId)

The resulting image could be:

enterpriseacr.azurecr.io/order-service:1234

19. Step 16 — Push Docker Image to ACR

Add another Docker task.

Select:

Docker

Command:

Push

Repository:

order-service

Tag:

$(Build.BuildId)

The CI process is now:

Git Push
    |
    v
Restore
    |
    v
Build
    |
    v
Unit Test
    |
    v
Publish
    |
    v
Docker Build
    |
    v
Docker Push
    |
    v
Azure Container Registry

This is the core Continuous Integration workflow.


20. Step 17 — Save and Run the CI Pipeline

Save the pipeline with a name such as:

CI-OrderService

Then select:

Save & Queue

Run the pipeline.

You should see tasks such as:

✔ Restore
✔ Build
✔ Unit Test
✔ Publish
✔ Docker Build
✔ Docker Push

If everything succeeds:

BUILD SUCCESSFUL

21. Step 18 — Verify the Docker Image in ACR

Open:

Azure Portal
    ↓
Container Registry
    ↓
Repositories

You should see:

order-service

Inside the repository:

order-service
    |
    └── 1234

The tag 1234 represents the pipeline build number.


22. Step 19 — Create the CD / Release Pipeline

The next step is Continuous Delivery/Deployment.

In the Classic pipeline model, the release pipeline is separate from the build pipeline.

Navigate to:

Pipelines
    ↓
Releases
    ↓
New pipeline

Select:

Empty Job

Rename the first stage:

DEV

A typical enterprise release pipeline can contain:

DEV
  |
  v
QA
  |
  v
UAT
  |
  v
PRODUCTION

23. Step 20 — Configure the Release Artifact

Add the output from the CI/build process as the release artifact.

For containerized applications, the key deployment input is the Docker image and its version/tag stored in ACR.

Conceptually:

CI Pipeline
     |
     v
Docker Image
     |
     v
ACR
     |
     v
Release Pipeline
     |
     v
AKS

24. Step 21 — Configure DEV Deployment

Open the DEV stage.

Add a Kubernetes deployment task.

Configure the Azure connection:

Connection Type:

Azure Resource Manager

Select:

Azure Subscription:

Azure-Enterprise-Connection

Then select the AKS cluster:

EnterpriseAKS

Use a namespace such as:

dev

This allows the same AKS cluster to host workloads for multiple environments when that is appropriate for the organization's architecture.


25. Kubernetes Deployment

A simplified Kubernetes Deployment might look like:

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

The important part is:

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

When a new version is released, the image tag changes.

For example:

Old:

order-service:1233

becomes:

New:

order-service:1234

Kubernetes then performs a rollout to replace the old application version with the new one.


26. DEV Deployment Flow

The deployment now looks like:

ACR
 |
 | order-service:1234
 v
AKS
 |
 v
DEV Namespace
 |
 +---- Pod 1
 |
 +---- Pod 2
 |
 +---- Pod 3

Running multiple replicas provides application redundancy and enables Kubernetes to distribute traffic across available Pods.


27. Step 22 — Create QA Stage

Add another stage:

QA

Configure the deployment to target:

QA

and use the appropriate Kubernetes namespace:

qa

The pipeline becomes:

DEV
 |
 v
QA

Configure the QA stage to execute after successful DEV deployment.


28. Step 23 — Create UAT Stage

Create another stage:

UAT

The release flow becomes:

DEV
 |
 v
QA
 |
 v
UAT

UAT is generally used for business/user acceptance validation before production.


29. Step 24 — Create Production Stage

Create the final stage:

PRODUCTION

The complete release flow is now:

DEV
 |
 v
QA
 |
 v
UAT
 |
 v
PRODUCTION

30. Step 25 — Add Production Approval

Production deployments should normally have appropriate controls.

Instead of allowing:

Developer
   |
   v
DEV
   |
   v
QA
   |
   v
UAT
   |
   v
PRODUCTION

without any control, introduce an approval gate:

DEV
 |
 v
QA
 |
 v
UAT
 |
 v
+----------------------+
| Production Approval  |
|                      |
| Lead / Manager       |
+----------+-----------+
           |
           v
      PRODUCTION

In the Classic Release pipeline, configure:

PRODUCTION
    ↓
Pre-deployment conditions
    ↓
Pre-deployment approvals

Add the authorized reviewers according to your organization's release-management process.


31. Complete CI/CD Architecture

The complete architecture now looks like this:

                         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

32. Where Does Ingress Fit?

Ingress is part of the Kubernetes application architecture. It is not a replacement for Azure DevOps.

A typical AKS architecture can look like:

                         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

The important distinction is:

Azure DevOps automates application delivery.

Kubernetes/AKS runs the application.

Ingress/Gateway manages incoming application traffic.


33. Where Do Azure SQL and Azure Service Bus Fit?

Azure SQL and Azure Service Bus are generally infrastructure dependencies rather than resources that should be recreated every time the application pipeline runs.

A typical environment contains:

Azure Infrastructure
    |
    +── AKS
    |
    +── ACR
    |
    +── Azure SQL
    |
    +── Azure Service Bus
    |
    +── Key Vault
    |
    +── Monitoring

The CI/CD pipeline then deploys the application:

CI/CD
   |
   v
AKS

The application can communicate with:

Order API
    |
    +---- Azure SQL
    |
    +---- Azure Service Bus

34. Managing Secrets

Sensitive information should never be hardcoded into:

  • Source code

  • Dockerfiles

  • Kubernetes manifests

  • Pipeline scripts

  • Git repositories

Examples include:

SQL connection strings
Service Bus credentials
JWT secrets
API keys
Third-party credentials

A recommended architecture is:

                    Azure Key Vault
                          |
                          |
                    Managed Identity
                          |
                          v
                         AKS
                          |
                          v
                    Microservices

Azure DevOps variable/secret mechanisms can also be used where appropriate, but secrets should be managed according to your organization's security architecture.


35. What Happens When a Developer Commits Code?

Suppose a developer changes the OrderService validation logic.

The developer executes:

git add .

Then:

git commit -m "Update order validation"

Then:

git push origin main

The automated process becomes:

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

This is the essence of CI/CD.


36. Continuous Integration vs Continuous Delivery

Understanding the difference between CI and CD is important.

Continuous Integration

Continuous Integration focuses on validating the application whenever code changes.

Code
 |
 v
Restore
 |
 v
Build
 |
 v
Test
 |
 v
Package
 |
 v
Docker Image
 |
 v
ACR

The primary question is:

"Is my code buildable, testable and packageable?"


Continuous Delivery / Deployment

Continuous Delivery/Deployment focuses on moving the validated application version through environments.

ACR
 |
 v
DEV
 |
 v
QA
 |
 v
UAT
 |
 v
Approval
 |
 v
PRODUCTION

The primary question is:

"Can this version be safely deployed to the required environments?"

Therefore:

CI = Build, test and package the application

CD = Deliver/deploy the application through environments


37. Classic Pipeline vs YAML Pipeline

The Classic UI is an excellent way to learn Azure DevOps because you can visually see:

Agent
Tasks
Stages
Artifacts
Approvals
Deployment

However, for modern enterprise projects, YAML pipelines are often preferred because the pipeline definition can be stored alongside the source code.

A modern architecture can look like:

Azure DevOps
      |
      v
YAML Pipeline
      |
      +---- CI
      |
      +---- Build
      |
      +---- Unit Tests
      |
      +---- Docker
      |
      +---- Security
      |
      +---- ACR
      |
      +---- CD
             |
             +---- DEV
             |
             +---- QA
             |
             +---- UAT
             |
             +---- PROD

The key advantage is Pipeline as Code.

The pipeline itself becomes version-controlled, reviewable, and reproducible.


38. Recommended Enterprise Improvements

The basic pipeline described above can be extended significantly for production environments.

Security

Add:

  • Azure Key Vault

  • Managed Identity

  • Microsoft Entra ID

  • Container image scanning

  • Dependency scanning

  • Secret scanning

  • Least-privilege service connections

Quality

Add:

  • Unit tests

  • Integration tests

  • Code coverage

  • SonarQube/SonarCloud

  • API testing

  • Performance testing

Deployment

Add:

  • Rolling deployments

  • Health probes

  • Readiness probes

  • Liveness probes

  • Deployment strategies

  • Automatic rollback

  • Environment approvals

Observability

Add:

  • Application Insights

  • Azure Monitor

  • Log Analytics

  • Kubernetes monitoring

  • Alerts

  • Dashboards


39. Production-Ready Microservices Flow

A mature enterprise architecture could eventually look like:

                         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

40. Important Takeaways

The complete deployment journey can be remembered as:

Developer
   ↓
Git
   ↓
Azure DevOps
   ↓
CI
   ↓
Build
   ↓
Test
   ↓
Docker
   ↓
ACR
   ↓
CD
   ↓
DEV
   ↓
QA
   ↓
UAT
   ↓
Approval
   ↓
PRODUCTION
   ↓
AKS

The responsibilities of the major components are:

ComponentResponsibility
Azure ReposSource-code management
Azure DevOpsCI/CD automation
DockerApplication containerization
ACRDocker image storage
AKSContainer orchestration
KubernetesApplication workload management
Ingress/GatewayIncoming traffic routing
Azure SQLRelational database
Azure Service BusAsynchronous messaging
Key VaultSecret management
Application InsightsApplication telemetry
Azure MonitorMonitoring and alerting

41. Final Conclusion

Implementing CI/CD for a .NET microservices application on Azure provides a repeatable and controlled way to move software from development to production.

The complete lifecycle is:

Code
  ↓
Commit
  ↓
Build
  ↓
Unit Test
  ↓
Docker Image
  ↓
Azure Container Registry
  ↓
AKS Deployment
  ↓
DEV
  ↓
QA
  ↓
UAT
  ↓
Production Approval
  ↓
PRODUCTION

For learning Azure DevOps, the Classic UI pipeline is a very useful starting point because every stage and task is visible through the portal.

For a new enterprise implementation, however, it is worth moving toward YAML-based pipelines, infrastructure as code, automated security scanning, managed identities, automated testing, deployment strategies, and comprehensive monitoring.

The ultimate goal is not simply to automate deployment.

The goal is to create a secure, repeatable, observable, and reliable software delivery process.


Quick Reference

CI

Git
 ↓
Restore
 ↓
Build
 ↓
Test
 ↓
Publish
 ↓
Docker Build
 ↓
Docker Push
 ↓
ACR

CD

ACR
 ↓
DEV
 ↓
QA
 ↓
UAT
 ↓
Approval
 ↓
PRODUCTION
 ↓
AKS

Application Architecture

Internet
   ↓
Ingress / Gateway
   ↓
Microservices
   ↓
Azure SQL
   +
Azure Service Bus
   +
Key Vault
   +
Application Insights

This architecture provides a strong foundation for deploying modern .NET 9 microservices applications on Azure using Azure DevOps, Docker, ACR and AKS.

Don't Copy

Protected by Copyscape Online Plagiarism Checker