Showing posts with label azure app service. Show all posts
Showing posts with label azure app service. Show all posts

Saturday, August 1, 2026

Azure App Service

 

Azure App Service – Complete Guide for .NET Lead

Official Documentation

Azure App Service Documentation


1. What is Azure App Service?

Azure App Service is a fully managed Platform as a Service (PaaS) that allows developers to deploy and host web applications, REST APIs, and mobile backends without managing servers or operating systems.

Instead of worrying about:

  • Installing Windows/Linux

  • IIS Configuration

  • OS Updates

  • Security Patches

  • Load Balancers

  • Scaling Infrastructure

You simply deploy your application, and Azure manages the infrastructure.


2. Traditional Hosting vs Azure App Service

Traditional Hosting

                 User
                   |
             Internet
                   |
           Load Balancer
                   |
            Windows Server
                   |
                  IIS
                   |
             ASP.NET Core API
                   |
              SQL Server

You manage:

  • Server

  • IIS

  • Windows Updates

  • Firewall

  • Certificates

  • Scaling

  • Backup

  • Monitoring


Azure App Service

                 User
                   |
              Internet
                   |
          Azure App Service
                   |
            ASP.NET Core API
                   |
             Azure SQL Database

Azure manages:

  • Infrastructure

  • Operating System

  • IIS/Web Server

  • Security Patching

  • Load Balancing

  • Auto Scaling

  • Health Monitoring

You only manage your application.


3. Why Companies Use Azure App Service

Imagine an e-commerce company.

Components:

Angular Frontend

ASP.NET Core API

Azure SQL

Azure Service Bus

Azure Functions

Application Insights

The API is deployed to Azure App Service.

Architecture:

                 Users
                    |
            Azure Front Door
                    |
           Azure API Management
                    |
            Azure App Service
                    |
      +-------------+-------------+
      |                           |
Azure SQL                 Azure Service Bus
      |                           |
      |                    Azure Functions
      |
Application Insights

4. What Applications Can Be Hosted?

Azure App Service supports:

  • ASP.NET Core

  • .NET Framework

  • Node.js

  • Java

  • Python

  • PHP

  • Static Web Apps

Example:

Company Portal

HR Management

Banking API

Hospital Management

Insurance Portal

E-Commerce API

5. Real-Time Banking Example

Suppose ABC Bank has:

  • Mobile App

  • Internet Banking

  • ATM Services

Customer logs in.

Mobile App
     |
     v
Azure App Service
     |
Authentication
     |
Azure SQL

Thousands of users connect simultaneously.

Azure App Service automatically distributes incoming requests across available instances when scaled out.


6. App Service Architecture

                Users
                   |
              Internet
                   |
          Azure Load Balancer
                   |
          Azure App Service
          +--------+--------+
          |                 |
      Instance 1       Instance 2
          |                 |
          +--------+--------+
                   |
            Azure SQL Database

7. Important Features

Azure App Service provides:

  • Auto Scaling

  • Load Balancing

  • HTTPS

  • SSL Certificates

  • Custom Domains

  • Deployment Slots

  • Backup

  • Authentication

  • Logging

  • Monitoring

  • Managed Identity

  • VNet Integration


8. App Service Plan

One of the most common interview questions.

Many beginners think:

App Service = Server

That's incorrect.

The App Service runs inside an App Service Plan.

App Service Plan
       |
       +------ CPU
       |
       +------ Memory
       |
       +------ Region
       |
       +------ Pricing Tier

Think of it like renting an apartment.

The apartment is the App Service Plan.

Your application lives inside the apartment.


9. Multiple Apps in One Plan

             App Service Plan
          (4 CPU, 16 GB RAM)

          |        |        |

     HR API   Order API   Payment API

All applications share the resources of the App Service Plan.


10. Pricing Tiers

Common tiers include:

Free

Shared

Basic

Standard

Premium

Isolated

Interview point:

  • Development → Free/Basic

  • Production → Standard/Premium (depending on workload and requirements)


11. Deploying an ASP.NET Core API

Create the API:

dotnet new webapi

Run:

dotnet run

Publish:

dotnet publish -c Release

Deploy through:

  • Azure DevOps

  • GitHub Actions

  • Visual Studio

  • Azure CLI

  • ZIP Deployment


12. Example ASP.NET Core API

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

var app = builder.Build();

app.MapControllers();

app.Run();

Controller:

[ApiController]
[Route("api/products")]
public class ProductsController : ControllerBase
{
    [HttpGet]
    public IActionResult Get()
    {
        return Ok(new[]
        {
            "Laptop",
            "Mouse",
            "Keyboard"
        });
    }
}

Once deployed:

https://companyapi.azurewebsites.net/api/products

13. Deployment Flow

Developer
     |
Git Push
     |
Azure DevOps
     |
Build
     |
Publish
     |
Deploy
     |
Azure App Service

14. Configuration

Never store secrets directly in code.

Bad:

string connection =
"Server=...;User=sa;Password=123";

Instead use configuration:

{
  "ConnectionStrings": {
    "DefaultConnection": ""
  }
}

Then override values in App Service Application Settings or use Azure Key Vault for secrets.


