Keeping Serverless Applications and Relational Databases Healthy with Amazon RDS Proxy
Serverless applications make it easy to scale compute capacity. But there is an important question that often appears when a serverless application connects to a relational database: What happens when the application scales faster than the database can handle connections?
What happens when the application scales faster than the database can handle connections?
This was the problem I wanted to understand through a hands-on AWS project.
I built and tested an architecture using AWS Lambda, Amazon RDS for PostgreSQL, Amazon RDS Proxy, AWS Secrets Manager, Amazon VPC, and AWS CloudFormation.
The objective was simple:
Build a serverless application that can handle high concurrency without overwhelming the relational database.
The Architecture
The basic request flow was:
Client → API Gateway → Lambda → RDS Proxy → RDS PostgreSQL
Lambda functions were deployed inside a VPC, while RDS and the proxy were placed in private subnets.
AWS Secrets Manager was used to manage database credentials rather than hard-coding them into the Lambda function.
CloudFormation was used to define the infrastructure so that the environment could be deployed consistently.
The important component in the architecture was RDS Proxy.
Why Direct Lambda-to-RDS Connections Can Become a Problem
Lambda creates execution environments dynamically.
When traffic increases, AWS can create additional execution environments to process requests concurrently.
If every execution environment creates its own database connection, connection usage can grow rapidly.
For example:
1,000 concurrent Lambda executions ≠ 1,000 requests that a relational database should necessarily handle as 1,000 independent connections.
The database has finite resources.
This creates a potential bottleneck between two systems with very different scaling characteristics.
Lambda can scale horizontally.
A relational database has limits.
This is where connection pooling becomes important.
How RDS Proxy Helps
RDS Proxy sits between Lambda and the database.
Instead of every Lambda execution establishing an independent backend database connection, the proxy maintains a managed pool of connections to the database.
Conceptually:
Without Proxy
Lambda → Connection → RDS
Lambda → Connection → RDS
Lambda → Connection → RDS
Lambda → Connection → RDS
With many concurrent executions, this can create significant connection pressure.
With RDS Proxy
Lambda → RDS Proxy → Connection Pool → RDS
The proxy can multiplex client requests across a smaller number of database connections.
This allows the application layer to scale without forcing the database connection count to grow at the same rate.
Execution Context Reuse
Another optimization I explored was Lambda execution-context reuse.
Instead of creating a database connection every time the Lambda handler executes, the connection can be initialized outside the handler.
Conceptually:
connection = create_connection()
def lambda_handler(event, context): # Reuse connection when the execution environment remains warm process_request(connection)
When Lambda reuses an execution environment, the existing connection can potentially be reused as well.
This reduces repeated connection-establishment overhead and can improve latency.
However, applications still need to handle stale or dropped connections correctly because execution environments are not permanent.
Testing the Architecture
I didn't want to stop after seeing a successful API response.
The architecture needed to be tested under concurrency.
I used a high-concurrency invocation test to generate a large number of Lambda executions.
The important metrics were:
- Lambda invocation count
- Lambda duration
- Lambda errors
- Lambda concurrency
- RDS database connections
- RDS Proxy connection behavior
- Application response behavior
The most interesting observation was the difference between client-side concurrency and backend database connections.
Even with a large number of Lambda invocations, the database backend maintained a much smaller connection footprint because RDS Proxy handled connection pooling and multiplexing.
That was the point where the architecture made sense beyond the diagram.
Security Considerations
The architecture also required careful IAM and networking configuration.
The Lambda function required permission to retrieve database credentials from Secrets Manager.
The network configuration restricted database access to the appropriate security groups and private subnets.
The design followed a simple principle:
Lambda should not have unnecessary access to other resources simply because it is part of the same application.
Least privilege should be applied to both IAM permissions and network connectivity.
Infrastructure as Code
I also deployed the infrastructure using CloudFormation.
This was important because manually creating:
- VPCs
- Subnets
- Security Groups
- Lambda functions
- RDS
- RDS Proxy
- Secrets Manager resources
- IAM roles
makes the environment difficult to reproduce.
With CloudFormation, the architecture becomes a version-controlled definition rather than a collection of console configurations.
That makes it easier to rebuild the environment, review changes, and maintain consistency between environments.
What I Learned
The biggest lesson from this project was not simply how to configure RDS Proxy.
It was understanding that scalability is a system-level property.
A serverless application can scale its compute layer extremely quickly while its database remains the limiting component.
Therefore, when designing serverless architectures, I now think about the complete dependency chain:
Compute → Connections → Database → Storage → Downstream Services
If one component scales differently from the others, it can become the bottleneck.
RDS Proxy provides one mechanism for addressing the database connection problem, but the broader lesson is more important:
Don't design scalability for individual services. Design scalability for the entire system.
Final Thoughts
This project changed how I look at serverless architectures.
Before, I mainly thought:
“Lambda scales automatically.”
Now I think:
“Lambda scales automatically—but what are the dependencies behind Lambda doing when that happens?”
That question leads to better architecture decisions.
Serverless doesn't remove infrastructure problems.
It changes where those problems appear.
Understanding those boundaries is what makes serverless architecture interesting—and what I wanted to explore through this project.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article