Serverless Architecture: Patterns, Limits, and Economics
#serverless#cloud#architecture#aws#gcp
Serverless computing shifts operational responsibility to the cloud provider, letting teams focus on business logic. But "serverless" is not a universal solution -- understanding its patterns, constraints, and cost dynamics is critical to making good architectural decisions.
Core Serverless Patterns
API Backend
The most common pattern: HTTP requests routed through an API Gateway to functions.
- API Gateway + Lambda / Cloud Functions
- Automatic scaling from zero to thousands of concurrent requests
- Pay-per-invocation pricing
Event Processing
Functions triggered by events from queues, streams, or storage changes.
- S3 upload triggers image processing
- SQS/SNS message triggers order fulfillment
- Kinesis/Pub-Sub stream triggers real-time analytics
Scheduled Jobs
Replacing cron servers with scheduled function invocations.
- EventBridge Scheduler + Lambda
- Cloud Scheduler + Cloud Functions
- Ideal for periodic data syncs, report generation, cleanup tasks
Orchestration Workflows
Composing multiple functions into complex workflows.
- AWS Step Functions / GCP Workflows
- Error handling, retries, and parallel execution built in
- Visual workflow definition
Serverless Services Landscape
| Category | AWS | GCP | Azure |
|---|---|---|---|
| Compute | Lambda | Cloud Functions / Cloud Run | Azure Functions |
| API | API Gateway | API Gateway / Cloud Endpoints | API Management |
| Orchestration | Step Functions | Workflows | Durable Functions |
| Database | DynamoDB | Firestore | Cosmos DB (serverless) |
| Storage | S3 | Cloud Storage | Blob Storage |
| Messaging | SQS, SNS, EventBridge | Pub/Sub, Eventarc | Event Grid, Service Bus |
Known Limits and Constraints
| Constraint | Impact | Mitigation |
|---|---|---|
| Cold starts | 100ms to several seconds latency on first invocation | Provisioned concurrency, keep-warm patterns |
| Execution time | Lambda: 15 min, Cloud Functions: 60 min | Break into smaller steps, use Step Functions |
| Payload size | API Gateway: 10MB, Lambda: 6MB sync | Use S3 presigned URLs for large payloads |
| Concurrency limits | Default 1000 concurrent per region | Request quota increases, implement throttling |
| Vendor lock-in | Deep integration with provider services | Portable business logic, adapter patterns |
| Debugging | Distributed tracing is harder than monolith debugging | X-Ray, structured logging, local emulators |
When Serverless Saves Money
- Variable traffic -- pay nothing at zero, scale automatically at peak
- Infrequent workloads -- scheduled jobs that run minutes per day
- Prototyping -- no infrastructure cost until real traffic arrives
- Event-driven pipelines -- bursty, unpredictable processing loads
When Serverless Costs More
- Steady high-throughput -- constant load is cheaper on reserved containers/VMs
- Long-running processes -- per-millisecond billing adds up for 10+ minute executions
- High memory workloads -- Lambda pricing scales linearly with memory allocation
- Chatty architectures -- many small inter-function calls multiply invocation costs
Cost Comparison Framework
| Workload Profile | Serverless | Containers (Fargate) | VMs (Reserved) |
|---|---|---|---|
| Spiky, low baseline | Best | Good | Worst |
| Steady, predictable | Worst | Good | Best |
| Short burst processing | Best | Good | Over-provisioned |
| 24/7 high throughput | Expensive | Moderate | Cheapest |