Skip to main content

Lesson 5: Serverless Compute Concepts

Core Principle: Functions as Ephemeral Compute Units​

Serverless compute is built around short-lived, stateless function invocations. Your architecture needs to assume:

  • Each invocation is isolated
  • Capacity scales automatically
  • State is externalized
  • Execution time is bounded by platform limits

Simple Explanation​

What it is​

Serverless compute is short-lived, on-demand execution. A function spins up, does its job, and then disappears. You are not running a server that stays on all day.

Why we need it​

It matches modern workloads that are bursty and unpredictable. Instead of paying for idle servers, you pay for the exact moments your code runs.

Benefits​

  • Fast scaling when traffic spikes.
  • Lower idle costs because compute turns off automatically.
  • Smaller units of code that are easier to reason about and deploy.

Tradeoffs​

  • Cold starts can slow the first request after idle time.
  • Long-running tasks often require different compute models.
  • Retries and timeouts must be handled carefully.

Real-world examples (architecture only)​

  • Webhook event → Function → Update database.
  • Queue message → Function → Process batch item.
  • Timer → Function → Nightly report.

Key Topics (Outline)​

  • Function lifecycle: Initialization, execution, termination
  • Concurrency vs parallelism in serverless
  • Cold starts: Impact on architecture and SLAs
  • Provisioned concurrency: Cost and performance trade-offs
  • Memory allocation and CPU proportionality
  • Execution timeouts and long-running tasks
  • Function versioning and aliases
  • Comparison: AWS Lambda runtime model vs Google Cloud Functions runtime model

Python Example: Function Lifecycle (Conceptual)​

def handler(event, context):
# Init: load dependencies (cold start cost lives here)
# Invoke: handle event
result = process_event(event)
# End: return response
return result

What this does: Highlights where cold-start overhead happens (dependency loading) and where your business logic executes.


Project (Cloud-Agnostic)​

Design a function that processes events in under the platform time limit and documents its cold-start risks.

Deliverables:

  1. Describe the event source and expected load.
  2. Explain how you will keep execution time bounded.
  3. List tactics to reduce cold-start impact.

If you want feedback, email your write-up to maarifaarchitect@gmail.com.


References​