Serverless Computing: When and When Not to Use It

📅 November 2, 2018
⏱️ 12 min read

Evaluating serverless vs. containers, comparing major provider services, cold start challenges, cost implications, and how to pick the right compute model for your workload.

1. Core Compute Models Compared

The three dominant compute models span a spectrum from full control to zero management:

ModelManagement ScopeScalingBillingTypical Use Cases
Virtual MachinesYou manage OS, patches, runtime, appsManual or autoscaling groupsPer-second or per-hourLong-running services, custom OS needs, full root access
Containers (ECS/EKS, ACI, Cloud Run)You manage container image, platform manages orchestrationScale to zero (managed) or manualPer-second while runningHTTP APIs, background workers, microservices with custom runtimes
Serverless (Lambda, Azure Functions, etc.)You manage only function code and configAutomatic, scales to zeroPer-invocation + resource-timeEvent handlers, webhooks, scheduled jobs, lightweight APIs
Key distinction: Serverless is a deployment and billing model, not a language or framework. The "functions" are just code units managed by a platform that provisions, scales, and bills automatically.

2. Major Serverless Platforms: Vendor Comparison

Each hyperscaler offers function-as-a-service (FaaS) with different runtimes, integration patterns, and pricing. Here is the current landscape:

ProviderService NameMax MemoryMax DurationPricing (per GB-s)Free Tier
AWSLambda10,240 MB15 minutes$0.00001666671M invocations + 400K GB-s / month
Microsoft AzureAzure Functions14,336 MB10 minutes (consumption)
60 minutes (premium)
$0.00001601M invocations + 400K GB-s / month
Google CloudCloud Functions (2nd gen)16,384 MB60 minutes$0.00000252M invocations + 360K GB-s / month
Oracle CloudOCI Functions1,024 MB (max 6 per function)5 minutes$0.000004171K invocations / month
Alibaba CloudFunction Compute16,384 MB60 minutes (container image)$0.0000161M invocations + 400K GB-s / month
IBM CloudCloud Functions2,048 MB60 minutes$0.000011115M invocations / month
Tencent CloudSCF16,384 MB60 minutes (container)$0.000016661M invocations / month

Runtime support comparison

ProviderNative RuntimesCustom RuntimeContainer ImageProvisioned Concurrency
AWS LambdaNode.js, Python, Java, Go, .NET, RubyYes (custom runtime API)Yes (up to 10 GB)Yes (provisioned concurrency)
Azure FunctionsNode.js, Python, PowerShell, Java, C#, .NETYes (custom handlers)YesYes (premium plan)
GCP Cloud FunctionsNode.js, Python, Go, Java, .NET, Ruby, PHPYesYes (2nd gen)Yes (min instances)
OCI FunctionsPython, Node.js, Go, Java, RubyYesYes (container images only)Yes (pre-provisioned concurrency)
Alibaba FCNode.js, Python, Java, PHP, C++, GoYesYesYes (provisioned concurrency)
IBM CloudNode.js, Python, Java, Go, Ruby, SwiftYesLimitedLimited
Tencent SCFNode.js, Python, Java, C#, Go, PHPYesYesYes (provisioned concurrency)
Recommendation: AWS Lambda and GCP Cloud Functions (2nd gen) lead in runtime flexibility and event integration. Azure Functions excels for .NET shops. OCI Functions is container-only but tightly integrated with Oracle Cloud. For non-US markets, Alibaba and Tencent offer strong local presence.

3. Serverless vs Containers vs VMs

Choosing a compute model is an architecture decision, not a trend. Here is how to evaluate:

FactorServerless (FaaS)Containers (managed)Virtual Machines
Cold startHigh (100ms - 5s+ depending on runtime)Moderate (50ms - 2s)None (always warm)
Scale to zeroYes, automaticYes, on managed platformsNo
Billing granularityPer-invocationPer-second while runningPer-hour
Vendor lock-inHighModerate (container images portable)Low
DebuggingLimited local parityGood (local container run)Full control
Custom dependenciesLimited (layers/custom runtimes)Full (container image)Full control
Event integrationExtensive (cloud-native events)ModerateManual setup
Best forBursty, event-driven, glueHTTP APIs, microservicesStateful, long-running, custom OS

