One Pager Cheat Sheet
- Serverless computing is a cloud execution model in which you deploy
functions or small services
without managing servers, letting the platform handleprovisioning, scaling, and patching
, and paying based on per execution time and resources used. - In serverless architectures, FaaS (Functions as a Service) involves uploading functions that run on demand, while BaaS (Backend as a Service) allows consumption of managed backends via APIs without running them yourself, often mixed together for serverless applications.
- Serverless pricing is characterized by paying for execution time and resources used, with charges per
invocation
,compute time
,resource allocation
, andoperations performed
, leading to a consumption-based model that minimizes idle costs but directly ties total cost to actual usage patterns and resource choices. - Key Properties (What You Get) include
Automatic scaling
to thousands of concurrent executions,No server management
with OS/security patching handled by the provider,Event-driven
functions triggered by various events, andGranular billing
perms
and memory/CPU allocation, while important constraints include functions beingstateless
, havingexecution time limits
,ephemeral filesystems
, and potentially sufferingcold starts
. - Definitions of
Cold start
,Warm start
,Provisioned concurrency
/min instances
, andStateless
in the context of serverless computing. - Node.js is used to create a serverless HTTP response by exporting a
handler(event, context)
function that takes event and context inputs and provides a response. - Serverless platforms require stateless functions that do not depend on in-memory variables due to the lack of guarantees about invocation reuse, emphasizing the use of external, durable state stores for shared or persistent data.
- Common Triggers (Events) include HTTP gateways for functions, Object storage events like file uploads for processing and resizing, Queue/stream mechanisms for async jobs, Schedulers for periodic tasks, and DB change streams for reactive workflows.
- Serverless HTTP functions follow the sequence of parsing the HTTP request to create an event, allocating or waking the runtime, executing the handler with the event and context, and serializing the handler result into an HTTP response to ensure proper functionality and communication with clients.
- Image Thumbnail Worker Implementation is a sample scenario where a serverless storage-triggered function processes files by simulating resizing through byte truncation, showcasing the effectiveness of serverless architecture for event-driven jobs like file processing.
- The serverless backend architecture uses Glue to connect HTTP/API, business logic, async tasks, scheduled jobs, and authentication/authorization services managed by BaaS providers.
- The correct phrase is
provisioned concurrency
, where a set amount of ready execution environments are pre-allocated to reducecold starts
and improve latency in serverless platforms. - Use serverless computing when dealing with spiky or unpredictable traffic, event processing pipelines, APIs with modest latency needs, prototypes/MVPs, and teams without ops bandwidth, but it may not be ideal for long-running jobs beyond platform time limits, extremely low-latency high and constant throughput, and heavy reliance on local state or custom OS dependencies.
- Stateless execution means an invocation cannot rely on any durable, instance-local memory or filesystem, requiring the function to encode all needed state in inputs or external stores for work to continue correctly across invocations, crashes, and scaled instances.
- Serverless computing charges are based on the formula duration × memory/CPU setting × invocations, which can be compared to the cost of running a small VM 24/7 or a function that runs
only on requests
. - Simple Router Function is an example of a function that can handle multiple paths using standard lib parsing.
- Observability in serverless environments includes structured logging with request IDs and durations, metrics for invocations and errors, tracing across functions and calls, and dead-letter queues to capture failed events for reprocessing.
- Serverless platforms autoscale compute, but rate limiting is still necessary due to fixed capacity of downstream systems, potential for amplified failures and costs with autoscaling, limits and throttles imposed by cloud providers and accounts, importance of security and abuse prevention, potential impact on latency and user experience, and risks of retries and retry storms; common mitigation techniques include edge throttling, per-user or per-API-key limits, reserved/provisioned concurrency limits, queuing/backpressure with SQS or Kinesis, circuit breaker and exponential backoff, and monitoring metrics.
- Patterns for State & Performance include utilizing
idempotency keys
for event retries, caching config/metadata in memory per container, prioritizingsmall bundles
to decrease cold start time, and consideringprovisioned concurrency
or edge runtimes for hot paths. - Security Basics include implementing the principle of least privilege, using managed secret stores for secrets instead of env-hardcoding, validating all inputs including those from internal events, and minimizing dependencies to reduce attack surface.
- Idempotency ensures that an operation can be safely run multiple times without changing the result beyond the initial application, preventing duplicates from corrupting state.
- Handlers should be written as pure functions so they can be tested locally with fixture events, validated using JSON schemas, and emulated with small drivers for schedules and queues.
- Event-driven, short-lived, highly parallelizable, and bursty workloads are well-suited for serverless platforms due to their automatic scaling, pay-per-use billing, and seamless integration with managed event sources/storage, offering cost efficiency and parallel processing capabilities.
- Serverless at the Edge involves running functions close to users in edge POPs using lightweight runtimes, such as V8 isolates and WebWorkers-style, offering benefits like low latency and fast cold starts but with constraints like limited CPU time and restricted APIs.