Cloud Notes
Understanding Function as a Service (FaaS) serverless computing model, covering AWS Lambda, Azure Functions, and Google Cloud Functions with practical examples.
Function as a Service (FaaS) is a serverless computing model where developers write individual functions that execute in response to events. The cloud provider manages all infrastructure — servers, scaling, patching, and availability — letting developers focus purely on business logic.
FaaS Execution Model
FaaS Platforms
| Platform | Provider | Languages | Max Timeout |
|---|---|---|---|
| AWS Lambda | Amazon | Python, Node, Java, Go, .NET, Ruby | 15 min |
| Azure Functions | Microsoft | C#, JavaScript, Python, Java, PowerShell | Unlimited* |
| Cloud Functions | Node.js, Python, Go, Java, .NET, Ruby | 60 min | |
| IBM Functions | IBM | Node.js, Python, Swift, PHP | 10 min |
| Cloudflare Workers | Cloudflare | JavaScript, Rust, WASM | 30 sec (free) |
Writing FaaS Functions
AWS Lambda (Python)
import json
import boto3
def lambda_handler(event, context):
"""Process an API Gateway request"""
# Extract request data
body = json.loads(event.get('body', '{}'))
name = body.get('name', 'World')
# Business logic
greeting = f"Hello, {name}! Welcome to serverless."
# Return response
return {
'statusCode': 200,
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
'body': json.dumps({
'message': greeting,
'timestamp': context.get_remaining_time_in_millis()
})
}Azure Functions (JavaScript)
Google Cloud Functions (Python)
import functions_framework
@functions_framework.http
def hello_http(request):
request_json = request.get_json(silent=True)
name = request_json.get('name', 'World') if request_json else 'World'
return {
'message': f'Hello, {name}! From Google Cloud Functions.',
'status': 'success'
}Deploying FaaS Functions
# AWS Lambda deployment
zip function.zip lambda_function.py
aws lambda create-function \
--function-name my-api-handler \
--runtime python3.11 \
--handler lambda_function.lambda_handler \
--zip-file fileb://function.zip \
--role arn:aws:iam::123456789:role/lambda-role \
--timeout 30 \
--memory-size 256
# Add API Gateway trigger
aws apigatewayv2 create-api \
--name my-api \
--protocol-type HTTP \
--target arn:aws:lambda:us-east-1:123456789:function:my-api-handler
# Google Cloud Functions deployment
gcloud functions deploy hello_http \
--runtime python311 \
--trigger-http \
--allow-unauthenticated \
--memory 256MB \
--region us-central1
# Azure Functions deployment
func azure functionapp publish my-function-appFaaS Pricing Model
| │ Free Tier | 1M requests + 400,000 GB-seconds/mo │ |
| │ After free tier | │ |
| │ Example | 10M requests/mo, 128MB, 200ms avg │ |
| │ Compute | 10M × 0.2s × 0.125GB = 250,000 GB-sec │ |
| │ Cost | (250,000 × $0.0000166667) + (10 × $0.20) │ |
| │ Total | $4.17 + $2.00 = $6.17/month │ |
| │ Equivalent server | ~$50-100/month (always on) │ |
FaaS vs Traditional Servers
| Aspect | FaaS | Traditional Server |
|---|---|---|
| Billing | Per-execution (ms) | Per-hour (running) |
| Scaling | Automatic (0 to thousands) | Manual or auto-scaling config |
| Cold Start | Yes (100ms-5s) | No (always running) |
| State | Stateless | Stateful |
| Max Duration | 15 min (Lambda) | Unlimited |
| Maintenance | Zero | OS patches, updates |
Interview Questions
- What is FaaS and how does it differ from traditional server-based computing?
FaaS executes individual functions in response to events, with zero server management. Unlike traditional servers that run continuously, FaaS functions are ephemeral, stateless, scale automatically, and charge only for actual execution time.
- What is a cold start in FaaS and how can you mitigate it?
Cold start is the delay when a function is invoked after being idle — the platform must provision a container and load the runtime. Mitigations: provisioned concurrency (Lambda), smaller deployment packages, lighter runtimes, and keeping functions warm with scheduled pings.
- When is FaaS NOT appropriate?
For long-running processes (>15 min), stateful applications, real-time systems requiring consistent low latency, high-throughput constant workloads (cheaper on reserved servers), and applications needing persistent connections.
- Explain event-driven architecture in the context of FaaS.
Functions are triggered by events (HTTP requests, file uploads, database changes, messages, schedules). This creates loosely coupled systems where components communicate through events rather than direct calls, improving scalability and maintainability.
- Compare AWS Lambda, Azure Functions, and Google Cloud Functions.
Lambda: most mature, largest ecosystem, 15-min timeout. Azure Functions: best for .NET, unlimited duration on premium plan, Visual Studio integration. Cloud Functions: simpler API, 60-min timeout, tight GCP integration, good for data pipelines.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for FaaS - Function as a Service.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Cloud Computing topic.
Search Terms
cloud-computing, cloud computing, cloud, computing, service, models, faas, function
Related Cloud Computing Topics