Serverless Computing Explained: Architecture, Real-World Use Cases, and Trade-offs

Arpit Bhayani

Arpit Bhayani

May 02, 2022 • 9 min read

Play

Serverless Computing Explained: Architecture, Real-World Use Cases, and Trade-offs

Serverless computing is one of the most prominent paradigms in modern cloud architecture. Despite the name, serverless does not mean there are no servers executing your code. Instead, it shifts the operational responsibility of provisioning, scaling, patching, and fault tolerance entirely to the cloud vendor.

While serverless offers massive cost savings and operational velocity for certain workloads, adopting it blindly can lead to severe architectural friction, performance degradation, and unexpected bills. Understanding when to adopt serverless—and when to avoid it—requires evaluating system access patterns, execution lifecycles, and underlying operational trade-offs.


1. The Traditional Server Model vs. The Serverless Paradigm

The Problem with Traditional Provisioning

In a conventional infrastructure model, backend services run on dedicated virtual machines (such as AWS EC2) or long-running containers (such as Docker on ECS/Kubernetes). Capacity planning requires provisioning resources for anticipated peak loads.

  • Suppose you provision an instance with 4 GB RAM and 2 vCPUs to sustain a peak load of 1,000 Requests Per Second (RPS).
  • In a production environment, traffic is rarely constant. It is often spiky, cyclical, or bursty.
  • If that 1,000 RPS peak occurs for only 1% of the day, the machine sits largely idle for the remaining 99% of the time (handling perhaps 2 to 10 RPS).
Traditional Provisioned Capacity vs. Serverless On-Demand Execution

Traffic (RPS)
   ^
   |         Peak (1000 RPS)  [1% of the day]
   |              /\  
   |             /  \  <--- You pay 100% of the cost 24/7 for this peak buffer
   |            /    \ 
   |   ________/      \____________________ Low Traffic (2-10 RPS) [99%]
   +--------------------------------------------------------> Time

Under provisioned hosting, you pay continuously for the idle capacity. Even auto-scaling groups (ASGs) take minutes to detect load metrics, initiate VM boots, and pass health checks, frequently lagging behind abrupt traffic surges.

What is Serverless Computing?

Serverless is an execution model where the cloud provider dynamically manages the allocation and provisioning of compute resources. Code is deployed as isolated functions (Function-as-a-Service or FaaS) that execute on-demand in response to events.

flowchart LR
    Event[Event / API Call] --> Ingress[Cloud Gateway / Event Router]
    Ingress --> Orchestrator[Serverless Runtime Manager]
    Orchestrator -->|On-Demand Spin-up| MicroVM[Ephemeral MicroVM / Container]
    MicroVM --> Execution[Execute Business Logic]
    Execution --> Terminate[Tear Down / Sleep]

Key Pillars of Serverless

  1. Dynamic Elasticity: The platform scales up horizontally and vertically on demand—from zero instances to thousands—without manual capacity planning.
  2. Pay-Per-Execution Billing: Costs are determined solely by the compute time consumed (measured in milliseconds) and allocated memory, rather than uptime.
  3. Scale-to-Zero: When incoming traffic drops to zero, resource consumption drops to zero, and your infrastructure cost is precisely $0.
  4. No Server Maintenance: OS upgrades, security patches, hardware failures, and network routing are abstracted away completely.

Common implementations include AWS Lambda, Google Cloud Functions (GCF), Cloudflare Workers, and Azure Functions.


2. Five Real-World Use Cases Built for Serverless

Serverless is ideal for event-driven, sporadic, or bursty workloads with discrete execution boundaries.

Use Case 1: Infrequent Chatbots and Slash Commands

Consider an internal corporate Slack integration where employees trigger a /holidays command to query upcoming company holidays from a database.

  • Access Pattern: High infrequency. An employee might run this command once a week or once a month.
  • Inefficient Approach: Running a 24/7 microservice on a VM, incurring perpetual compute costs for virtually zero utilization.
  • Serverless Approach: Slack webhooks route the HTTP request directly to a serverless function via an API Gateway. The function wakes up, executes the database query, responds to the Slack channel in ~150ms, and shuts down. The billing footprint is constrained entirely to those 150ms.

Use Case 2: Online Judges and Code Evaluation Engines

Platforms like LeetCode or competitive programming portals accept arbitrary user submissions that require isolated, sandboxed execution against test suites.

sequenceDiagram
    autonumber
    participant User
    participant APIServer as API Service (Web)
    participant Lambda as Serverless Judge Function
    participant DB as Central Database

    User->>APIServer: Submit Code & Language
    APIServer->>Lambda: Trigger Isolated Execution (Payload + Test Cases)
    activate Lambda
    Note over Lambda: Ephemeral execution sandbox (Stateless, 10-60s timeout)
    Lambda->>DB: Write Test Results (Pass/Fail/TLE)
    deactivate Lambda
    APIServer-->>User: Poll / Stream Evaluation Status
  • Access Pattern: Highly volatile and bursty. Thousands of submissions arrive during weekend contests, while mid-week traffic at 3 AM drops near zero.
  • Execution Lifecycle: Strictly time-bound (e.g., 2-second timeout per test case).
  • Advantage: Each submission runs in a clean, stateless sandbox. The platform handles concurrent contest traffic by scaling out execution instances automatically, without risk of one submission exhausting compute resources for another.

Use Case 3: Distributed IoT and Vending Machine Telemetry

