Chapter 9
Serverless and Managed Application Platforms
Diploma in DevOps
Cloud Deployment Basics (AWS/GCP)
•
Diploma
Serverless and Managed Application Platforms
Introduction and Context
Cloud deployment has moved beyond the simple provisioning of virtual machines. Modern teams can deploy code while delegating much of the operating-system, runtime, scaling, patching, and availability work to a cloud provider. Two important families of services support this approach:
Serverless functions, such as AWS Lambda and Google Cloud Functions, which execute short-lived code in response to events.
Managed application platforms, such as AWS App Runner, AWS Elastic Beanstalk, and Google Cloud Run, which run complete web services or containers without requiring the development team to manage servers directly.
These services do not mean that servers disappear. Servers, networks, operating systems, and schedulers still exist in the provider’s infrastructure. “Serverless” means that server administration and capacity management are abstracted from the customer, usually with usage-based pricing and automatic scaling.
The central engineering decision is not whether one platform is universally superior. It is whether the workload’s execution model, latency requirements, state, traffic pattern, operational controls, and portability needs match the platform selected.
Learning Objectives
By the end of this chapter, a learner should be able to:
explain the architecture and execution model of serverless functions;
deploy an event-driven application using Lambda or Cloud Functions;
distinguish App Runner, Elastic Beanstalk, and Cloud Run;
design triggers, permissions, configuration, and failure handling;
evaluate scaling, concurrency, observability, quotas, and cost factors;
identify security, governance, and vendor-lock-in risks; and
recommend an appropriate platform for a practical application.
1. Core Concepts and Terminology
1.1 Event-driven computing
An event is a record that indicates that something has happened. Examples include an HTTP request, an object uploaded to storage, a message published to a queue, a scheduled time, or a database change. An event-driven application reacts to such records rather than continuously polling every possible source.
A typical flow is:
Event source → routing or trigger → compute handler → output service
For example, an object-storage event may invoke a function that validates an uploaded image and writes a resized version to another storage location.
The event payload should be treated as an input contract. It commonly contains an event type, source, time, resource identifier, and data specific to the source. Robust handlers validate this structure rather than assuming that every event is well formed.
1.2 Function as a Service
Function as a Service (FaaS) provides a managed execution environment for individual functions. A function normally has:
source code and dependencies;
a runtime such as Python, JavaScript, Java, or Go;
a handler or entry point;
memory and timeout configuration;
an execution identity; and
event or HTTP triggers.
The platform starts an execution environment, runs the handler, and may reuse the environment for later requests. Reuse can improve performance because dependencies may remain loaded, but it must not be relied upon for correctness.
A function should therefore be designed to be stateless and repeatable. Persistent state belongs in a database, object store, cache, or queue rather than in local temporary storage or global variables.
1.3 Managed application platforms
A managed application platform is a higher-level service for deploying an application or container. It usually manages infrastructure provisioning, load balancing, health checks, deployment mechanisms, and some scaling operations while exposing more application structure than a single function.
AWS App Runner deploys source code or a container image as an internet-facing service and manages the underlying service infrastructure.
AWS Elastic Beanstalk deploys applications onto supported environments, such as web servers or workers, while AWS manages much of the environment provisioning. It provides more traditional application-server control than App Runner.
Google Cloud Run runs stateless HTTP containers and scales revisions according to incoming requests or events. It is particularly useful when an application already has a container image.
1.4 Cold start and warm execution
A cold start occurs when a provider must create or initialize an execution environment before handling a request. Initialization includes loading the runtime, application code, and dependencies. A warm invocation reuses an already initialized environment.
Cold starts are affected by runtime, package size, initialization work, network configuration, and provider configuration. They are not necessarily defects, but they matter for interactive systems with strict latency requirements.
1.5 Concurrency and idempotency
Concurrency is the number of requests or events being processed simultaneously. A function may use one execution environment per concurrent request, subject to provider and account limits. A container service may allow multiple requests per container, depending on configuration.
An idempotent operation produces the same intended result when the same event is processed more than once. Idempotency is essential because retries, duplicate delivery, client retransmission, and partial failures are normal in distributed systems.
A common technique is to store an event identifier or business transaction key in a durable data store. Before applying a side effect, the application checks whether that key has already been processed.
2. Serverless Function Architecture
2.1 Invocation models
Functions are commonly invoked in three ways:
Invocation model
Typical source
Application concern
Synchronous
HTTP request or API gateway
Caller expects a response and experiences latency
Asynchronous
Storage event or notification
Provider may retry; caller does not wait for completion
Poll-based
Queue or stream
The platform reads records and invokes a handler
The invocation model influences error handling. A synchronous handler should return an appropriate status code and bounded response time. An asynchronous handler should record failures and use retry or dead-letter mechanisms. A queue consumer should acknowledge a message only after successful processing.
2.2 AWS Lambda and Google Cloud Functions
AWS Lambda functions are associated with an execution role, runtime configuration, memory allocation, timeout, and trigger. Lambda can be invoked by services such as API Gateway, Amazon S3, EventBridge, and SQS.
Google Cloud Functions, including the current Cloud Functions generations, integrate with services such as Cloud Storage, Pub/Sub, Eventarc, and HTTP endpoints. They use a service account identity and Google Cloud IAM permissions.
The conceptual workflow is similar in both clouds:
create or package the function;
select a runtime and entry point;
assign a least-privilege execution identity;
configure environment variables and resource limits;
attach a trigger;
test with representative events;
inspect logs, metrics, and failed deliveries; and
release through a repeatable deployment pipeline.
Exact commands, supported runtimes, quotas, and pricing change over time. Production work should therefore consult the current provider documentation rather than relying on memorized limits.
Event-driven serverless processing flow
Figure: Event-driven serverless processing flow
Figure: A serverless event flow with a controlled failure path.
2.3 Reliable function design
A production function should:
validate the event schema and required fields;
set explicit timeouts and avoid unbounded loops;
use structured logs containing correlation and business identifiers;
handle transient errors with bounded retries and backoff;
separate retryable errors from permanent validation errors;
protect downstream systems from sudden concurrency spikes;
keep initialization outside the handler only when reuse is safe; and
avoid embedding secrets in source code or environment files.
Retries can be harmful if an operation is not idempotent. For example, retrying a payment charge without an idempotency key may produce duplicate charges. A dead-letter queue or failure destination provides a place to inspect events that cannot be processed successfully.
3. Managed Application Platforms
3.1 Choosing the abstraction level
The platforms differ primarily in the unit of deployment and the degree of control.
Service
Main deployment unit
Best fit
Important trade-off
Lambda
Function
Short event handlers and APIs
Runtime, duration, and event-model limits
Cloud Functions
Function
Google Cloud event integrations
Function-oriented operational model
App Runner
Web service or container
Straightforward HTTP services
Less infrastructure control than a cluster
Elastic Beanstalk
Application environment
Conventional web applications and workers
More environment concepts and operational surface
Cloud Run
Stateless container revision
Portable HTTP containers and services
Application must obey container and statelessness requirements
3.2 AWS App Runner
App Runner accepts source code or a container image and deploys it as a managed web service. It is suitable for an API or web application that listens on a port and can be built using a supported workflow. The service can provide a public endpoint, TLS integration, health checks, deployment configuration, and automatic scaling.
App Runner is attractive when a team wants more than a function but does not want to design an orchestration cluster. Its limitations include reduced control over low-level networking and scheduling compared with a self-managed platform. Teams must also understand startup time, instance limits, outbound connectivity, secrets, and the difference between application health and process health.
3.3 AWS Elastic Beanstalk
Elastic Beanstalk creates and manages an application environment using AWS resources such as compute instances, load balancing, and scaling groups. It supports familiar application stacks and deployment policies. It is often appropriate when an organization has a conventional web application and wants platform automation without managing every infrastructure resource manually.
Compared with App Runner, Beanstalk exposes more environment-level configuration and can therefore support more traditional operational patterns. That flexibility also creates more configuration drift, patching responsibility, and diagnostic complexity. Teams should manage Beanstalk settings as code and establish ownership for the underlying resources.
3.4 Google Cloud Run
Cloud Run executes container images as stateless HTTP services. A deployment creates a revision; traffic can be directed to a revision, split between revisions, or rolled back. Cloud Run can scale instances down when demand falls and can support request concurrency per instance.
A Cloud Run container should listen on the port supplied by the platform, start reliably, and avoid dependence on local durable storage. Long-running background work should be represented by a suitable queue or job design rather than hidden inside a request whose lifetime may end.
Cloud Run is a strong option when portability matters because the core application artifact is a standard container image. Portability is not complete: IAM, logging, identity, networking, deployment, and managed database integrations remain provider-specific.
4. Scaling, Capacity, and Limits
4.1 Scaling behavior
Serverless scaling is elastic but bounded. A platform may create more function environments or service instances as demand increases, subject to account, region, concurrency, and downstream limits. Scaling is not instantaneous and does not guarantee that every burst is absorbed without delay.
For a queue consumer, increasing concurrency can reduce backlog but may overload a database. Therefore, scaling must be evaluated as a system property rather than a compute-only property.
A useful capacity relationship is Little’s Law:
L = λW
Here, L is the average number of items in a stable system, λ is the average arrival rate in items per second, and W is the average time an item spends in the system in seconds. The units are consistent because items/second × seconds = items. The relationship assumes a stable long-run system and is useful for reasoning about queues, in-flight requests, and concurrency; it does not by itself guarantee a particular latency or error rate.
For example, if a service receives 40 requests per second and the average response time is 0.25 seconds, the average number of in-flight requests is:
L = 40 × 0.25 = 10 requests.
This is an average, not a maximum. Bursts, variance, retries, and cold starts require additional capacity analysis.
4.2 Important limits
A design must identify at least the following limits:
maximum function duration;
memory and temporary storage;
package or image size;
maximum request and response payload;
concurrency per function or service;
regional and account-level instance quotas;
deployment frequency and artifact limits;
connection limits of databases and APIs; and
log ingestion, retention, and monitoring quotas.
Provider limits may be hard limits, adjustable quotas, or practical limits imposed by cost and downstream capacity. Quotas should be monitored and tested in the target region.
4.3 Cost reasoning
Serverless pricing commonly depends on requests, execution duration, allocated memory or compute, data transfer, and related managed services. A simplified function-duration estimate is:
Cexec ≈ N × t × p
where N is the number of invocations, t is billable execution time per invocation in the provider’s billing unit, and p is the price per unit. This is only an estimate: real bills may include request charges, free tiers, architecture-specific rates, rounding rules, concurrency features, network transfer, logs, and downstream services.
Cost should be evaluated with workload measurements, not only list prices. A low per-request price can be outweighed by excessive logging, inefficient initialization, database connections, or cross-region data transfer.
5. Observability and Operations
Observability combines logs, metrics, traces, and useful context.
Logs should be structured and should include timestamp, severity, service, revision or function version, correlation identifier, and a safe business key. Sensitive data such as passwords, access tokens, and unnecessary personal data must not be logged.
Metrics should include request count, duration, error rate, throttling, concurrency, cold-start indicators where available, queue age, and downstream failures. Percentiles are more informative than averages for latency. The 95th percentile, for example, is the value below which approximately 95% of observations fall; it does not describe the slowest 5% precisely.
Distributed tracing links work across an API, function, queue, and database. Trace identifiers should be propagated across asynchronous boundaries when the platform supports it.
A useful service-level objective might specify availability and latency, such as “99.9% of valid requests succeed within 500 ms over a calendar month.” The measurement window, exclusions, sampling method, and treatment of provider errors must be documented. An objective is not the same as a provider guarantee.
6. Security, Governance, and Compliance
The shared-responsibility model remains applicable. The provider protects its infrastructure, while the customer remains responsible for code, identities, configuration, data, and access decisions.
Best practices include:
use least-privilege IAM roles and service accounts;
separate development, test, and production accounts or projects;
store secrets in a managed secret service;
encrypt data in transit and at rest;
restrict public endpoints and use authentication where required;
validate and size-limit incoming events;
scan dependencies and container images;
control outbound network access where sensitive data is involved;
define retention and deletion policies for logs and events; and
record deployment approvals and configuration changes.
Serverless does not remove regulatory duties. Personal data may be exposed through logs, event payloads, backups, or cross-border processing. Data classification should occur before selecting regions, services, and retention periods.
7. Vendor Lock-In and Portability
Vendor lock-in is the increasing cost or difficulty of changing provider, service, or architecture. It has several dimensions:
API lock-in: code depends on provider-specific event schemas or SDKs;
data lock-in: data uses proprietary formats or managed databases;
operational lock-in: monitoring, IAM, deployment, and incident procedures are provider-specific;
economic lock-in: migration becomes expensive because of traffic, contracts, or specialized services; and
skills lock-in: only a small team understands the platform.
Portability is not binary. A Cloud Run container may be portable at the application-runtime level while its identity and event integration are not. A Lambda handler can be made more portable by separating business logic from the adapter that converts a provider event into an internal command.
Practical mitigation includes:
define internal domain events and isolate provider adapters;
use containers or standard protocols where they provide real value;
export data in documented formats and test restoration;
use infrastructure as code;
maintain deployment and rollback documentation;
avoid unnecessary use of proprietary features; and
perform an exit exercise for critical workloads.
Avoiding every managed feature is not automatically wise. A proprietary queue or database may provide substantial reliability and productivity. The decision should compare the value gained with the cost and probability of migration.
8. Worked Deployment Pattern
Consider an image-processing service. A user uploads an image to object storage. The storage event invokes a function. The function validates the object type, places a processing command on a queue, and returns. A container service consumes commands through an HTTP or pull-based worker interface, performs CPU-intensive transformation, stores the result, and records status in a database.
This decomposition separates a short event handler from a potentially slower processing workload. The queue absorbs bursts and permits controlled worker concurrency. The function must use an idempotency key based on the object identifier and version. The worker must write results atomically or use a processing-state record so that retries do not create conflicting outputs.
A deployment pipeline should:
lint and unit-test the handler and worker;
scan dependencies and the container image;
deploy to a non-production environment;
send a synthetic event;
verify output, logs, metrics, and failure routing;
perform a controlled production rollout; and
retain the previous function version or container revision for rollback.
9. Illustrative Case Study: Regional Notification Service
Background
A fictional retailer, Northstar Supplies, sends order-confirmation notifications. Its existing application runs on virtual machines and experiences sharp traffic increases during promotions.
Problem
The team wants automatic scaling and lower operational effort, but notifications must not be duplicated. The email provider also limits requests per second.
Analysis
A synchronous function directly calling the email provider would be simple, but promotional bursts could create excessive concurrent calls. A queue is therefore required. The notification request should contain an order identifier, recipient, template, and idempotency key. The email provider’s response and retry policy must be recorded.
Approach
An order event is published to a queue. A Lambda or Cloud Function consumes messages with a deliberately limited concurrency. Each invocation checks a durable notification record. If the order has already been sent, it acknowledges the message without sending again. Transient provider errors cause bounded retries. Permanent address or template errors are routed to a dead-letter queue. A dashboard tracks queue age, delivery success, retry count, and provider throttling.
If the notification logic later becomes a larger HTTP service, the team could package it as a container and deploy it to Cloud Run or App Runner. Elastic Beanstalk would be reasonable if the organization already operates conventional AWS application environments and requires their configuration model.
Outcome
The architecture absorbs bursts through the queue, protects the email provider through controlled concurrency, and supports replay from failed messages. It introduces additional components and operational responsibilities, including queue monitoring, idempotency storage, and dead-letter review.
Learning Points
The case demonstrates that automatic compute scaling does not remove downstream capacity limits. Reliability comes from the complete flow—durable messaging, idempotency, bounded retries, observability, and operational ownership—not merely from selecting a serverless product.
10. Best-Practice Decision Framework
Use the following questions when selecting a platform:
Is the workload naturally event-driven, or is it a continuously running web service?
What are the maximum duration, memory, payload, startup-latency, and concurrency requirements?
Does the application already have a container image?
Which downstream systems limit throughput?
Which identity, network, data-residency, and compliance controls are required?
How will failures, retries, duplicate events, and poison messages be handled?
What logs, metrics, traces, alerts, and runbooks are needed?
What is the estimated total cost at normal and peak load?
Which provider-specific features create useful value, and which create avoidable dependency?
Can the service be deployed, tested, rolled back, and recovered by another qualified engineer?
A sound design begins with workload characteristics and failure modes, not with product popularity.
Contemporary Developments
Managed platforms increasingly support revisions, gradual traffic shifting, event routers, container-based functions, managed asynchronous jobs, and stronger supply-chain security. Platform engineering teams are also creating internal deployment templates that standardize identity, logging, networking, and policy controls.
AI services can be integrated as event-driven components, but their latency, token cost, data handling, nondeterministic output, and provider-specific APIs require additional governance. An AI invocation should have bounded cost and time, logged model and prompt metadata where permissible, and a fallback path for provider or model failure. AI does not alter the fundamental requirements for idempotency, least privilege, observability, and data protection.
Chapter Summary
Serverless functions execute code in response to events and are well suited to short, stateless, independently scalable tasks. Lambda and Cloud Functions provide similar conceptual capabilities but differ in APIs, identities, event schemas, quotas, and integrations. App Runner, Elastic Beanstalk, and Cloud Run provide progressively different managed application abstractions: simplified web services, conventional managed environments, and container-based services.
Successful deployments account for invocation type, retries, idempotency, cold starts, concurrency, quotas, downstream capacity, cost, and observability. Metrics, structured logs, traces, and failure destinations make managed systems operable. Security remains a customer responsibility, especially identity, secrets, data protection, and configuration. Finally, portability should be assessed as a set of technical, operational, data, economic, and skills dependencies rather than as a simple choice between “portable” and “locked in.”
Key Terms
Event: A record describing something that has happened.
Event-driven architecture: A design in which components communicate and react through events.
Function as a Service: Managed execution of individual functions without customer-managed servers.
Handler: The function entry point that receives an event and performs processing.
Cold start: Initialization delay when a new execution environment is created.
Warm invocation: Execution using an already initialized environment.
Concurrency: The number of operations processed simultaneously.
Idempotency: The property that repeated processing produces one intended effective result.
Dead-letter queue: A destination for messages that cannot be successfully processed.
Retry: A repeated attempt after a failure, usually governed by a policy.
Managed application platform: A service that operates deployment infrastructure while exposing an application-level interface.
Revision: A versioned deployment of an application or container service.
Quota: A provider-imposed resource or usage boundary.
Observability: The ability to understand system behavior through logs, metrics, and traces.
Least privilege: Granting only the permissions required for an identity’s task.
Vendor lock-in: Dependence that makes changing provider or service costly or difficult.
Little’s Law: The stable-system relationship L = λW between average items, arrival rate, and time in system.
Shared responsibility model: Division of security responsibilities between cloud provider and customer.
Review Questions
Short Answer Questions
What is the difference between synchronous and asynchronous function invocation?
Why should serverless functions generally be stateless?
Define a cold start and identify two factors that influence it.
What is the purpose of a dead-letter queue?
Name two dimensions of vendor lock-in.
Long Answer Questions
Compare AWS Lambda, Google Cloud Functions, AWS App Runner, Elastic Beanstalk, and Cloud Run in terms of deployment unit, control, and suitable workload.
Explain how retries, idempotency, and durable state work together in an event-driven application.
Discuss the observability requirements of a production serverless service.
Explain why automatic scaling does not eliminate the need for capacity planning.
Describe security and governance practices for a managed application platform.
Analytical / Application Questions
A queue consumer receives bursts that exceed the database’s write capacity. Propose a scaling and back-pressure design, including monitoring signals.
A team wants to migrate a Lambda application to Cloud Run. Identify the likely portability issues and propose a migration sequence.
Select a platform for a CPU-intensive image-processing API with an existing container image, variable traffic, and a requirement for gradual rollbacks. Justify the selection and identify two risks.
Multiple Choice Questions with Answers
Question 1
Which invocation model requires the caller to wait for the function response?
A. Synchronous invocation
B. Asynchronous invocation
C. Dead-letter invocation
D. Batch archival invocation
Correct Answer: A. Synchronous invocation
Question 2
What is the primary purpose of idempotency in an event-driven system?
A. To increase the memory allocation of a function
B. To ensure repeated processing does not create unintended duplicate effects
C. To eliminate all network latency
D. To make every event arrive in order
Correct Answer: B. To ensure repeated processing does not create unintended duplicate effects
Question 3
Which platform is primarily designed to run stateless HTTP container images?
A. AWS Lambda
B. AWS Elastic Beanstalk
C. Google Cloud Run
D. Amazon S3
Correct Answer: C. Google Cloud Run
Question 4
According to Little’s Law, if the arrival rate is 40 requests per second and average time in the system is 0.25 seconds, what is the average number of in-flight requests?
A. 4
B. 10
C. 40
D. 160
Correct Answer: B. 10
Question 5
Which component is most appropriate for retaining messages that repeatedly fail processing?
A. Dead-letter queue
B. Cold-start cache
C. Container image registry
D. DNS resolver
Correct Answer: A. Dead-letter queue
Question 6
Which practice best follows the principle of least privilege?
A. Giving every function administrator access
B. Sharing one credential across all environments
C. Granting an execution identity only the permissions needed for its task
D. Embedding cloud access keys in source code
Correct Answer: C. Granting an execution identity only the permissions needed for its task
Question 7
What is a cold start?
A. A failed database backup
B. The initialization of a new execution environment before processing a request
C. A queue message that has expired
D. A container image stored in a cold region
Correct Answer: B. The initialization of a new execution environment before processing a request
Question 8
Which statement about automatic scaling is correct?
A. It removes all downstream capacity limits
B. It guarantees zero latency during traffic bursts
C. It remains bounded by quotas and can overload dependent systems
D. It makes observability unnecessary
Correct Answer: C. It remains bounded by quotas and can overload dependent systems
Question 9
Which measure most directly reduces duplicate email notifications after retries?
A. Increasing log verbosity only
B. Using a durable idempotency key and processing record
C. Removing all retry policies
D. Increasing the container image size
Correct Answer: B. Using a durable idempotency key and processing record
Question 10
Which is an example of operational vendor lock-in?
A. Using a documented HTTP protocol
B. Using a provider-specific IAM, monitoring, and deployment workflow
C. Writing unit tests for business logic
D. Storing source code in a version-control system
Correct Answer: B. Using a provider-specific IAM, monitoring, and deployment workflow