Azure Functions is a serverless compute service in Azure. You write code, and Azure runs it automatically whenever an event triggers it. No need to manage servers or infrastructure.
🟢 1. What is Azure Function?
- Serverless → pay only for execution time, no VM management.
- Runs small units of code ("functions") in response to triggers.
- Supports multiple languages (C#, JavaScript, Python, Java, PowerShell, etc.).
🟢 2. Key Concepts
- Function App → Container for one or more functions (like a project).
- Trigger → Event that starts a function (HTTP request, Timer, Blob, Queue, Event Hub, etc.).
- Binding → Way to connect to other services without boilerplate code.
- Input Binding: brings data into function.
- Output Binding: sends data from function.
- Consumption Plan → Auto-scales and pay-per-use.
- Premium/Dedicated Plan → Pre-warmed instances, VNET support, higher performance.
🟢 3. Types of Triggers
- HTTP Trigger → run on API calls.
- Timer Trigger → run on schedule (CRON).
- Blob Trigger → run when file uploaded/modified in Blob Storage.
- Queue Trigger → run when message is added to Azure Storage Queue.
- Event Hub / Service Bus Trigger → run on event/message arrival.
- Cosmos DB Trigger → run when document changes in Cosmos DB.
🟢 4. Example: HTTP Trigger (C#)
[FunctionName("HelloFunction")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger executed.");
string name = req.Query["name"];
return new OkObjectResult($"Hello {name}");
}
👉 Call: https://<function-app>.azurewebsites.net/api/HelloFunction?name=Tushar
🟢 5. Authorization Levels
- Anonymous → No key required.
- Function → Requires function key.
- Admin → Master key required.
- Supports Azure AD / Entra ID authentication.
🟢 6. Durable Functions (Stateful Workflows)
- Built on top of Azure Functions.
- Lets you write stateful workflows in code.
- Patterns supported:
- Function chaining (A → B → C)
- Fan-out/Fan-in (parallel tasks then aggregate)
- Human interaction (wait for external input)
🟢 7. Monitoring & Logging
- Integrated with Application Insights.
- Tracks execution time, failures, dependencies.
🟢 8. Best Practices
- Keep functions small and single responsibility.
- Use retry policies for transient errors.
- Handle exceptions & logging properly.
- Choose right hosting plan based on workload.
- Secure secrets with Azure Key Vault.
- Version your APIs (for HTTP functions).
🟢 9. Pros & Cons
✅ Pros:
- Auto scaling, pay-per-use.
- Easy integration with Azure services.
- Event-driven, quick to build APIs.
❌ Cons:
- Cold start latency (Consumption plan).
- Limited execution time in consumption (5–10 min).
- Vendor lock-in (Azure specific).
🟢 10. Common Interview Questions
- What are triggers and bindings in Azure Functions?
- Difference between Consumption, Premium, and Dedicated plans?
- How do you secure an HTTP-triggered function?
- Explain Durable Functions with a use case.
- How do you monitor failures in Azure Functions?
- How do you handle configuration and secrets securely?
- Difference between Azure Functions and Azure Logic Apps?
- What is a cold start? How to reduce it?
✅ Quick Recap for Interview:
- Azure Function = serverless event-driven code.
- Key building blocks → Triggers + Bindings.
- Supports many triggers (HTTP, Timer, Blob, Queue, Cosmos, Event Hub).
- Plans → Consumption (pay-per-use), Premium (no cold start), Dedicated (App Service plan).
- Durable Functions → Orchestration + workflows.
Comments
Post a Comment