15. Environment Variables

Azure App Service allows configuration such as:

Connection String

API URL

Storage Account

Service Bus

Application Insights

No code changes are required to switch environments when configuration is externalized.


16. Auto Scaling

Suppose your API receives:

Morning:

500 Users

Afternoon:

5,000 Users

Night:

30,000 Users

Instead of buying larger servers, Azure can scale based on configured rules.

Users
   |
App Service
   |
+----------+
| Instance |
+----------+

↓

High CPU

↓

+----------+
|Instance 1|
|Instance 2|
|Instance 3|
+----------+

17. Scale Up vs Scale Out

Scale Up (Vertical)

Increase resources of a single instance.

2 CPU

↓

8 CPU

Scale Out (Horizontal)

Increase the number of instances.

Instance 1

↓

Instance 1
Instance 2
Instance 3

Interview Question:

Which is better?

Answer:

Scale out generally provides better availability and elasticity for stateless web applications, while scale up can help when an application requires more resources per instance.


18. Deployment Slots

One of the best App Service features.

Suppose Production is live.

Production

Version 1

You want to deploy Version 2.

Instead of deploying directly:

Production

↓

Version 2

Use slots.

Production Slot

Version 1

Staging Slot

Version 2

Test Version 2.

If successful:

Swap

↓

Production

Version 2

Users experience little or no downtime during the swap.


19. Slot Swap

Before

Production → V1

Staging → V2

↓

Swap

↓

Production → V2

Staging → V1

If a rollback is required, you can swap again (assuming compatibility and deployment strategy support it).


20. Managed Identity

Instead of storing passwords:

App

↓

SQL Password

Use Managed Identity.

App Service

↓

Managed Identity

↓

Azure SQL

↓

Access Granted

No database password is stored in your application.


21. Authentication

App Service supports integration with identity providers.

Examples:

  • Microsoft Entra ID (Azure AD)

  • Microsoft Accounts

  • Google

  • GitHub (supported scenarios)

  • Other OpenID Connect/OAuth providers

This can simplify authentication for many applications.


22. Custom Domain

Instead of:

company.azurewebsites.net

Use:

api.company.com

along with an SSL certificate.


23. Logging

You can use ASP.NET Core logging:

_logger.LogInformation("Order Created");

Application Insights captures logs, requests, exceptions, dependencies, and traces for analysis.


24. Health Check

Suppose one instance becomes unhealthy.

Azure App Service can remove unhealthy instances from rotation when health checks are configured.

Load Balancer

↓

Instance 1

Instance 2

Instance 3

↓

Instance 2 unhealthy

↓

Traffic goes to healthy instances

25. Real-Time Insurance Example

Customer submits:

Claim

↓

App Service

↓

Azure SQL

↓

Service Bus

↓

Notification Service

If traffic suddenly increases after a natural disaster:

Azure App Service can scale based on configured policies while Azure Monitor and Application Insights help you observe performance.


26. Security Best Practices

  • Use HTTPS only

  • Store secrets in Azure Key Vault

  • Use Managed Identity

  • Restrict network access where appropriate

  • Enable authentication/authorization

  • Keep dependencies updated

  • Monitor with Azure Monitor and Application Insights


27. Interview Questions

Basic

  1. What is Azure App Service?

  2. What is PaaS?

  3. Difference between App Service and Virtual Machine?

  4. What applications can App Service host?

  5. What is an App Service Plan?

  6. What is deployment?

  7. What is auto scaling?

  8. What is slot deployment?

  9. What is Managed Identity?

  10. What is a custom domain?

Intermediate

  1. Difference between Scale Up and Scale Out?

  2. Explain deployment slots.

  3. How does App Service communicate with Azure SQL?

  4. How do you secure secrets?

  5. How do you monitor App Service?

  6. How do you configure Application Settings?

  7. What is VNet Integration?

  8. How do you enable authentication?

  9. How does zero-downtime deployment work?

  10. What are App Service Plans?

Lead-Level

  1. Design a highly available App Service architecture.

  2. How would you deploy microservices?

  3. How would you secure production APIs?

  4. How would you implement CI/CD using Azure DevOps?

  5. How would you monitor production?

  6. How would you troubleshoot a slow App Service?

  7. How would you design disaster recovery?

  8. How would you integrate App Service with Service Bus and Azure Functions?

  9. When would you choose App Service over AKS?

  10. What production best practices would you follow?


28. Lead-Level Interview Answer

If an interviewer asks:

"Explain how you have used Azure App Service in your project."

A strong answer is:

"In our microservices-based .NET solution, we hosted ASP.NET Core Web APIs on Azure App Service. Azure DevOps pipelines automatically built and deployed the applications. Configuration values were managed through App Service settings and Azure Key Vault. Authentication was integrated with Microsoft Entra ID, and Managed Identity was used to securely access Azure SQL and other Azure resources without storing credentials in code. We used deployment slots for zero-downtime releases, auto-scale rules based on CPU and HTTP traffic, and monitored the application using Application Insights and Azure Monitor. The APIs also communicated asynchronously with Azure Service Bus to improve scalability and resilience."