Imagine an enterprise managing thousands of automated vending machines globally. Each time a product is dispensed, inventory must be updated in a central data store to signal restocking requirements.

  • Access Pattern: Discrete, low-frequency events per physical device. A single vending machine might process a transaction only 5 to 30 times a day.
  • Advantage: Instead of running heavy central ingress clusters, each vending machine makes an authenticated API call directly to a serverless endpoint. Compute instances spin up only during active purchases, keeping inventory pipelines lean and resilient across geo-distributed locations.

Use Case 4: Automated Scheduled Tasks and Cron Jobs

Database snapshots, log rotations, and cache warmups often need to execute on a schedule (e.g., trigger an RDS backup snapshot every day at 4:00 PM).

  • Inefficient Approach: Running a dedicated VM solely to maintain a crontab. If the VM crashes, the cron fails silently. Running multiple VMs introduces race conditions and duplicate task execution unless distributed locks are used.
  • Serverless Approach: Cloud schedulers (e.g., AWS EventBridge / CloudWatch Events) trigger a serverless function on a cron schedule. The function runs for 100 milliseconds to call the backup API and terminates. Reliability and scheduling are guaranteed by the cloud vendor.

Use Case 5: Reactive Batch and Stream Processing

In decoupled asynchronous architectures, systems push messages to brokers like AWS SQS or RabbitMQ.

flowchart LR
    Producer[Ingress Producer] -->|Enqueue Message| SQS[(Message Queue / SQS)]
    SQS -.->|Event Trigger| Lambda[Serverless Consumer]
    subgraph AutoScaling Group of Functions
        Lambda
        Lambda2[Lambda Instance 2]
        Lambda3[Lambda Instance N]
    end
    Lambda --> DB[(Target Store)]
    Lambda2 --> DB
    Lambda3 --> DB
  • Traditional Polling: Consumer instances must run 24/7, continuously long-polling the queue for incoming messages, burning CPU cycles even when queues are dry.
  • Reactive Serverless: Modern cloud platforms natively bind message queues to serverless runtimes. When a message lands in the queue, the platform triggers the function immediately, passing the message payload. As queue depth increases, the platform spins up concurrent functions to clear the backlog, scaling back down to zero when empty.

3. Advantages of Serverless Computing

  1. Zero Infrastructure & OS Management: Eliminates the operational overhead of kernel patching, security compliance upgrades, AMI baking, and manual server replacement.
  2. Precise Pay-as-You-Go Billing: Billing tracks compute time down to the millisecond. For lightweight APIs and sporadic traffic, infrastructure costs can drop to negligible amounts (often mere fractions of a dollar per month).
  3. Automated, Elastic Capacity Scaling: Removes human error from auto-scaling policies. The platform manages horizontal scaling dynamically during unexpected traffic spikes.

4. Key Limitations and Disadvantages

Despite its advantages, serverless introduces distinct architectural challenges.

1. The Cold Start Problem

When a function has not received traffic for a period, the cloud provider deprovisions its underlying container to reclaim resources. When a new request arrives, the provider must allocate a microVM/container, download the code artifact, initialize the runtime (JVM, Node.js, Python), and execute global initialization code.

  • Impact on Latency: An execution that normally takes 150ms might experience a 1 to 2-second latency spike on a cold start.
  • Implication: Workloads with strict, low-latency Service Level Agreements (SLAs) or sub-millisecond requirements cannot tolerate cold start penalties.

2. Execution Duration Limits

Serverless runtimes enforce hard timeout ceilings (e.g., AWS Lambda terminates any function running beyond 15 minutes).

  • Workloads such as heavy distributed MapReduce jobs, long video transcodes, or long-running database migrations cannot run inside a single serverless function without being fundamentally re-architected into modular, step-driven pipelines.

3. Local Testing and Debugging Friction

  • Emulating complete cloud-native ecosystems (event buses, permissions, IAM roles, managed databases) locally is difficult.
  • Distributed traces, aggregated logs (e.g., CloudWatch), and ephemeral debug environments create higher operational friction compared to stepping through code in a traditional monolithic server.

4. Vendor Lock-In

Functions are often tightly coupled to cloud-specific interfaces, context objects, and proprietary SDKs (e.g., writing explicitly for AWS Lambda and its S3 event formats). Migrating functions across cloud providers (e.g., moving from AWS to Cloudflare Workers or GCP) often demands code restructuring, pipeline re-writes, and IAM overhauls.


5. Decision Matrix: When to Use vs. When NOT to Use

CriteriaAdopt ServerlessStick to Provisioned Servers (EC2, ECS, K8s)
Traffic PatternHighly erratic, bursty, or unpredictable with idle intervalsSteady, sustained, and highly predictable baseline
Cost ProfileCheaper for intermittent / low-volume executionCheaper per request at sustained high volumes (e.g., constant 5,000+ RPS)
Process LifecycleShort-lived, ephemeral, event-driven (< 15 mins)Long-running daemon processes, batch analytics, continuous streams
Latency SLAsCan tolerate occasional cold-start spikesDemands predictable, ultra-low p99 latency guarantees
Isolation NeedsStandard shared infrastructure tenancy is acceptableDedicated bare-metal or single-tenant hardware isolation required
Team VelocitySmall teams focusing purely on business logic / rapid prototypingLarge infrastructure teams with mature container orchestration systems

Final Thought

Serverless is not a universal replacement for provisioned infrastructure. It is a targeted architectural tool. Adopting it for spiky, event-driven, or lightweight utility tasks can drastically reduce maintenance overhead and cost. Conversely, applying it to high-throughput, sustained, or long-running computations leads to inflated bills and architectural roadblocks. Always design your compute strategy around your workload’s specific traffic profile and latency constraints.

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses