Skip to main content

Serverless

Serverless computing is a cloud execution model where the cloud provider manages the infrastructure, automatically provisions resources, and scales based on demand. You write code; the platform handles everything else.

Key Characteristics

  • No server management: No provisioning, patching, or scaling decisions
  • Pay-per-use: Charged only for actual execution time
  • Auto-scaling: Scales from zero to thousands of instances automatically
  • Event-driven: Functions triggered by events (HTTP, queues, schedules)

Serverless vs Traditional

AspectServerlessTraditional Server
ScalingAutomaticManual/configured
PricingPer executionPer hour/month
Cold startsYesNo
MaintenanceProviderYou
ControlLimitedFull
StateStatelessStateful possible

AWS Serverless Stack

ServicePurpose
LambdaCompute (functions)
API GatewayHTTP APIs
DynamoDBDatabase
S3File storage
SQS / SNSMessaging
EventBridgeEvent routing
CognitoAuthentication
CloudFrontCDN

Common Patterns

API Backend

CloudFront → API Gateway → Lambda → DynamoDB

Event Processing

S3 Upload → Lambda → Process → Store Result

Scheduled Tasks

EventBridge (cron) → Lambda → Task Execution

Queue Processing

SQS → Lambda → Process Message → External Service

What We Like

  • Operational simplicity: Focus on code, not infrastructure
  • Cost efficiency: No idle costs, great for variable workloads
  • Scalability: Handle traffic spikes without planning
  • Speed to deploy: From code to production in minutes
  • Reduced risk: Less infrastructure to secure

What We Don't Like

  • Cold starts: Initial latency on first invocation
  • Vendor lock-in: Architectures tied to specific providers
  • Debugging: Distributed systems are harder to trace
  • Statelessness: Requires rethinking data patterns
  • Execution limits: Timeouts, memory caps, package sizes

Cold Start Mitigation

  • Provisioned Concurrency: Keep instances warm (costs money)
  • Smaller packages: Faster initialisation
  • Choose runtime wisely: Node.js/Python start faster than Java
  • Keep functions warm: Scheduled pings (hacky but works)

When to Use Serverless

Good fit:

  • Variable or unpredictable traffic
  • Event-driven workloads
  • APIs with sporadic usage
  • Background processing
  • Startups and MVPs

Consider alternatives for:

  • Consistent high traffic (EC2 may be cheaper)
  • Long-running processes
  • Stateful applications
  • Ultra-low latency requirements

Beyond AWS

ProviderService
Google CloudCloud Functions, Cloud Run
AzureAzure Functions
CloudflareWorkers
VercelEdge Functions