LinuxUnity LinuxUnity

Posts / AWS Databases & Caching

Managing Databases on AWS: RDS, Aurora, and ElastiCache — Architecture and How They Work

An overview of AWS managed database services, covering Amazon RDS, Aurora, and ElastiCache, including their architecture, availability, scaling, storage, backups, encryption, and core operating principles.

02/04/2026 13 min read 8 views

Z Zedx

In this article

Introduction

In modern systems, database is a core component that directly affects performance and scalability. Instead of handling complex database operations yourself, the AWS Managed Database Services simplify management through features such as backup, scaling, and high availability.

AWS provides several database services, notably Amazon RDS, Amazon Aurora and Amazon ElastiCache, with each service suited to specific use cases.

For example, when you install a database on EC2 yourself, you have to handle everything: installation, OS patching, database engine patching, backup, replication, failover, monitoring, scaling… This is time-consuming and prone to errors.

Managed Database (RDS, Aurora, ElastiCache) — AWS handles most of the infrastructure:

Self-managed (EC2 + DB) AWS managed (RDS/Aurora)
Install the database engine ✅ AWS
OS patching ✅ AWS
Database engine patching ✅ AWS
Automated backup ✅ AWS
Multi-AZ replication ✅ AWS
Automatic failover ✅ AWS
Schema, queries, and data Customer
Security Group, IAM Customer
Encryption settings Customer

Evaluation: version cannot SSH into the RDS instance. There is no OS-level access.

In this article, we will provide an overview of managed databases on AWS, including their architecture, how they work, and the differences between these services.


Amazon RDS

RDS (Relational Database Service) is a managed service for popular relational database engines.

Supported engines

  • PostgreSQL
  • MySQL
  • MariaDB
  • Oracle
  • Microsoft SQL Server
  • Amazon Aurora (AWS’s proprietary engine — see section 3)

RDS Multi-AZ and High Availability

Multi-AZ is a feature HA (High Availability), not for read scaling.

high availability

How it works:

  • Every write on the Primary is synchronously replicated to the Standby before returning success
  • When the Primary fails, AWS automatically fails over (changes the DNS endpoint), and the Standby becomes the new Primary
  • Failover time: 1–2 minutes
  • The application does not need to change the connection string because the DNS endpoint automatically points to the new instance

RDS Read Replicas — Scale Reads

Read Replicas are used to increase read throughput, not for HA.

rds

Key features:

  • Replication lag asynchronous There may be lag replication lag
  • Maximum 15 Read Replicas (Aurora), 5 (RDS MySQL/PostgreSQL)
  • The application must proactively connect directly to the Read Replica endpoint
  • Can promote the Read Replica to a standalone DB (replication is lost)
  • Cross-region Read Replica: available data transfer cost

Typical use case:

database

  • You have a production database running under normal load
  • You want to run an additional Reporting application to perform analytics
  • Create a Read Replica to handle this new workload → without touching the Primary
  • production application is not affected at all
  • A Read Replica is used only for SELECT (read) — not for INSERT, UPDATE, or DELETE

RDS Backup

Automated Backups:

  • Enabled by default; daily backups run during the maintenance window
  • Transaction logs are stored every 5 minutes → enabling Point-in-Time Recovery to any second within the retention period
  • Retention: 1–35 days (default: 7 days)
  • Backups are stored in S3 (you cannot access them directly)

Manual Snapshots:

  • You trigger them manually at any time
  • Not deleted automatically → remain available even after the RDS instance is deleted
  • Can be copied to another Region and shared with another account

RDS Storage

RDS uses EBS storage the following types:

  • gp2/gp3: General-purpose SSD, suitable for most workloads
  • io1/io2: Provisioned IOPS, suitable when high, consistent IOPS are required (production-critical)
  • Magnetic: Legacy, not recommended

Storage Auto Scaling: Enable this feature in RDS to automatically increase storage when it is nearly full (no downtime required). Set Maximum Storage Threshold to control costs.

RDS Encryption

  • At rest: Uses AWS KMS. Must be enabled when creating the instance and cannot be enabled afterward for a running instance.
    • How to enable encryption for a running instance: Snapshot → Copy snapshot (enable encryption) → Restore from the encrypted snapshot
  • In transit: SSL/TLS — AWS provides the certificate; the application must be configured to use it

Amazon Aurora

Aurora is a proprietary database engine An AWS database compatible with MySQL and PostgreSQL, but rewritten from the ground up and optimized for the cloud.

Key differences between Aurora and RDS

Criteria RDS MySQL Aurora MySQL-compatible
Storage EBS, incremented manually Automatically scales up to 128 TB
Read Replicas Up to 5 Up to 15
Replication lag A few seconds < 10ms
Failover 1–2 minutes < 30 seconds
Multi-AZ 1 standby 6 copies across 3 AZs
Performance Baseline 5x MySQL, 3x PostgreSQL
Cost Lower ~20% higher than RDS

