AWS Systems Architect Professional

AWS Serverless Architecture Patterns – SAP-C02 Study Guide

Study AWS serverless architecture patterns for SAP-C02, including SQS decoupling, Lambda scaling, API Gateway, Step Functions, and S3 events.

AWS Systems Architect ProfessionalAWS Systems Architect ProfessionalUpdated Sep 1, 2026
Study options
WatchComing later
ListenComing later
ReadAvailable
ReviewComing later

Study guide

Technical reference and lesson notes

Purpose of This Lesson

This lesson focuses on recognizing common serverless architecture patterns and selecting AWS services based on workload behavior, scaling requirements, ordering constraints, execution limits, and global latency needs.

Key Concepts

Decoupling workloads with Amazon SQS

When one application tier produces work faster than another tier can process it, a direct synchronous connection can cause failures or dropped writes. Amazon SQS provides a durable buffer between the tiers.

A common pattern is:

  1. A web or application tier places work items in an SQS queue.
  2. Consumers retrieve messages from the queue.
  3. The work is processed asynchronously by Lambda or EC2 instances.
  4. Failed processing can be retried, and messages can be moved to a dead-letter queue after repeated failures.

This pattern absorbs traffic spikes and allows producers and consumers to scale independently.

For EC2-based consumers, Auto Scaling can use the approximate number of messages visible in the queue as a scaling signal. A growing backlog indicates that more processing capacity is required.

Standard queues versus FIFO queues

Use an SQS FIFO queue when messages must be processed in the order they were sent. FIFO queues are appropriate for workflows such as order processing where sequence is part of the business requirement.

A standard queue provides very high scalability but does not guarantee strict ordering. If ordering is required, select FIFO and design consumers to preserve the required message-group ordering.

Lambda memory affects CPU allocation

Lambda allocates CPU power in proportion to the configured memory. Increasing memory can therefore reduce execution time for CPU-bound or data-processing workloads, even if the function does not need additional memory for its data.

Lambda pricing is based on invocation duration and configured memory. The correct setting should be validated with testing rather than assuming that the lowest memory configuration is cheapest.

API Gateway and Lambda for unpredictable demand

For a REST API with unpredictable traffic, Amazon API Gateway integrated with AWS Lambda provides a managed, automatically scaling front end and compute layer. Lambda can then access a backend such as Amazon RDS.

A production design should also consider database connection management, connection limits, authentication, throttling, caching, and whether Amazon RDS Proxy is needed for high-concurrency Lambda workloads.

Lambda for variable image processing

A variable-volume image-processing workload that currently uses EC2 may be a good candidate for Lambda when:

  • Processing is event-driven.
  • Each image can be handled independently.
  • The code and dependencies fit Lambda limits.
  • A single invocation does not exceed the maximum Lambda timeout of 15 minutes.
  • The workload does not require persistent local state or specialized host configuration.

S3 can trigger Lambda when new objects are created. Event filtering can restrict processing to a particular prefix or suffix, such as only objects in uploads/ or only files ending in .jpg.

Step Functions for multi-step workflows

AWS Step Functions is useful when a legacy chain of scripts has multiple stages, branching, retries, error handling, or dependencies between steps. Lambda functions can implement individual processing tasks while Step Functions coordinates execution.

This is generally easier to operate and modify than embedding control flow across many scripts. Step Functions can also provide workflow visibility and explicit retry and failure handling.

Regional and edge-optimized API Gateway endpoints

A Regional API Gateway endpoint is accessed through the AWS Region hosting the API. It can be suitable when clients are concentrated near that Region or when another content-delivery or global routing design is used.

An edge-optimized API uses the CloudFront edge network to reduce latency for globally distributed clients. Converting a Regional API to an edge-optimized API can improve access performance when the API has suddenly acquired a global user base.

The endpoint type should be selected based on client geography, routing requirements, security controls, and whether the organization already uses CloudFront or another global acceleration layer.

Lambda concurrency and throttling

Lambda limits the number of concurrent executions. If API Gateway receives more requests than Lambda can execute within its available concurrency, requests may be throttled or fail while capacity is constrained.

When the function itself shows no application errors, investigate service-side throttling and concurrency limits, including:

  • Account or Region concurrency quotas.
  • Function reserved concurrency.
  • Provisioned concurrency configuration.
  • API Gateway throttling limits.
  • Downstream service capacity.

The appropriate fix may be to request a quota increase, adjust reserved concurrency, tune API Gateway throttling, or reduce pressure on a constrained dependency. Simply increasing a limit without checking the database or downstream systems can move the bottleneck elsewhere.

