What I do
I provide guidance on building serverless applications using Functions-as-a-Service (FaaS) and managed services.
When to use me
Load this skill when:
- Event-driven workloads
- Variable/unpredictable traffic patterns
- Want to minimize operational overhead
- Pay-per-use cost model preferred
- Rapid iteration and deployment
- Don't need long-running processes
Core Principles
1. Stateless Functions
Functions don't maintain state between invocations.
2. Event-Driven
Functions triggered by events (HTTP, queue, schedule, etc.).
3. Managed Infrastructure
No server management - cloud provider handles scaling.
4. Pay Per Execution
Only pay for actual function execution time.
Function Structure
// AWS Lambda handler
export const handler = async (event: APIGatewayEvent) => {
const userId = event.pathParameters?.id;
const user = await dynamodb.get({
TableName: 'Users',
Key: { id: userId },
});
return {
statusCode: 200,
body: JSON.stringify(user),
};
};
Event Sources
HTTP (API Gateway)
// GET /users/{id}
export const getUser = async (event: APIGatewayEvent) => {
// Handle GET request
};
// POST /users
export const createUser = async (event: APIGatewayEvent) => {
// Handle POST request
};
Queue (SQS, EventBridge)
export const processOrder = async (event: SQSEvent) => {
for (const record of event.Records) {
const order = JSON.parse(record.body);
await processOrderLogic(order);
}
};
Schedule (Cron)
// Run every hour
export const cleanupOldRecords = async () => {
const cutoffDate = new Date();
cutoffDate.setHours(cutoffDate.getHours() - 24);
await dynamodb.delete({
TableName: 'TempRecords',
Key: { createdAt: { $lt: cutoffDate } },
});
};
Advantages
- No Server Management: Focus on code, not infrastructure
- Auto-Scaling: Automatic scaling to demand
- Cost Efficient: Pay only for execution time
- Fast Deployment: Deploy functions independently
- Built-in HA: High availability by default
Challenges
- Cold Starts: Initial invocation latency
- Execution Limits: Timeout constraints (15 min AWS Lambda)
- Vendor Lock-in: Platform-specific code
- Debugging: Harder to debug distributed functions
- State Management: No local state between invocations
Best Practices
- Keep functions small: Single responsibility
- Minimize cold starts: Keep dependencies minimal
- Use managed services: DynamoDB, S3, SQS instead of self-hosted
- Handle errors gracefully: Implement retries and dead letter queues
- Monitor everything: CloudWatch, distributed tracing
- Optimize bundle size: Tree-shake dependencies
Example Stack (AWS)
API Gateway → Lambda → DynamoDB
→ S3
→ SQS → Lambda → External API
Infrastructure as Code
# serverless.yml
service: user-service
provider:
name: aws
runtime: nodejs18.x
functions:
getUser:
handler: src/handlers/getUser.handler
events:
- http:
path: users/{id}
method: get
createUser:
handler: src/handlers/createUser.handler
events:
- http:
path: users
method: post
resources:
Resources:
UsersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Users
BillingMode: PAY_PER_REQUEST
References
- AWS Lambda documentation
- Serverless Framework
- AWS SAM (Serverless Application Model)
