# PART 1: COMPUTE SERVICES

---

## 1.1 Azure Virtual Machines (VMs)

### Overview
Azure VMs provide on-demand, scalable compute resources. You choose the OS (Windows/Linux), size, and configuration. You manage everything above the hypervisor; Azure manages the physical hardware.

### VM Families
| Family | Use Case | Examples |
|---|---|---|
| **B-series** | Burstable, low-cost dev/test | B1s, B2s, B2ms |
| **D-series** | General purpose, balanced CPU/memory | D2s_v5, D4s_v5 |
| **E-series** | Memory-optimized | E2s_v5, E4s_v5 |
| **F-series** | Compute-optimized (high CPU) | F2s_v2, F4s_v2 |
| **N-series** | GPU-enabled (AI/ML, rendering) | NC6s_v3, ND40rs_v2 |
| **H-series** | High-performance computing (HPC) | HB120rs_v2 |
| **Ls-series** | Storage-optimized (NoSQL, data warehousing) | L8s_v3 |
| **M-series** | Memory-intensive (SAP HANA, large DBs) | M128s, M416ms_v2 |
| **NP-series** | FPGA workloads | NP10s |

### VM Sizing Naming Convention
Format: **[Family][vCPUs][Sub-family][Feature][Version]**

Example: `D4s_v5` = D-family, 4 vCPUs, s=Premium SSD support, v5=5th generation

### Storage Options for VMs
- **Premium SSD v2** — Configurable IOPS/throughput, cost-optimized
- **Premium SSD** — Production workloads, low latency
- **Standard SSD** — Web servers, light workloads
- **Standard HDD** — Backups, non-critical
- **Ultra Disk** — Sub-millisecond latency, configurable IOPS (SAP HANA, tier-1 DBs)

### Availability
- **Availability Sets** — Fault domains (FD) + Update domains (UD) within a datacenter. Min 2 FDs, up to 20 UDs. Protects against hardware failure and planned maintenance.
- **Availability Zones** — Physically separate datacenters within a region. 3 zones per region. VMs in different zones = 99.99% SLA.
- **Proximity Placement Groups** — Co-locate VMs for low latency

### Key Concepts
- **VMSS (VM Scale Sets)** — Auto-scaling groups of identical VMs. Supports autoscale rules, custom images.
- **Spot VMs** — Up to 90% discount. Can be evicted with 30s notice. Good for batch, dev/test, stateless workloads.
- **Reserved Instances** — 1-year or 3-year commitment. Up to 72% savings. Can be exchanged/cancelled.
- **Azure Dedicated Host** — Single-tenant physical server. For licensing (e.g., SQL Server BYOL) and compliance.

### Interview Q&A
**Q: When would you use Availability Set vs Availability Zone?**
A: Availability Sets protect within a single datacenter (FD/UD). Availability Zones spread across physical datacenters in a region. Zones give higher SLA (99.99% vs 99.95%) but cost more and not all regions support them. Use Zones for mission-critical workloads.

**Q: How do you optimize VM costs?**
A: Reserved Instances for predictable workloads, Spot VMs for fault-tolerant workloads, right-sizing via Azure Advisor, auto-shutdown for dev/test, use B-series for burstable workloads.

---

## 1.2 Azure App Service

### Overview
Fully managed PaaS for building and hosting web apps, mobile backends, REST APIs, and containerized workloads. Zero infrastructure management — focus on code.

### App Service Types
| Type | Purpose |
|---|---|
| **Web App** | Web applications (.NET, Node.js, Python, Java, PHP, Ruby) |
| **Web App for Containers** | Run custom Linux containers |
| **API App** | REST API hosting with Swagger support |
| **Mobile App** | Mobile backend with offline sync, auth |

### App Service Plans (Tiers)
| Tier | Use Case | Key Feature |
|---|---|---|
| **Free (F1)** | Dev/test | 60 min/day, shared infrastructure |
| **Shared (D1)** | Dev/test | Custom domain, no SSL |
| **Basic (B1-B3)** | Small production | Dedicated compute, SSL, auto-scale |
| **Standard (S1-S3)** | Production | Auto-scale, traffic manager, slots |
| **Premium (P1v3-P3v3)** | High-scale production | VNet integration, more memory |
| **Isolated (I1-I3)** | Enterprise/compliance | App Service Environment (ASE), max isolation |
| **Isolated v2 (I1v2-I6v2)** | Largest workloads | ASE v3, more cores |

### Key Features
- **Deployment Slots** — Staging environments. Swap slots for zero-downtime deployment. Up to 1 (Standard), 5 (Premium), unlimited (Isolated).
- **Auto-scaling** — Scale up (bigger tier) vs Scale out (more instances). Rules based on CPU, memory, queue length, schedule.
- **Custom Domains & SSL** — Bind custom domains, free managed certificates, bring your own SSL.
- **VNet Integration** — Connect App Service to your VNet for accessing on-prem/private resources. Regional VNet integration (outbound) + VNet-injected ASE (inbound+outbound).
- **Authentication** — Built-in auth with Entra ID, Google, Facebook, Twitter, Microsoft Account.
- **CI/CD** — Deploy from GitHub, Azure DevOps, Bitbucket, local Git.
- **Backups** — Scheduled backups to storage account (Standard+).
- **Private Endpoints** — Access App Service via private IP. Inbound private endpoint.

### App Service Environment (ASE)
- Runs in your own VNet (fully isolated)
- Single-tenant App Service
- For compliance (PCI, HIPAA), high scale, internal-only apps
- ASE v3 is simpler and cheaper than v2
- Internal ILB ASE = no public endpoint; External ASE = public endpoint