Managed container options

If you want serverless benefits without FaaS cold starts, consider managed container platforms:

PlatformScale to zeroPricing modelNotes
AWS FargateNo (ECS/Fargate)Per-vCPU-secondECS or EKS, no cold start, no scale-to-zero
AWS App RunnerYesPer-second while servingBuild from source or container, scales to zero
Google Cloud RunYesPer-second while servingKnative-based, scales to zero, generous free tier
Azure Container AppsYesPer-second while servingBased on Dapr/KEDA, scales to zero
OCI Container InstancesNoPer-secondSimple container run, no orchestration
Decision matrix: Use FaaS for event-driven glue and bursty workloads. Use Cloud Run / App Runner for HTTP APIs that need scale-to-zero without cold starts. Use Fargate / Container Instances for long-running services that need container flexibility.

4. When Serverless Wins

Serverless is excellent for:

Use CaseWhy Serverless FitsProvider Strength
Infrequent jobsPay only when running; zero idle costAll providers
WebhooksAuto-scale on burst; event-native triggersAWS Lambda + API Gateway
File processing (S3/Cloud Storage triggers)Built-in object store event sourcesAWS Lambda (S3 events)
Scheduled tasks (cron replacement)No need to keep a process runningAWS Lambda (EventBridge), GCF (Pub/Sub)
Lightweight API backendsScales with traffic; no capacity planningAWS Lambda + API Gateway, Cloud Run
Real-time stream processingPush-based event modelAWS Lambda (Kinesis/DynamoDB Streams), GCF (Pub/Sub)
Chatbot / voice assistantsMillions of users, zero sustained trafficAWS Lambda (Lex), Azure Functions (Bot Service)
Image/video processingBurst on upload; parallel processingAWS Lambda + Step Functions, GCF

When to pick a specific serverless platform

ScenarioRecommended PlatformWhy
AWS-centric stack, rich event sourcesAWS Lambda + EventBridge + SQS/SNSDeepest integration with all AWS services, largest ecosystem
.NET shop, Visual Studio integrationAzure FunctionsNative .NET support, easy local debugging, Azure DevOps integration
Data pipelines on GCP, Pub/Sub eventsCloud Functions (2nd gen)Built on Cloud Run, integrates with BigQuery, Pub/Sub, Vertex AI
Oracle Cloud workloads, OCI ecosystemOCI FunctionsTight integration with Autonomous Database, Object Storage, Streaming
Low-latency API, scale to zeroGoogle Cloud Run or AWS App RunnerContainer image support, near-zero cold starts with min instances
Multi-region global edgeCloudflare Workers / VercelEdge runtime, sub-50ms cold starts globally
Guidance: Serverless excels where you have unpredictable traffic, event-driven logic, or short-lived tasks. The cost alignment (pay-per-execution) is its most powerful feature for intermittent workloads.

5. When Containers Win

Serverless is a poor fit when you need:

RequirementWhy Serverless FailsBetter Choice
Steady high-throughputBilled per invocation can outcost reserved VMsFargate, Cloud Run with min instances, or VMs
Strict cold-start SLAs (<50ms)Cold starts add hundreds of msCloud Run (min instances=1) or Fargate
Long-running processes (>15 min)Lambda caps at 15 minutesContainers or VMs
Custom runtimes or binariesLimited by supported runtimesContainer image support
Large dependency packages (>250 MB)Layers add complexityContainer images (Cloud Run, App Runner)
Predictable constant trafficNo cost advantage over containersReserved instances or committed use discounts
Bare-metal networking or GPUNot available in FaaSVMs or GPU instances
Complex local debuggingLimited local simulationContainers (run locally, deploy same image)