This answer demonstrates not only knowledge of Azure App Service but also how it fits into a modern production architecture.

Saturday, October 18, 2025

🚀 Deployment Slots in CI/CD Pipelines — Complete Guide

 🌐 What Are Deployment Slots?

Deployment Slots are live environments within an Azure App Service (Web App) that let you deploy, test, and swap applications without downtime.

Think of them as separate versions of your app running under the same App Service Plan — for example:

  • Production Slot – your live application

  • Staging Slot – where new code is deployed and tested

  • Testing / QA Slot – for internal validation

💡 In short: Deployment slots allow safe, zero-downtime deployments by letting you deploy new versions to a staging environment first and then swap them into production.


🧩 Example Slot Setup

Slot NamePurposeURL Example
ProductionLive user traffichttps://myapp.azurewebsites.net
StagingTest new releases before going livehttps://myapp-staging.azurewebsites.net
QAInternal testinghttps://myapp-qa.azurewebsites.net

Each slot:

  • Has its own configuration (connection strings, app settings)

  • Runs under the same compute resources

  • Can be swapped instantly


⚙️ How Deployment Slots Work in CI/CD

In a CI/CD pipeline, deployment slots are used between the Build and Release stages.

Let’s visualize the flow:

🔁 Pipeline Flow Example

Developer Commit → Build Pipeline → Create Artifact → Deploy to Staging Slot → Validate Tests → Swap to Production Slot

🔹 Step-by-Step Explanation

  1. Build Stage

    • Your code is compiled and tested.

    • Output is packaged as an artifact.

  2. Release Stage

    • The artifact is deployed to the staging slot (not production yet).

    • Automated smoke tests or manual validations are performed.

  3. Slot Swap

    • Once validated, the staging slot is swapped with the production slot.

    • The swap is instantaneous, so users experience zero downtime.

  4. Rollback (if needed)

    • If something goes wrong, simply swap back — instant rollback.


🧱 Example: YAML CI/CD Pipeline Using Deployment Slots

trigger: - main stages: - stage: Build jobs: - job: BuildApp steps: - task: DotNetCoreCLI@2 inputs: command: 'publish' projects: '**/*.csproj' arguments: '--output $(Build.ArtifactStagingDirectory)' - publish: $(Build.ArtifactStagingDirectory) artifact: drop - stage: Deploy dependsOn: Build jobs: - deployment: DeployToStaging environment: 'staging' strategy: runOnce: deploy: steps: - download: current artifact: drop - task: AzureWebApp@1 inputs: azureSubscription: 'MyAzureConnection' appName: 'myapp-service' package: '$(Pipeline.Workspace)/drop/**/*.zip' slotName: 'staging' - deployment: SwapToProduction dependsOn: DeployToStaging steps: - task: AzureAppServiceManage@0 inputs: azureSubscription: 'MyAzureConnection' Action: 'Swap Slots' WebAppName: 'myapp-service' SourceSlot: 'staging' ResourceGroupName: 'MyResourceGroup'

✅ In this pipeline:

  • The Build stage publishes artifacts.

  • The Deploy stage deploys to staging.

  • The Swap step promotes the app to production after verification.


🧠 Key Benefits of Deployment Slots

BenefitDescription
Zero-Downtime DeploymentSwap instantly between slots with no downtime.
Safe TestingTest new versions in staging with production-like settings.
Instant RollbackSwap back to previous slot in seconds if issues occur.
Configuration IsolationDifferent connection strings or keys per slot.
Warm-Up Before ReleaseStaging slot can “preload” your app before swap.

🔍 Use Cases

  1. Blue-Green Deployments
    Deploy new code to blue (staging), swap with green (production) once validated.

  2. Canary Releases
    Gradually route small portions of traffic to the staging slot to monitor impact.

  3. Testing in Production Environment
    Test the latest build in a real environment before it goes live.

  4. Instant Rollback Scenarios
    When a new release fails, swap back to restore the previous version.


⚠️ Things to Keep in Mind

  • Slots share App Service Plan (CPU/RAM).

  • App settings marked as “Slot specific” won’t transfer on swap.

  • Swapping doesn’t move custom domain or SSL settings (they stay on production).

  • Limit: Free and Shared App Service Plans do not support slots.


🧰 Integration with Azure DevOps

In Azure DevOps, you can use:

  • Azure Web App Deploy Task to deploy to specific slots

  • Azure App Service Manage Task to perform swap operations

  • Environments for approvals before swapping to production

This allows controlled, automated deployments without affecting live traffic.


🏁 Summary Table

FeatureDescription
Deployment SlotSeparate environment within App Service
Common SlotsProduction, Staging, QA
Supported PlansStandard, Premium, Isolated
Swap OperationMoves staging → production instantly
CI/CD IntegrationAzure DevOps Pipelines, GitHub Actions, or CLI

💬 Final Thought

Deployment slots are one of the most effective DevOps strategies for achieving:

  • Zero downtime

  • Safe testing in production

  • Quick rollback in case of failure

🗣️ “If you’re deploying to Azure App Service, deployment slots are your safety net for continuous delivery.”

Don't Copy

Protected by Copyscape Online Plagiarism Checker