Architecture Decision Guide

RequirementRecommended patternImportant considerations
Absorb bursts between an application and a database or worker tierAmazon SQS between producer and consumerUse retries, visibility timeout, and a dead-letter queue; do not assume processing is exactly once
Dynamically scale EC2 workers based on pending jobsSQS queue-depth metric with EC2 Auto ScalingTune scale-out thresholds and ensure workers delete messages only after successful processing
Preserve message orderSQS FIFO queueDesign around FIFO throughput and message-group behavior
Run variable-volume image processingS3 event notification to LambdaConfirm the task fits Lambda runtime, packaging, timeout, and concurrency constraints
Expose a REST API with unpredictable demandAPI Gateway plus LambdaProtect and size the database; consider authentication, throttling, and RDS Proxy
Process a workflow made of multiple dependent stepsStep Functions plus LambdaModel retries, branching, timeouts, and failure compensation explicitly
Improve API latency for globally distributed clientsEdge-optimized API Gateway endpointEvaluate CloudFront behavior, custom domains, routing, and security requirements
Reduce Lambda duration for compute-heavy codeIncrease Lambda memoryCPU increases with memory; benchmark cost and performance

Exam-Relevant Takeaways

  • Use Amazon SQS to decouple producers from consumers and buffer bursts.
  • Use queue depth as a scaling signal for worker fleets when backlog determines required capacity.
  • Choose SQS FIFO when strict ordering is a requirement; standard queues do not guarantee ordering.
  • Lambda memory controls more than storage allocation: CPU allocation also increases with memory.
  • Lambda has a maximum invocation timeout of 15 minutes. Longer-running work requires another compute pattern or workflow design.
  • S3 event notifications can invoke Lambda for object-created processing.
  • Step Functions coordinates multi-step serverless workflows and supports explicit retries and error handling.
  • Edge-optimized API Gateway endpoints use the CloudFront edge network and are appropriate for many globally distributed API clients.
  • API Gateway and Lambda failures without Lambda application errors can indicate throttling or concurrency limits.
  • Increasing Lambda concurrency may not solve the problem if RDS or another downstream service is the actual bottleneck.

Common Exam Traps

  • Using a standard SQS queue when ordering is mandatory: Standard queues prioritize scalability and provide at-least-once delivery, not strict ordering.
  • Treating SQS as a transaction mechanism: Queue delivery and database writes require idempotent consumers and appropriate retry handling.
  • Assuming Lambda automatically eliminates database connection limits: High concurrency can create too many database connections. Use pooling, throttling, or RDS Proxy where appropriate.
  • Choosing Lambda for long-running work: The 15-minute maximum timeout is a hard design boundary.
  • Increasing memory only to get more memory: The main performance benefit may be the proportional increase in CPU allocation.
  • Confusing API Gateway endpoint types: Regional endpoints and edge-optimized endpoints have different latency and routing characteristics.
  • Increasing only the Lambda timeout to solve failures: Timeout, throttling, concurrency, downstream capacity, and message visibility timeout are separate concerns.
  • Ignoring duplicate processing: SQS and event-driven systems commonly require idempotent processing because a message or event may be delivered more than once.

Real-World Engineer Notes

  • Set the SQS visibility timeout longer than the expected processing time, with enough margin for retries. If it is too short, another consumer can receive the message while the first consumer is still working.
  • Configure a dead-letter queue so repeatedly failing messages do not block diagnosis or consume processing capacity indefinitely.
  • Make consumers idempotent. Use a unique order ID, object version, or processing record to prevent duplicate side effects.
  • S3-to-Lambda processing can create recursive invocation loops if the function writes processed objects back to the same triggering prefix. Separate input and output prefixes or buckets.
  • Queue depth alone may not represent user experience. Monitor message age, processing duration, error rate, and downstream saturation as well.
  • For API Gateway and Lambda backed by RDS, protect the database with connection controls and consider caching or asynchronous workflows for bursty workloads.
  • Use Step Functions for orchestration, not merely as a replacement for every script. Simple independent tasks may be better served by direct events or SQS.
  • Test Lambda memory settings with representative payload sizes. A faster execution can reduce total billed duration, but higher memory can also increase per-millisecond pricing.