6. Cold Start Deep Dive

Cold start is the initialization delay when a serverless platform spins up a new instance of your function. It is the primary performance trade-off of serverless.

Contributing factors

FactorImpactMitigation
Runtime/languageJVM/.NET ~ 3-5s; Node.js/Python ~ 100-500msChoose a lighter runtime or use container images
Deployment package sizeLarger packages take longer to download/importMinimize dependencies, use layers, trim unused code
Memory allocationHigher memory = more CPU = faster initAllocate more memory if cost permits
Initialization codeHeavy setup (DB connections, SDK init) runs per cold startLazy-load dependencies, reuse connections in global scope
VPC attachmentENI provisioning adds 500ms-2s on AWSUse VPC-less design, or provisioned concurrency for VPC functions

Provisioned concurrency and warmed instances

ProviderFeatureUse case
AWS LambdaProvisioned ConcurrencyKeep functions pre-initialized for predictable latency
AWS LambdaSnapStart (Java only)Snapshots JVM after init, reducing cold starts to <1s
Azure FunctionsPremium planAlways-warmed instances, VNET connectivity
GCP Cloud FunctionsMin instancesKeep N instances always warm
OCI FunctionsPre-provisioned concurrencyKeep functions pre-initialized
Cloud RunMin instancesKeep N containers always ready
Cold start checklist: Measure p99 latency under load. Use provisioned concurrency/min instances for user-facing APIs. Optimize the global scope initialization. Avoid VPC unless necessary. Consider Cloud Run for HTTP workloads where cold starts matter.

7. Cost Modeling and Pricing Models

Serverless is cheap at low volume and can be expensive at sustained high volume. Model before choosing.

Pricing models across providers

ProviderPricing ComponentsFree TierCrossover Point
AWS Lambda$0.20 per 1M requests + $0.00001667 per GB-s1M requests + 400K GB-s / month for 12 months~5M requests / 20M GB-s (vs. t4g.micro)
Azure Functions$0.20 per 1M executions + $0.000016 per GB-s1M requests + 1GB-s / month free~6M requests / 16M GB-s
GCP Cloud Functions$0.40 per 1M invocations + $0.0000025 per GB-s2M invocations + 360K GB-s / month~8M invocations (GCP is cheapest per GB-s)
OCI Functions$0.00000417 per GB-s + $0.0000041 per invocation1K invocations per monthVery cheap, but limited free tier
Cloud Run$0.000024 per vCPU-s + $0.0000025 per GB-s180K vCPU-s + 360K GB-s + 2M requests / monthCompetitive with FaaS for HTTP workloads

Cost comparison example

A function with 512 MB memory invoked 100 times/second with 100 ms duration:

# Approximate monthly cost (720 hours)

# AWS Lambda:
# 100 * 3600 * 24 * 30 = ~2.6M invocations
# Duration cost = 2.6M * 0.1s * 0.5GB * $0.00001667/GB-s
# Total ~ $640/month

# GCP Cloud Run (min_instances=0):
# Same compute = 2.6M * 0.1s * 0.5 vCPU * $0.000024/vCPU-s
# Plus request cost = 2.6M * $0.0000024
# Total ~ $1,050/month (but no provision time cost)

# Fargate (always on):
# 0.05 vCPU * 730 hours * $0.04048/vCPU-hr
# Plus 1GB memory * 730 * $0.004445/GB-hr
# Total ~ $140/month (but always running)
Rule of thumb: Use serverless for bursty or low-trafficked workloads. For anything consistently above 10% of the month's free tier equivalent, calculate whether containers or reserved instances would be cheaper. The crossover point varies significantly by provider and workload profile.

8. Event Sources and Trigger Integration

Serverless functions are triggered by events. Each provider has a different event model and integration surface.