### Interview Q&A
**Q: What's the difference between Scale Up and Scale Out?**
A: Scale Up = increase compute resources (e.g., S1 → S3, more CPU/RAM). Scale Out = add more instances (e.g., 2 → 5 instances). Scale Up has downtime; Scale Out doesn't.

**Q: When to use App Service vs AKS?**
A: App Service for simple web apps/APIs with standard frameworks — faster to deploy, less management. AKS when you need microservices architecture, container orchestration, custom networking, or workloads that don't fit App Service constraints.

**Q: How do deployment slots work?**
A: Create a staging slot, deploy new version there, test it, then swap with production. Swap is near-instant. You can also route % traffic (canary). Rollback by swapping back.

---

## 1.3 Azure Kubernetes Service (AKS)

### Overview
Managed Kubernetes. Azure manages the control plane (free). You manage the agent nodes (pay for VMs).

### Key Features
- **Cluster Autoscaler** — Automatically adds/removes nodes based on pod scheduling needs.
- **KEDA** — Scale pods based on external events (queue length, etc.).
- **Virtual Nodes** — Serverless burst using ACI.
- **Azure CNI** — Each pod gets an IP from VNet.
- **Kubenet** — Pods use NAT. Simpler but less network control.
- **Private Cluster** — API server has no public IP.
- **Entra ID Integration** — Use Entra ID for K8s RBAC.
- **Azure Policy for AKS** — Enforce policies on K8s resources.
- **Secret Store CSI Driver** — Mount Key Vault secrets as volumes in pods.
- **AGIC** — Use App Gateway as K8s ingress.
- **Workload Identity** — Use managed identities for pods.

### Networking Models
| Model | How It Works | When to Use |
|---|---|---|
| **Kubenet** | Pods get internal IPs, use NAT for outbound | Simple workloads, IP-constrained VNets |
| **Azure CNI** | Each pod gets a VNet IP | Enterprise, pod IP visibility needed |
| **Azure CNI Overlay** | Pods get overlay IPs, nodes get VNet IPs | Scale without IP exhaustion |
| **Cilium** | eBPF-based networking + network policy | Advanced networking, better performance |

### Interview Q&A
**Q: How does AKS cluster autoscaler work?**
A: When pods can't be scheduled, the autoscaler adds nodes. When nodes are underutilized, it removes them. Configured per node pool with min/max counts.

**Q: How do you secure secrets in AKS?**
A: Use Azure Key Vault with Secret Store CSI Driver — secrets mounted as volumes, not stored in etcd. Use Workload Identity for pod-to-Azure-service auth.

---

## 1.4 Azure Functions

### Overview
Serverless compute. Write code that runs on events. Pay only for execution time.

### Hosting Plans
| Plan | Scaling | Duration Limit | Cold Start | Use Case |
|---|---|---|---|---|
| **Consumption** | Automatic | 10 min (default 5) | Yes | Event-driven, unpredictable load |
| **Premium** | Automatic (pre-warmed) | Unlimited | Minimal | No cold start, VNet, long runs |
| **App Service (Dedicated)** | Manual/Auto-scale | Unlimited | No | Full control, existing plan |
| **Flex Consumption** | Automatic, per-function | 60 min | Low | Fast scaling, per-function config |

### Triggers & Bindings
- **Triggers** — What starts the function: HTTP, Timer, Blob, Queue, Service Bus, Event Grid, Event Hubs, Cosmos DB, SignalR, Durable
- **Bindings** — Declarative connection to data/services (input/output). No SDK code needed.

### Durable Functions
Stateful orchestration patterns:
- **Function Chaining** — Sequential steps
- **Fan-out/Fan-in** — Parallel execution then aggregate
- **Async HTTP API** — Long-running operations with polling
- **Monitor** — Recurring checks
- **Human Interaction** — Wait for external approval

### Interview Q&A
**Q: When to use Functions vs Logic Apps?**
A: Functions = code-first, complex logic, performance-sensitive. Logic Apps = designer-first, no-code, integration with 200+ connectors.

---

## 1.5 Azure Container Apps

### Overview
Serverless container platform built on K8s + Envoy + KEDA. No cluster management.

### Key Features
- Built-in KEDA scaling (scale to zero)
- Revision management with traffic splitting (blue/green, canary)
- Built-in ingress (HTTP/TCP)
- Dapr integration for microservices
- Service discovery within environment

### Container Apps vs AKS vs App Service
| Feature | Container Apps | AKS | App Service |
|---|---|---|---|
| Management | Fully serverless | Manage nodes | Fully managed |
| K8s features | Subset | Full K8s | None |
| Scaling | KEDA (scale to zero) | Cluster autoscaler + KEDA | Auto-scale (min 1) |
| Best for | Microservices, event-driven | Complex K8s workloads | Web apps, APIs |

---

## 1.6 Azure Container Instances (ACI)

### Overview
Fastest way to run a container. No VMs, no orchestration.

### Key Features
- Fast startup (seconds)
- Container groups (multiple containers sharing network/lifecycle — like a pod)
- VNet integration, GPU support, persistent storage via Azure Files

### Use Cases
- Quick batch jobs, CI/CD agents
- Testing containers before AKS deployment
- Burst capacity for AKS (virtual nodes)

---

## 1.7 Azure Static Web Apps

### Overview
Full-stack static app hosting + serverless APIs. Built-in CI/CD from GitHub/Azure DevOps.

- Free tier available
- Auto-deploy from GitHub Actions
- Built-in Azure Functions for API
- Free SSL, custom domains, built-in auth
- Preview environments per PR

---

## 1.8 Azure Spring Apps

### Overview
Managed Spring Boot microservice platform.

- Run Spring Boot without managing K8s
- Built-in service discovery, config server
- Blue/green deployments, VNet integration, auto-scaling