Quick Reference Summary

  • Burst buffering: API or EC2 producer → SQS → Lambda or EC2 consumer.
  • Queue-based scaling: Scale workers using SQS backlog or message age.
  • Ordered processing: Use SQS FIFO.
  • Event-driven object processing: S3 event notification → Lambda.
  • Serverless REST API: API Gateway → Lambda → backend service.
  • Global API latency: Consider an edge-optimized API Gateway endpoint.
  • Long or complex workflow: Step Functions → Lambda and other tasks.
  • Lambda performance: More memory provides more CPU; maximum runtime is 15 minutes.
  • Lambda failures without code errors: Check concurrency and throttling limits.

Flashcards

  1. Q: What AWS service decouples a producer from a consumer and buffers bursts?

A: Amazon SQS.

  1. Q: Which SQS queue type preserves message order?

A: FIFO, provided the application uses it according to FIFO ordering and message-group rules.

  1. Q: What metric can drive EC2 Auto Scaling for queue workers?

A: SQS backlog indicators such as the approximate number of visible messages, often supplemented by message age.

  1. Q: What happens to Lambda CPU allocation when memory is increased?

A: CPU allocation increases proportionally with configured memory.

  1. Q: What is Lambda’s maximum execution timeout?

A: 15 minutes per invocation.

  1. Q: How can an S3 object upload invoke Lambda?

A: Configure an S3 event notification for object-created events, optionally filtered by prefix or suffix.

  1. Q: Which service orchestrates multiple Lambda steps with retries and branching?

A: AWS Step Functions.

  1. Q: Which API Gateway endpoint type uses the CloudFront edge network?

A: An edge-optimized endpoint.

  1. Q: What should be investigated when API Gateway requests fail but Lambda reports no application errors?

A: API Gateway throttling, Lambda concurrency limits, account quotas, reserved concurrency, and downstream capacity.

  1. Q: Why should SQS consumers be idempotent?

A: Messages can be delivered more than once, so repeated processing must not create unintended duplicate effects.

Practice Questions

Question 1

A web application receives unpredictable bursts of requests. Each request creates a database update, but the database cannot handle the peak write rate and updates are being lost. Which architecture best addresses the immediate decoupling requirement?

A. Place an SQS queue between the application and the database and process messages asynchronously
B. Increase the API Gateway cache size
C. Use an SQS FIFO queue and write directly from the web tier without consumers
D. Increase the Lambda timeout

Correct answer: A

Explanation: SQS buffers work and separates the request-producing tier from the database-writing tier. A consumer, such as Lambda or EC2, can process messages at a sustainable rate. The application must also handle retries, duplicates, and failed messages.

Question 2

A company processes customer orders asynchronously. If two orders arrive close together, the second order must never be processed before the first. Which solution should an architect recommend?

A. Amazon SQS standard queue
B. Amazon SQS FIFO queue
C. Amazon SNS standard topic only
D. Amazon EventBridge with no ordering controls

Correct answer: B

Explanation: SQS FIFO is designed for ordered message processing. The application should also select an appropriate message-group strategy and use idempotent processing.

Question 3

A Lambda function processes large image payloads. Its duration increases substantially as image size grows, but the function remains within the Lambda timeout. Which change is most likely to improve execution time?

A. Reduce the function’s memory allocation
B. Increase the function’s memory allocation and benchmark the result
C. Convert the API Gateway endpoint from Regional to private
D. Add an SQS FIFO queue solely to increase CPU

Correct answer: B

Explanation: Lambda allocates CPU in proportion to memory. Increasing memory can improve CPU-bound processing and reduce duration, although cost and performance should be tested together.

Question 4

A company has a chain of batch scripts. Each script passes output to the next, and the workflow includes retries, conditional branches, and failure handling. Which AWS service is best suited to coordinate the workflow?

A. AWS Step Functions
B. Amazon S3 lifecycle rules
C. Amazon CloudFront
D. AWS Direct Connect

Correct answer: A

Explanation: Step Functions provides state-machine orchestration, sequencing, branching, retries, timeouts, and workflow visibility. Individual steps can be implemented with Lambda or other AWS services.

Question 5

An API Gateway and Lambda application works correctly during normal traffic. During traffic spikes, requests fail, but Lambda logs show no function errors. What should the architect investigate first?

A. Whether Lambda’s maximum timeout should be reduced to zero
B. API Gateway and Lambda throttling or concurrency limits
C. Whether S3 event notifications are enabled
D. Whether the SQS queue is FIFO

Correct answer: B

Explanation: Failures without application-level Lambda errors can result from throttling before or during invocation. Review API Gateway limits, Lambda account and function concurrency, reserved or provisioned concurrency, and the capacity of downstream services before selecting a remediation.