5
5
Table of Contents

In today's cloud-native landscape, API gateways play a critical role in serverless and microservices architectures. This is a powerful tool for building scalable APIs, but it's also easy to overlook the cost-effectiveness, especially if the APIs are frequently called or redundant. For FinOps practitioners who are sure to focus on reducing costs without compromising, the use of API Gateways integrated with a cache is a game-changer.

What Is API Gateway Caching?

Amazon API Gateway provides integrated response caching, interfering with edge layer endpoints, eliminating the need to access back-end services (such as Lambda, EC2, RDS) for each request.
Here’s how it works:

  • When caching is enabled on a stage or method, API Gateway stores responses in an in-memory cache.
  • Subsequent requests with the same parameters hit the cache instead of the backend.
  • You control cache TTL (Time to Live) and cache keys for precision.

How Should Cache be Handled? 

1. Reduce Backend Invocation Costs

Back-end views (such as Lambda or RDS calls) often incur the majority of API-related costs. These calls are avoided in intermediate storage if the same query from the cache is being operated on.

2. Control Data Transfer Charges

Output data transmission (especially for large payloads) is reduced, leading to savings in data transmission costs (DTO).

3. Enhance User Experience

Faster response times and lower latency mean you don’t need to scale up infra  (saving both cost and operational effort).

Use Case

Suppose you want to run the Product Catalog API for your e-commerce platform. To retrieve the product listings.

Without caching:

  • Every user requests to call the backend service.
  • During high usage, our backend suffers from the load, and it impacts the performance.
  • Each query adds latency due to DB access and data processing.

With Caching Enabled: 

With Caching Enabled:

Multiplying this by multiple APIs can save thousands of dollars each year.

How to Enable API Gateway Caching (Step-by-Step)

Step 1: Open the API Gateway Console

Sign in to the AWS Management Console and navigate to Amazon API Gateway. Select the REST API where you want to enable caching.

Step 2: Select the Deployment Stage

From the left navigation pane, choose Stages, then select the deployment stage (for example, dev, staging, or production) where caching should be enabled.

Step 3: Enable the Cache Cluster

Click Edit in the Stage details section.
Under Cache Settings:

  • Enable Provision API Cache.
  • Select the appropriate cache cluster size.
  • Configure the Cache TTL (Time to Live) based on how frequently your data changes. The default TTL is 300 seconds, the maximum is 3,600 seconds, and setting TTL = 0 disables caching. Use a shorter TTL for frequently changing data and a longer TTL for relatively static content.

Step 4: Configure Method-Level Caching

Enable Default Method-Level Caching to cache responses for eligible GET methods. By default, API Gateway caches only GET requests.

You can also configure cache key parameters so that requests with different parameter values generate separate cache entries.

Example Request

Example Request

Cache Key

Cache Key

Requests such as GET /users?type=regular are cached separately because the type query parameter is included in the cache key.

Note: If you have an existing setting for a method-level cache, changing the default method-level caching setting doesn't affect that existing setting.

Step 5: Save the Configuration

Choose Save Changes to provision the cache cluster. Creating or deleting a cache cluster can take up to four minutes. Once the cache status changes to Active, monitor cache performance using Amazon CloudWatch metrics such as CacheHitCount and CacheMissCount to verify that caching is working as expected.

Pro Tip:

Use stage variables to toggle caching across environments without redeploying code.

CloudFormation Example

CloudFormation Example

Terraform Example

Terraform Example

API Gateway Cache Pricing

API Gateway provisions a dedicated cache cluster for each deployment stage. Selecting the appropriate cache size depends on your API traffic, response payload size, and expected cache hit ratio.

API Gateway Cache Pricing

Note: Pricing may vary by AWS Region. Refer to the official AWS API Gateway Pricing page for the latest pricing. 

When to Use API Gateway Caching

Ideal For

  • API Gateway caching is most effective for workloads where responses are requested frequently but change infrequently. Common use cases include:
  • Read-heavy, infrequently changing endpoints, such as product catalogs, FAQs, blog posts, and documentation.
  • Microservices with repetitive payloads, where identical requests are made by multiple users.
    APIs fronting expensive backend operations, including database lookups, Lambda functions, and machine learning inference.
  • Public APIs with predictable traffic patterns, where reducing backend load improves scalability and lowers infrastructure costs.

Avoid Caching When

API Gateway caching may not be suitable for every workload. Avoid enabling caching in the following scenarios:

  • Data changes frequently, such as real-time stock prices, live inventory, or continuously updated analytics.
  • Request-by-request freshness is required, for example, personalized dashboards, user-specific recommendations, or session-based responses.
  • Authentication and authorization endpoints, where responses differ for every user and should never be reused.
  • Payment processing or transactional APIs, where stale responses can affect data accuracy and user experience.
  • Write-heavy workloads, where frequent updates reduce cache effectiveness and increase the risk of serving outdated data.

Best Practices

Best Practices

Conclusion

API Gateway Caching is one of the easiest ways to reduce costs and improve performance. Doing more in less amounts. If you're managing serverless APIs or want to advise your team on cost strategies, put caching in your roadmap today.

12
Let's discuss your cloud challenges and see how CloudKeeper can solve them all!
Meet the Author
  • Varshit Agarwal
    Senior Software Engineer

    Varshit is a Senior Software Engineer with over five years of experience in DevOps and Platform Engineering.

No Comments Yet
Leave a Comment
Certified. Trusted. Industry Recognized.

Stop paying for cloud tools. Start paying for outcomes.

Get Started with CloudKeeper