Serverless & Edge Computing
Overview
Serverless and edge computing are transforming how applications are built and deployed. This tutorial covers AWS Lambda, API Gateway, and edge computing platforms like Cloudflare Workers and Vercel Edge. You'll learn to build event‑driven, globally distributed applications with minimal operational overhead.
1. Introduction to Serverless
Serverless (FaaS) allows you to run code without provisioning or managing servers.
Key characteristics
- Event‑driven: Functions are triggered by events (HTTP requests, database changes, etc.).
- Auto‑scaling: Automatically scales from 0 to thousands of concurrent executions.
- Pay‑per‑use: Only pay for execution time (millisecond billing).
- Managed infrastructure: No server maintenance.
Popular serverless platforms
- AWS Lambda: Most mature, integrated with AWS ecosystem.
- Google Cloud Functions: Integrated with GCP.
- Azure Functions: Integrated with Microsoft ecosystem.
- Vercel Functions: Built for Next.js applications.
- Cloudflare Workers: Edge‑based serverless (global edge).
2. AWS Lambda
AWS Lambda is the most popular serverless platform. Functions run in response to events and scale automatically.
Infrastructure as Code (Serverless Framework)
3. API Gateway
API Gateway is a managed service for creating and managing APIs that expose Lambda functions (or other backends) via HTTP.
4. Edge Computing
Edge computing runs code at the edge (closest to users), reducing latency.
Cloudflare Workers
Vercel Edge Functions
- Geolocation‑based personalisation
- A/B testing
- Bot protection
- Real‑time user personalisation
- Edge caching of API responses
5. Use Cases & Best Practices
Best use cases for serverless
- APIs with variable traffic: Auto‑scales to handle spikes.
- Background processing: Image/video processing, data transformation.
- Event‑driven workflows: File uploads, database changes, schedule tasks.
- Microservices: Small, focused functions.
- Prototyping: Fast development and iteration.
Best practices
- Keep functions small: Single responsibility.
- Use environment variables: For configuration.
- Monitor and log: Use CloudWatch, Datadog, etc.
- Optimise cold starts: Use provisioned concurrency if needed.
- Secure your functions: Use IAM roles, API keys, JWT.
Quiz
Question 1
What is the primary billing model for AWS Lambda?
- Fixed monthly fee
- Per‑request + per‑execution time
- Per‑GB of storage
- Based on the number of concurrent executions
Show answer
Question 2
Which platform runs code at the edge, closest to users?
- AWS Lambda
- Cloudflare Workers
- Google Cloud Functions
- Azure Functions
Show answer
Question 3
What is a "cold start" in serverless?
- When the function runs for the first time after being idle
- When the function encounters an error
- When the function is deployed
- When the function times out
Show answer
Exercises
Exercise 1
Write an AWS Lambda function that returns a random number between 1 and 100. Deploy it with API Gateway.
Sample answer
Use Serverless Framework or AWS Console to deploy.
Exercise 2
Write a Cloudflare Worker that caches API responses for 1 hour and returns a custom greeting based on the user's geolocation.
Sample answer
Homework
Homework 1
Deploy a serverless function for your capstone project's backend using AWS Lambda or Cloudflare Workers. Include a REST API endpoint and implement caching.
Sample outline
- Platform: AWS Lambda + API Gateway.
- Function: Products API (GET /products, GET /products/:id).
- Caching: Use CloudFront or API Gateway caching.
- Monitoring: CloudWatch logs and metrics.
Mini‑Project
Serverless Application
Build a complete serverless application with:
- AWS Lambda + API Gateway for the backend
- S3 for static assets (frontend)
- Edge caching with CloudFront or Cloudflare
- Database (DynamoDB or RDS)
- Monitor with CloudWatch
Sample outline
- Backend: Lambda functions for CRUD operations.
- API: API Gateway REST API.
- Frontend: Static site in S3.
- Database: DynamoDB for low‑cost storage.
- Edge: CloudFront CDN for global delivery.
Tutorial Summary
You learned about serverless platforms (AWS Lambda, API Gateway) and edge computing (Cloudflare Workers, Vercel Edge). You can now build event‑driven, globally distributed applications that scale automatically and cost efficiently.
Key takeaway: Serverless and edge computing represent the future of cloud architecture — focusing on code, not infrastructure.