Serverless Architecture - Introduction to FaaS

15 min read | 2025.12.04

What is Serverless

Serverless is an architecture where you delegate server management to cloud providers and focus only on code execution. It doesn’t mean “no servers” but rather “you don’t need to think about servers.”

Benefits: No infrastructure management, automatic scaling, pay only for what you use

Types of Serverless

FaaS (Function as a Service)

Execute functions via event triggers.

// AWS Lambda example
export const handler = async (event) => {
  const name = event.queryStringParameters?.name || 'World';
  return {
    statusCode: 200,
    body: JSON.stringify({ message: `Hello, ${name}!` })
  };
};

BaaS (Backend as a Service)

Provides backend functionality like authentication, databases, and storage as services.

BaaS ExampleCategory
Firebase AuthenticationAuth
FirestoreDatabase
AWS S3Storage
AlgoliaSearch

How FaaS Works

flowchart LR
    Event --> Startup["Container startup"]
    Startup --> Exec["Function execution"]
    Exec --> Response
    Response --> Stop

Parallel execution: Functions A, B, C can run simultaneously

Scaling: 0 → 1 → 100 → 1000 → 0 (automatic)

Event Sources

EventTriggerFunction
HTTP RequestAPI GatewayLambda
File UploadS3 EventLambda
ScheduleCloudWatchLambda
MessageSQS/SNSLambda
Database ChangeDynamoDBLambda

Major FaaS Platforms

ServiceProviderFeatures
AWS LambdaAmazonMarket leader, rich integrations
Cloud FunctionsGoogleGCP integration, Firebase integrated
Azure FunctionsMicrosoft.NET affinity
Cloudflare WorkersCloudflareEdge execution, low latency
Vercel FunctionsVercelFrontend integration

Cold Start

When a function runs for the first time, container startup takes time.

Start TypeFlowNotes
Cold startRequest → Container startup (100-1000ms) → Function execution → ResponseInitial latency
Warm startRequest → Function execution → ResponseContainer reuse
After idleContainer stops → Next request is cold start

Cold Start Mitigation

StrategyDescription
Provisioned ConcurrencyPre-start containers
Regular warmupKeep containers warm with periodic execution
Lightweight runtimeNode.js, Python (faster than Java)
Dependency optimizationReduce package size
// Initialize connections outside handler (will be reused)
const db = new Database();

export const handler = async (event) => {
  // db is reused
  return await db.query('SELECT * FROM users');
};

Pricing Model

Pay-per-use Example (AWS Lambda)

Cost = Request count × Execution time × Memory

MetricValue
Requests1 million/month
Average execution time200ms
Memory512MB
Cost≈ $0.20 + $3.33 = $3.53/month

Free tier: 1M requests, 400,000 GB-seconds/month

Comparison with Traditional Servers

ModelCost Calculation
Traditional Server24 hours × 30 days = 720 hours running → Always charged (even when idle)
ServerlessCharged only for actual execution time → No charge when idle

Use Cases

Good Fit

  • ✓ Event-driven processing (file processing, webhooks)
  • ✓ Irregular batch processing
  • ✓ API backends (especially low-medium traffic)
  • ✓ Parts of microservices
  • ✓ Prototyping, MVPs

Not a Good Fit

  • ✗ Consistently high traffic (cost inefficient)
  • ✗ Long-running processes (timeout limits)
  • ✗ Ultra-low latency required (cold starts)
  • ✗ Stateful processing
  • ✗ WebSocket (partial support)

Limitations

LimitAWS LambdaCloud Functions
Max execution time15 min9 min (HTTP), 60 min (event)
Memory128MB-10GB128MB-32GB
Payload size6MB (sync), 256KB (async)10MB
Concurrent executions1000 (default, can increase)Limited

Implementation Patterns

API Gateway + Lambda

flowchart LR
    Client --> Gateway["API Gateway<br/>(Auth, rate limiting, caching)"]
    Gateway --> Lambda
    Lambda --> DynamoDB

Event Processing Pipeline

flowchart TB
    S3_1["S3 (image upload)"] --> Lambda["Lambda<br/>(thumbnail generation)"]
    Lambda --> S3_2["S3 (save thumbnail)"]
    S3_2 --> SNS["SNS (notification)"]

Scheduled Execution

// serverless.yml
functions:
  dailyReport:
    handler: handler.generateReport
    events:
      - schedule: cron(0 9 * * ? *)  // Daily at 9am

Frameworks

FrameworkFeatures
Serverless FrameworkMulti-cloud support
AWS SAMAWS official, CloudFormation integration
SSTTypeScript, local development
TerraformUnified IaC management

Summary

Serverless is an architecture that reduces infrastructure management burden and lets you focus on development. It’s particularly suited for event-driven processing and irregular workloads. However, there are considerations like cold starts and execution time limits. It’s important to choose between serverless and traditional servers based on your use case.

← Back to list