AWS Serverless Website - Article 2 Optimizing Performance in Serverless React Apps
My personal website doesn't have millions of users (yet.) However, performance optimization is crucial for enhancing user experience and reducing costs ...

Todd Bernson
2024-09-28

My personal website doesn't have millions of users (yet.) However, performance optimization is crucial for enhancing user experience and reducing costs in serverless applications.

This article will explore techniques to optimize your serverless React app using AWS services like Lambda@Edge, DynamoDB, and CloudFront.
Here is my personal website repo.
Leveraging AWS Lambda@Edge
Lambda@Edge allows you to run code closer to users, reducing latency. Here's how you can use Lambda@Edge to cache dynamic content:
Create a Lambda Function: Write a Lambda function that modifies responses.
exports.handler = async (event) => {
const response = event.Records[0].cf.response;
response.headers['cache-control'] = [{ key: 'Cache-Control', value: 'max-age=3600' }];
return response;
};
Associate Lambda@Edge with CloudFront: Attach this function to your CloudFront distribution.
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
lambda_function_association {
event_type = "origin-response"
lambda_arn = aws_lambda_function.edge_function.arn
}
}
Optimizing DynamoDB Usage
DynamoDB is a fast and flexible NoSQL database service. Optimize its performance by:
- Using Efficient Indexing: Implement Global Secondary Indexes (GSIs) to optimize query performance. Taking a deep, detailed look at the query structure will save time and money in the future.
- Provisioning Throughput Capacity: Monitor and adjust read/write capacity to match your workload demands.
resource "aws_dynamodb_table" "my_table" {
name = "my_table"
read_capacity = 5
write_capacity = 5
hash_key = "id"
attribute {
name = "id"
type = "S"
}
global_secondary_index {
name = "GSI"
hash_key = "attribute_name"
projection_type = "ALL"
read_capacity = 5
write_capacity = 5
}
}
Implementing Caching Strategies with CloudFront
CloudFront can cache your content at edge locations to improve load times.
Set Cache Behaviors: Configure different cache behaviors for static and dynamic content.
ordered_cache_behavior = [
{
path_pattern = "/totals"
target_origin_id = "api_gw"
viewer_protocol_policy = "redirect-to-https"
allowed_methods = ["GET", "HEAD", "OPTIONS", "POST", "DELETE", "PUT", "PATCH"]
cached_methods = ["GET", "HEAD"]
compress = true
query_string = true
},
{
path_pattern = "/insert"
target_origin_id = "api_gw"
viewer_protocol_policy = "redirect-to-https"
allowed_methods = ["GET", "HEAD", "OPTIONS", "POST", "DELETE", "PUT", "PATCH"]
cached_methods = ["GET", "HEAD"]
compress = true
query_string = true
},
{
path_pattern = "*"
target_origin_id = "s3_one"
viewer_protocol_policy = "redirect-to-https"
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
compress = true
query_string = true
}
]
Enable Compression: Use gzip or Brotli compression to reduce the size of your assets.
# from the snippet above
compress = true
Code Splitting and Lazy Loading in React
Optimize your React app by implementing code splitting and lazy loading.
import React, { Suspense, lazy } from 'react';
const LazyComponent = lazy(() => import('./LazyComponent'));
function App() {
return (
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
);
}
My site isn't big enough to need this at this point.
Optimizing performance in serverless React applications involves various strategies, from leveraging Lambda@Edge for reduced latency to optimizing DynamoDB usage and implementing effective caching strategies with CloudFront. By incorporating these techniques, you can ensure your application delivers a fast and efficient user experience.
Visit my website here.
Read More
View all posts
AI/ML
Why Enterprise AI Must Be Application-Led, Not Agent-Led
A deep dive by Todd Bernson, CTO and Chief AI Officer, on why enterprise AI systems should be architected as application-led, deterministic platforms with embedded agentic AI—not fully autonomous agents. This article explains how API-first, governed, multi-channel architectures deliver higher reliability, compliance, scalability, and business value in real-world Fortune-500 environments.

Todd Bernson
2025-12-02

AI/ML
Application-First Agentic AI
Application-first agentic AI is emerging as the only reliable path to real enterprise ROI. In this in-depth analysis, Todd Bernson, CTO & CAIO, breaks down why most generative AI initiatives stall in production—and how disciplined enterprise architecture, deterministic workflows, and narrowly scoped AI agents can finally unlock repeatable business value. Using a real sprint-intelligence system as a case study, the article shows how organizations can combine serverless engineering, structured orchestration, and constrained LLM reasoning to reduce reporting effort, increase trust, eliminate hallucinations, and deliver actionable insights across engineering, operations, compliance, and customer experience.

Todd Bernson
2025-11-28
AI/ML
Why 95% of AI Projects Fail and How to Be Among the 5% That Succeed

Lee Hylton
2025-08-22