Event SourceAWS LambdaAzure FunctionsGCP Cloud FunctionsOCI Functions
Object storageS3 Event NotificationsBlob Storage EventsCloud Storage eventsObject Storage events
Message queueSQS, SNSAzure Queue, Service BusPub/SubStreaming, Queue
Database streamsDynamoDB Streams, RDSCosmos DB Change FeedFirestore, BigQueryAutonomous DB events
HTTP/WebhookAPI GatewayHTTP TriggerHTTP TriggerAPI Gateway
Scheduled (cron)EventBridge (CloudWatch Events)Timer TriggerCloud SchedulerEvents Service
File systemEFS mount (container)LimitedFilestoreFile Storage
IoTIoT Core rulesIoT HubCloud IoT CoreLimited
Event busEventBridgeEvent GridEventarcEvents Service
Orchestration: For multi-step workflows, use Step Functions (AWS), Durable Functions (Azure), Workflows (GCP), or orchestrate with Apache Airflow on managed Kubernetes. Complex logic in a single function is an anti-pattern.

9. Vendor Lock-in and Portability

FaaS platforms are deeply integrated with their cloud's event model, IAM, and managed services. Lock-in is real.

StrategyApproach
Abstract the platformWrap function calls behind an internal interface you control
Minimize cloud-specific eventsStandardize on HTTP/webhook triggers and message queues
Use container-based FaaSCloud Run, OCI Functions accept container images
Treat functions as glueKeep business logic in portable code libraries, not in the function
Plan for portabilityAvoid vendor-specific SDK calls inside functions

Multi-cloud and hybrid options

FrameworkDescriptionLanguages
Serverless FrameworkDeploy to AWS, Azure, GCP, OCI with one configNode.js, Python, Java, Go, .NET
AWS SAMServerless app model, AWS-onlyNode.js, Python, Java, Go, .NET
Azure Functions Core ToolsLocal dev and deployment, Azure-onlyAll Azure-supported languages
Google Cloud Functions FrameworkLocal testing, GCP or on-premPython, Go, Java, Node.js
KnativeKubernetes-native serverless, any cloudAny (container-based)
Warning: No framework eliminates lock-in entirely. Multi-cloud adds operational complexity. Choose portability only when you have a real business requirement for it, not as a hypothetical.

10. Pitfalls and Best Practices

Serverless is powerful but easy to misuse. Here are the most common mistakes:

PitfallConsequenceSolution
Long initialization in global scopeEvery invocation pays the costMoved heavy init to lazy loading in the handler
No monitoring or loggingHard to debug in productionUse structured logs, correlate with trace IDs, set alerts
Ignoring concurrency limitsSilent throttling at scaleCheck default quotas, request increases, use provisioned concurrency
Putting everything in one functionHard to maintain, slow cold startsDecompose into small single-purpose functions
Not caching connectionsRepeated DB/API connection overheadReuse clients outside the handler
Ignoring dead-letter queuesFailed events are lostConfigure DLQ for async invocations
VPC attachment by defaultAdds seconds to cold startsOnly use VPC when accessing private resources

Best practices summary

CategoryPractice
DesignKeep functions single-purpose, stateless, and short
DependenciesMinimize packages, use layers, trim unused code
StateExternalize state to managed databases or caches
Error handlingReturn structured errors, use DLQs, retry with backoff
SecurityPrinciple of least privilege IAM roles per function
MonitoringLogs, metrics, traces, and alerts per function
TestingLocal unit tests, integration tests with real event payloads
DeploymentInfrastructure as code, blue/green or canary deployments
Final guidance: Serverless removes server management and scales to zero. It is excellent for event-driven workloads, APIs with variable traffic, and glue logic between services. It is a poor default for steady high-throughput systems or workloads with strict latency requirements at cold start. Always model your expected invocation count, duration, and memory before choosing serverless over containers.
Topics & Tags
Serverless Lambda Cloud Functions Containers Architecture Cost Optimization AWS Azure GCP