This lesson combines 2 topics: Modernization Patterns, Serverless Patterns and Best Practices.
Learning Objectives
- Understand the modernization spectrum (VMs → managed services → containers → serverless) and its trade-offs
- Master the Strangler Fig pattern to break up a monolith safely
- Know microservices/event-driven architectures on AWS and Gen AI patterns (Bedrock, RAG)
- Recognize the 6 classic serverless patterns (API backend, event processing, fan-out, load leveling, saga, strangler fig)
- Master Lambda best practices: cold start, memory/timeout, error handling by invocation type
- Choose correctly between REST API vs HTTP API vs WebSocket and Standard vs Express Step Functions
Part 1: Modernization Patterns
1. Modernization Paths
2. Strangler Fig Pattern
3. Microservices on AWS
4. Event-Driven Architecture
5. Amazon MQ — Re-platform Messaging
A managed message broker for Apache ActiveMQ and RabbitMQ. This is the re-platform option for messaging: on-prem apps that use a message broker with industry-standard protocols — JMS, AMQP 0-9-1, MQTT, OpenWire, STOMP — migrate to the cloud without changing application code, only switching the connection endpoint to the Amazon MQ broker.
Amazon MQ vs SQS/SNS
| Criterion | Amazon MQ | SQS/SNS |
|---|---|---|
| Protocol | JMS, AMQP 0-9-1, MQTT, OpenWire, STOMP (industry standard) | AWS-specific API (HTTPS) |
| Migrating legacy apps | No code changes needed | Must rewrite the messaging layer |
| Throughput/scale | Limited by the broker instance size | Cloud-native, nearly unlimited scale |
| Network | Runs in a VPC (private endpoint) | Public endpoint (VPC endpoint supported) |
| Auth | Broker username/password (+ LDAP with ActiveMQ) | IAM policies |
| Operational overhead | You still choose the instance size and manage broker config | Lowest (fully serverless) |
| Use case | Existing apps using ActiveMQ/RabbitMQ/standard protocols | New apps built on AWS |
Exam selection rule: for new apps → always prefer SQS/SNS (better scale, cheaper, less operations); for existing apps that use a standard messaging protocol with the requirement "migrate messaging without rewriting application code" → Amazon MQ. If the question allows code changes and emphasizes "unlimited scale" / "least operational overhead", then SQS/SNS is the answer — do not pick MQ just because you see the words "message broker".
6. Generative AI Modernization Patterns
AWS has pushed hard on Gen AI services since 2023-2024. SAP-C02 (post-2024) has started including scenarios about AI-augmented application architectures — you need to know the main options.
Amazon Bedrock (managed Foundation Models)
When to use Bedrock: you need to add Gen AI to an application without managing GPUs/model serving. Multi-tenant, cross-account access via IAM Identity Center or resource-based policies.
Bedrock vs SageMaker JumpStart vs Self-managed
| Criterion | Bedrock | SageMaker JumpStart | Self-managed (EC2/EKS) |
|---|---|---|---|
| Infra management | None (serverless) | One-click deploy to an endpoint | Fully self-managed |
| Model customization | Limited fine-tuning | Full fine-tuning, custom training | Full control |
| Cost model | Per token | Endpoint + storage | EC2/GPU hours |
| Privacy | Data does not leak into the base model | In a VPC, isolated | Full control |
| Operational overhead | Lowest | Medium | Highest |
| Use case | Production Gen AI apps, RAG, agents | Custom models, deep fine-tuning | Special compliance requirements |
Pattern: RAG (Retrieval-Augmented Generation)
Other AI/ML services SAP-C02 often asks about
- SageMaker: end-to-end ML platform (train, deploy, monitor models)
- SageMaker JumpStart: pre-trained models + solution templates
- Comprehend: NLP (sentiment, entity recognition, language detection)
- Textract: OCR + form/table extraction
- Rekognition: image/video analysis (faces, objects, moderation)
- Transcribe / Polly: speech-to-text / text-to-speech
- Translate: real-time translation
- Lex: build chatbots/voice bots with ASR + NLU (intents/slots — the same technology as Alexa); integrates with Amazon Connect to automate contact centers
- Kendra: ML-powered enterprise search over internal documents (connectors: S3, SharePoint, Salesforce...), answers natural language questions; often used as the retriever for RAG with Bedrock
- Personalize: recommendation engine (a great fit for e-commerce)
- Q Developer (formerly CodeWhisperer): AI code assistant for IDE/CLI
Exam keywords for Gen AI scenarios
| Requirement in the question | Matching service |
|---|---|
| "Use foundation models with least operational overhead" | Bedrock |
| "Customize model with enterprise data, no data leakage" | Bedrock fine-tuning or Knowledge Bases |
| "Build chatbot with context from internal docs" | Bedrock + Knowledge Bases (RAG) |
| "Multi-step agent with tool use" | Bedrock Agents |
| "Content moderation, PII redaction" | Bedrock Guardrails or Comprehend PII |
| "Train custom model from scratch, full control" | SageMaker (training jobs) |
| "Quick deploy pre-trained model" | SageMaker JumpStart |
| "Automated customer service chatbot" (contact center) | Lex (+ Amazon Connect) |
| "Natural language search across company documents" | Kendra |
Part 2: Serverless Patterns and Best Practices
Serverless Architecture Overview
Common Serverless Patterns
1. API Backend Pattern
GraphQL Variant:
2. Event Processing Pattern
3. Fan-Out Pattern
4. Queue-Based Load Leveling
5. Saga Pattern (Distributed Transactions)
6. Strangler Fig Pattern
Lambda Best Practices
1. Cold Start Optimization
2. Memory and Timeout
3. Error Handling
API Gateway Patterns
1. REST API vs HTTP API
2. Caching Strategy
Step Functions Patterns
1. State Machine Types
2. Common States
Exam Scenarios
Scenario 1: High-Volume Event Processing
Scenario 2: Async Workflow
Scenario 3: Real-time Dashboard
Quick Reference
Review Questions
-
How does the Strangler Fig pattern work, and why is it safer than a big-bang rewrite?
Show answer
Put a facade (ALB/API Gateway) in front of the monolith, then extract features one at a time into new services — the facade routes migrated paths to the new services while everything else still goes to the monolith, until the monolith is fully "strangled". It is safer than big-bang because: each small step can be rolled back (change the routing), the business keeps running, you learn from the first service before extracting the next, and it reduces the risk of "a 2-year rewrite with no releases". Keyword "gradually migrate monolith with minimal risk" → Strangler Fig.
-
Should communication between microservices be sync (API) or async (event)?
Show answer
Sync (API Gateway/ALB): when the caller needs the result immediately (query, validate) — but it creates temporal coupling: if service B dies, A goes down with it. Async (SQS/SNS/EventBridge): when processing can be delayed (order processing, notifications) — loose coupling, spike buffering, natural retries; the trade-off is eventual consistency and harder debugging (you need tracing). Professional rule: default to async between bounded contexts, sync only on the critical read path — many exam questions reward inserting SQS between 2 tiers to "decouple and absorb spikes".
-
When is Bedrock Knowledge Bases the answer instead of fine-tuning?
Show answer
Knowledge Bases (RAG): the knowledge lives in frequently changing documents (internal policies, product docs) — the model retrieves context at query time, updates only require re-indexing with no retraining, and the data is controllable (citations). Fine-tuning: you need to change the model's behavior/tone/format or handle a specialized domain where prompts + RAG are not enough — more expensive, and knowledge updates are slow. Keyword "chatbot answers from internal documents, always up to date" → Knowledge Bases; "model must follow company-specific style at scale" → fine-tuning.
-
Which modernization scenario is App2Container suited for?
Show answer
App2Container (A2C): a CLI that analyzes running Java/.NET apps on VMs/on-prem, automatically packages them into container images + generates ECS/EKS artifacts and a pipeline — used for the "containerize without code changes" step (between Rehost and Refactor). Good fit: legacy apps without a Dockerfile, teams that want to standardize on ECS/EKS quickly. Not a good fit: apps that need their logic rewritten (true Refactor) or unsupported COTS apps.
-
A company is migrating an on-prem app that uses ActiveMQ with JMS to AWS, with the requirement of no application code changes. Choose Amazon MQ or SQS/SNS, and how do you design HA?
Show answer
Amazon MQ (ActiveMQ engine) — it supports the JMS/OpenWire protocols as-is, so the app only needs to change its endpoint, matching the keyword "migrate messaging without rewriting application code" (re-platform). SQS/SNS requires rewriting the messaging layer to the AWS API, so it is ruled out. HA: deploy active/standby multi-AZ with shared storage on EFS — the standby broker in another AZ takes over automatically when the active one fails, with no message loss. (With the RabbitMQ engine, HA is a 3-node cluster across 3 AZs.) Conversely, for a new app or when the question allows code changes and emphasizes "unlimited scale"/"least operational overhead" → SQS/SNS.
-
A self-service customer chatbot must answer from internal documents: when do you use Lex, when do you use Kendra, and when do you combine them?
Show answer
Lex = the conversational interface (ASR + NLU, intents/slots): receives user requests via voice/text, fits "automated customer service chatbot", and integrates with Amazon Connect for contact centers. Kendra = ML-powered enterprise search: indexes internal documents (S3, SharePoint, Salesforce...) and answers natural language questions — keyword "natural language search across company documents". Combined: Lex captures the intent, and fulfillment (Lambda) queries Kendra to get the answer from the docs; or the more modern pattern is Kendra as the retriever for RAG with Bedrock. Lex does not search documents on its own, and Kendra does not manage conversations — if the question asks for both, the answer is the combined architecture.
-
What does fan-out with SNS → SQS → Lambda gain over SNS → Lambda directly?
Show answer
Inserting SQS between SNS and Lambda gives: (1) a buffer when the consumer is slow/down — messages are not lost (when SNS fails to invoke Lambda it only retries a limited number of times), (2) rate control via batch size + reserved concurrency, (3) a DLQ per consumer with maxReceiveCount, (4) easier replay. Trade-off: extra latency and SQS cost. If you need ordering in fan-out → SNS FIFO + SQS FIFO (message group) — EventBridge does not guarantee ordering.
-
Standard vs Express Step Functions — which criteria decide?
Show answer
Standard: exactly-once, runs up to 1 year, charged per state transition, full history — for business workflows (order saga, human approval, long-running). Express: at-least-once (must be idempotent), up to 5 minutes, charged per execution + duration, much cheaper at high volume — for high-frequency event processing/IoT ingestion. Keyword "high-volume short-lived executions, cost-effective" → Express; "long-running with audit trail" → Standard.
-
Why must the SQS visibility timeout be greater than the Lambda function timeout?
Show answer
Lambda polls a message → the message is hidden for the visibility timeout; if the function is still processing when the visibility timeout expires, the message reappears and another consumer processes it as a duplicate. AWS recommendation: visibility timeout ≥ 6× the function timeout (accounting for retries + batch window). Alongside that: maxReceiveCount → DLQ so bad messages do not loop forever, and enable partial batch failure reporting (
ReportBatchItemFailures) to retry only the failed messages in a batch. -
How do you correctly handle requests that exceed 29 seconds behind API Gateway?
Show answer
The standard async + polling/callback pattern: API Gateway → Lambda accepts the job, pushes it to SQS/Step Functions, and immediately returns 202 Accepted + a job ID; the client polls a status endpoint (or receives a WebSocket/webhook notification when done). Note the 06/2024 update: Regional and private REST APIs can request an integration timeout increase beyond 29s (possibly in exchange for a lower account throttle quota); edge-optimized REST APIs (29s) and HTTP APIs (30s maximum) cannot be raised — but on the exam, raising the timeout is rarely the "best answer" compared with a proper async design.
Hands-on Exercises
Part 1: Modernization Patterns
-
Mini Strangler Fig: build a "monolith" (1 EC2/container with
/ordersand/usersroutes) behind an ALB; extract/usersinto a Lambda + new target group, and change the listener rule so/usersgoes to Lambda — no code changes to the monolith. -
Event-driven decoupling: replace a direct call between 2 demo services with EventBridge (the publisher emits an
OrderCreatedevent, a consumer Lambda processes it); turn off the consumer and verify events are not lost (archive + DLQ), then turn it back on to continue processing. -
RAG with Bedrock Knowledge Bases: create a Knowledge Base from a few PDF files in S3 (OpenSearch Serverless auto-created), ask questions through the console/API, and check that the citations point to the correct source documents.
Part 2: Serverless Patterns and Best Practices
-
Queue-based load leveling: build API Gateway → Lambda → SQS → Lambda worker (reserved concurrency 2); fire 500 requests quickly and watch the queue depth rise and then drain — the system does not drop any requests.
-
Saga with Step Functions: create a 3-step state machine (reserve inventory → charge payment → confirm) with a Catch that transitions to compensation steps (release/refund); run an input that fails at step 2 and watch the rollback branch in the console.
-
Async API pattern: implement a
POST /jobsendpoint that returns 202 + jobId (written to DynamoDB), a worker that processes for 2 minutes, and aGET /jobs/{id}endpoint that returns the status — simulating exactly the "long-running task behind API Gateway" answer.
References
- Modern applications on AWS
- Strangler fig pattern (AWS Prescriptive Guidance)
- Microservices on AWS
- Serverless Application Model
- Amazon Bedrock User Guide
- Bedrock Knowledge Bases
- SageMaker JumpStart
- Amazon MQ Developer Guide
- Amazon Lex Developer Guide
- Amazon Kendra Developer Guide
- AWS Lambda Developer Guide
- Amazon API Gateway
- AWS Step Functions
- Serverless Land Patterns