Aurora Storage Architecture

This is Aurora's most distinctive architecture:

  • 6 copies across 3 AZs ??? tolerates the loss of 2 copies without affecting writes and the loss of 3 copies without affecting reads
  • Storage type heal when corruption is detected
  • Auto-growing from 10GB in 10GB increments, up to 128TB

Aurora Endpoints

Aurora has several types of endpoints:

  • The client connects through two endpoints: Writer Endpoint always points to the Master to handle write operations, Reader Endpoint automatically load-balances read requests across multiple Reader instances (which can use Auto Scaling to increase or decrease capacity based on load).
  • All instances share a single Shared Storage Volume that automatically expands from 10 GB to 128 TB, ensuring data consistency without traditional replication.

Aurora Serverless

No need to provision capacity in advance—Aurora automatically scales ACUs (Aurora Capacity Units) based on traffic:

  • Aurora Serverless v2: Continuous scaling (without discrete steps), with faster scaling than v1
  • Use case: Unpredictable workloads, development/test environments, and applications with traffic spikes

Aurora Global Database

Cross-region replication with ??? latency < 1 second:

  • Disaster Recovery: Promote the secondary region to primary in < 1 minute
  • Reads closer to global users to significantly reduce latency

RDS Proxy

RDS Proxy is a fully managed database proxy between the application and RDS/Aurora.

Why do you need RDS Proxy?

The problem when Lambda (or ECS with many tasks) connects directly to RDS:

RDS Proxy features

  • Connection pooling: Maintains a connection pool to the database, reusing connections instead of creating new ones each time
  • Faster failover: RDS Multi-AZ failover through the Proxy is faster 66% than direct connections
  • IAM Authentication: Requires IAM authentication or Secrets Manager, eliminating the need to hardcode credentials
  • Not accessible from the internet: RDS Proxy is accessible only within the VPC (there is no public endpoint)
  • Supported: RDS MySQL, PostgreSQL, Aurora MySQL, PostgreSQL
text

text
# Application connect đến Proxy endpoint thay vì RDS endpoint
# Không cần đổi gì khác trong code

import pymysql
conn = pymysql.connect(
    host='my-proxy.proxy-xxx.rds.amazonaws.com',  # Proxy endpoint
    user='admin',
    password=get_secret(),  # Từ Secrets Manager
    database='mydb'
)

Amazon ElastiCache

Similar to RDS, it is a managed Relational Database service, ElastiCache is a managed service for in-memory cache and currently supports three engines: Valkey, Redis OSS, and Memcached (AWS added Valkey in 2024 as the preferred alternative to Redis OSS).

A cache is a database that stores data in RAM, enabling microsecond-level access—dozens of times faster than reading from disk. ElastiCache is suitable for two primary purposes: reducing the load on the primary database for read-heavy workloads, and making the application stateless by storing sessions externally.

AWS manages the entire infrastructure, including OS patching, optimization, configuration, monitoring, failover, and backups. However, note that: integrating ElastiCache requires changes to the application code —it is not a drop-in replacement; you must design the caching logic explicitly.

ElastiCache Solution Architecture – DB Cache

  • The application queries ElastiCache first. If data is available (cache hit), it is returned immediately without querying the database. If there is no (cache miss), the application queries RDS, retrieves the result, writes it to the cache, and then returns it to the user.
  • The main benefit is a significant reduction in the load on RDS, especially for repeated queries. However, the cache needs an invalidation strategy to automatically delete or update stale data in the cache when the database changes, preventing users from receiving outdated results.

ElastiCache Solution Architecture — User Session Store

  • This pattern enables the application to run in a statelessmanner. When a user logs in to any instance, the session is stored in ElastiCache. If the user is routed to another instance by the load balancer, that instance retrieves the session from ElastiCache and recognizes that the user is already logged in, without requiring another login.
  • This pattern is particularly important in auto-scaling environments, where instances may be replaced at any time.

5.3 ElastiCache — Redis vs. Memcached

Valkey / Redis OSS and Memcached based on the content you provided:

Criteria Valkey / Redis OSS Memcached
High Availability (HA) Supports Multi-AZ + Auto-Failover No built-in HA
Read Scaling Supports Read Replicas to scale reads Does not support replicas
Persistence Yes (AOF, snapshot) No (fully in-memory)
Backup & Restore Fully supported Not supported
Data Structures Rich: Strings, Sets, Sorted Sets, Hashes, Streams, etc. Simple key-value only
Vector Search Yes (Valkey 8.2+) Not supported
Sharding (Horizontal Scaling) Yes (cluster mode) Yes (simple native sharding)
Architecture More complex, with more features Simple and lightweight
CPU performance Primarily single-threaded (some components are multi-threaded) Multi-threaded and highly effective at utilizing multiple cores
Primary use cases Caching + data store + real-time features Simple pure caching with high performance
Flexibility High (supports many use cases) Low (caching only)

