DEV Community

Danh Hoang Hieu Nghi
Danh Hoang Hieu Nghi

Posted on

Designing Serverless Applications at Massive Scale with AWS Lambda and RDS Proxy

I love serverless architecture because i can build scalable systems without managing any infra or server, however for scaling some "provisioning" services like RDS is quite difficult.

This blogs will have you take a look at how to design and scale an serverless architecture with AWS RDS Proxy and AWS Lambda

1. Problem: The Hidden Scaling Problem

AWS Lambda can scale horizontally to thousands of concurrent executions within seconds.

But relational databases (MySQL/PostgreSQL on Amazon RDS or Aurora) have hard limits:

  • Limited number of concurrent connections
  • Each connection consumes memory and CPU
  • Opening/closing connections is expensive

If every Lambda invocation creates a new database connection, high concurrency can quickly exhaust the database’s max_connections limit.

The result:

  • Connection errors
  • Increased latency
  • Database instability

This is the core scaling bottleneck in serverless architecture

2. Solution: Amazon RDS Proxy

What Is RDS Proxy?

Amazon RDS Proxy is a managed database proxy that sits between your Lambda functions and your RDS database.

RDS Proxy

Instead of:

Lambda to RDS

We should use:

Lambda to RDS Proxy to RDS

Why RDS Proxy?

The main purpose is connection pooling and connection reuse.

Without proxy:

  • Each Lambda instance opens its own DB connection.
  • Thousands of Lambdas = thousands of connections.

With RDS Proxy:

  • Proxy maintains a pool of persistent connections to the database.
  • Lambda connects to the proxy endpoint.
  • Proxy reuses existing DB connections.

This dramatically reduces:

  • Database memory usage
  • CPU overhead
  • Connection storms during traffic spikes

How RDS Proxy Works Internally

There are two authentication layers:

Lambda → RDS Proxy

Lambda authenticates using either:

  • Username/password
  • IAM database authentication (recommended)

With IAM authentication:

  • Lambda generates a temporary auth token.
  • Token is valid for ~15 minutes.
  • No password is stored in code.
  • IAM policies control access.

RDS Proxy → Database

RDS Proxy retrieves database credentials from AWS Secrets Manager.

RDS retrieves DB credentials from AWS Secrets Manager

Flow:

  1. You store DB credentials in Secrets Manager.
  2. RDS Proxy is configured to use that secret.
  3. Proxy establishes and maintains pooled connections to the database.

Lambda never needs the real database password when using IAM auth.

Full Authentication Flow

Full Authentication Flow

  • Removes hardcoded credentials
  • Enables password rotation
  • Improves security posture
  • Supports massive concurrency

3. Designing Serverless Apps for Massive Scale

Scaling Lambda is automatic.

Scaling everything else is your responsibility.

The most common architectural mistake is:

asynchronus

Under heavy load:

  • Lambda scales
  • Database becomes overwhelmed
  • System fails

The Right Pattern: Decoupled and Asynchronous

Instead of tight synchronous chains, use buffering and **event-driven **design:

event-driven

  • SQS absorbs traffic spikes
  • Lambda processes messages in controlled batches
  • Database load becomes predictable
  • System becomes resilient

Key design principles:

  • Decouple services
  • Use asynchronous processing
  • Avoid direct scaling pressure on databases
  • Design for backpressure handling

4. Understanding Lambda Invocation Models

Choosing how Lambda is invoked affects performance and reliability.

AWS Lambda supports three invocation types.


Synchronous Invocation

Synchronous Invocation

Caller waits for response.

Examples:

  • API Gateway
  • Application Load Balancer

Characteristics:

  • Immediate execution
  • Caller handles retry
  • Suitable for request/response APIs

Use when:

  • Low latency response is required
  • User-facing APIs

Asynchronous Invocation

Caller sends event and does not wait.

Asynchronous Invocation

Examples:

  • S3
  • SNS

Characteristics:

  • Event is queued internally
  • Lambda retries automatically
  • Better for background tasks

Use when:

  • Event-driven processing
  • Non-blocking workflows

Poll-Based Invocation (Event Source Mapping)

Lambda polls a data source.

Examples:

  • SQS
  • Kinesis
  • DynamoDB Streams

Characteristics:

  • Batch processing
  • Controlled concurrency
  • Ideal for high-throughput workloads

This model is critical when designing for massive scale.

5. Putting Everything Together: A Production-Grade Architecture

Here is a scalable, secure serverless design:

AWS Async full architecture

Security:

  • Database credentials stored in Secrets Manager
  • Lambda authenticates via IAM
  • RDS Proxy manages pooled connections

Scalability:

  • SQS absorbs spikes
  • Lambda scales safely
  • RDS Proxy protects database
  • Aurora handles transactional workload

Reliability:

  • Automatic retries
  • Dead-letter queues
  • Backpressure handling

6. When Should You Use RDS Proxy?

Use RDS Proxy when:

  • You use Lambda with RDS/Aurora
  • You expect unpredictable traffic spikes
  • You need secure IAM-based DB authentication
  • You want connection pooling without managing it manually

Do not rely on direct Lambda-to-RDS connections in high-scale production systems.

7. Final Takeaways

Conclusionn

Serverless scaling is easy for compute.

It is difficult for:

  • Databases
  • Stateful systems
  • Downstream dependencies

To design correctly:

  1. Use asynchronous patterns where possible.
  2. Protect relational databases with RDS Proxy.
  3. Use IAM authentication instead of hardcoded credentials.
  4. Understand Lambda invocation types before designing workflows.
  5. Always design for backpressure and burst traffic.

Serverless is powerful — but only when architecture decisions support massive scale.

References:

Top comments (0)