Question

Difficulty: HardApplication Caching and Session State Management

A developer is designing a serverless e-commerce application. The application has a public API endpoint hosted on Amazon API Gateway that triggers an AWS Lambda function. The Lambda function queries an Amazon DynamoDB table to retrieve a list of active discount codes. This discount list is read-heavy, updated only once per day, and must be returned with sub-second response times. During peak shopping events, the API Gateway endpoint experiences high latency and DynamoDB triggers provisioned throughput exceptions. The developer wants to implement a caching solution that minimizes costs and reduces the load on both the Lambda function and the DynamoDB table.

Which caching strategy should the developer implement to meet these requirements?

  1. A
    Provision an Amazon DynamoDB Accelerator (DAX) cluster to cache the read queries from the DynamoDB table.
  2. Enable Amazon API Gateway stage-level caching with a Time to Live (TTL) of 24 hours.Answer
  3. C
    Initialize a global variable inside the AWS Lambda function to cache the list in the execution context.
  4. D
    Perform a DynamoDB Scan operation within the Lambda function and cache the results in the AWS Systems Manager Parameter Store.

Answer

Enable Amazon API Gateway stage-level caching with a Time to Live (TTL) of 24 hours.
Enabling caching at the Amazon API Gateway stage level is the most cost-effective and low-latency solution. When API Gateway caching is enabled, API Gateway caches responses from the backend (Lambda and DynamoDB) for the specified Time to Live (TTL). If a cache hit occurs, API Gateway returns the response directly to the client without invoking the AWS Lambda function or querying the Amazon DynamoDB table. This eliminates Lambda execution costs and DynamoDB read unit charges for all cached requests, while providing the lowest latency.

Step-by-Step Solution

1
Analyze the traffic and cost profile of the serverless application layers.
Determine that requests are read-heavy, data changes only once per day, and both Lambda execution cost and DynamoDB read capacity need to be optimized.
This establishes that caching should occur as close to the client as possible to prevent downstream invocations and costs.
2
Evaluate the capabilities of Amazon API Gateway stage-level caching.
API Gateway caching can store responses and serve them directly to clients, bypassing both Lambda and DynamoDB entirely for cache hits.
Serving requests directly from API Gateway minimizes latency and eliminates execution costs for downstream services.
3
Determine the appropriate cache configuration and TTL.
Configure API Gateway caching with a TTL of 24 hours to align with the daily update frequency of the discount codes.
Aligning the TTL with the data update frequency ensures clients receive fresh data while maximizing the cache hit ratio.

Key Concept

Caching at the API Gateway layer to minimize downstream serverless execution and database costs.
Rate this question