Conclusion

  • Choose Valkey / Redis OSS when you need a powerful, flexible system with HA, persistence, or advanced features.
  • Choose Memcached when you only need an extremely simple, fast cache optimized for CPU efficiency.

Pattern 1 — Lazy Loading / Cache-Aside

This is the most common pattern. The application loads data into the cache only when it is actually needed; it does not pre-populate the cache.

Advantages:

  • The cache contains only data that is actually used, with no unnecessary memory overhead.
  • A node failure does not crash the system; it only causes temporarily increased latency while the cache warms up again.

Disadvantages:

  • A cache miss results in three round trips: reading from the cache, reading from the database, and writing to the cache. The first request is always slower.
  • Data may become stale if the database is updated but the cache has not been invalidated.

Python pseudocode:

text

text
def get_user(user_id):
    # Bước 1: kiểm tra cache
    record = cache.get(user_id)

    if record is None:
        # Bước 2: cache miss → đọc từ DB
        record = db.query("select * from users where id = ?", user_id)
        # Bước 3: ghi vào cache cho lần sau
        cache.set(user_id, record)
        return record
    else:
        return record

# App code
user = get_user(17)

Pattern 2 — Write-Through

  • Whenever data is written to the DB, it is also written to the cache at the same time. The cache always reflects the database’s latest state.
  • Advantages:
  • Data in the cache never becomes stale
  • Reads are always fast because the cache always contains the latest data
  • Write penalty instead of Read penalty — users accept slightly slower writes in exchange for consistently fast reads
  • Disadvantages:
  • New data that has never been written before will not be present in the cache (missing data). Solution: combine it with Lazy Loading
  • Cache churn — a large amount of data is written to the cache but never read again, resulting in wasted resources
text

text
def save_user(user_id, values):
    # Bước 1: ghi vào DB
    record = db.query("update users ... where id = ?", user_id, values)
    # Bước 2: ghi vào cache
    cache.set(user_id, record)
    return record

# App code
user = save_user(17, {"name": "Nate Dogg"})

Cache Eviction vs. Time-to-Live (TTL)

  • Cache eviction occurs in 3 ways: manual deletion through code, automatic removal when memory is full according to the LRU (Least Recently Used) algorithm, or expiration when the TTL is reached.
  • TTL is a simple yet effective mechanism suitable for most types of data: leaderboards, comments, activity feeds, and search results. TTL can be set from seconds to days, depending on the application's tolerance for stale data.
  • If the system continuously experiences eviction due to insufficient memory, you need to scale up (use larger nodes) or scale out (add more nodes).

Best Practices

  • Lazy Loading is the baseline implementation, suitable for most cases, especially read workloads
  • Write Through combine it with Lazy Loading for important queries that require consistently fresh data
  • Always Set a TTL is a reasonable practice; the only exception is when using pure Write Through with a cache that is updated automatically
  • Cache only data that provides real value: user profiles, search results, blog content, and aggregations
  • Prefer Valkey if you are using Redis OSS to save 20–33% in costs; it is fully compatible and supports Vector Search starting with version 8.2

High-Level Comparison

Situation Solution
Relational database, low budget, simple requirements RDS (MySQL/PostgreSQL)
High performance requirements, horizontal scaling, managed service Aurora
Lambda + RDS, too many connections RDS Proxy
Reduce database read load with simple caching ElastiCache Memcached
Sessions, leaderboards, pub/sub, require persistence ElastiCache Redis
Cross-region disaster recovery, < 1s replication Aurora Global Database
Unpredictable traffic, development/testing Aurora Serverless v2

Multi-AZ vs. Read Replica

Multi-AZ Read Replica
Main purpose High Availability (HA) Scale reads
Replication Synchronous Asynchronous
Does the standby receive traffic? No Yes (reads only)
Automatic failover? Yes No (manual promotion)
Cross-region? No Yes
Cost 2x instance cost Additional instance cost

Conclusion

Using managed database significantly simplifies system operations, from ensuring availability and backing up data to scaling as the workload increases. Instead of focusing on infrastructure, you can spend more time developing and optimizing your applications.

Each solution has its own characteristics and trade-offs, making it suitable for different workload types and system architectures. Therefore, choosing the right technology depends not only on its features but also on the specific problem you are solving and how you design the overall system.

Understanding how these components work will help you make better decisions when building and operating systems in the cloud.