devHọc Dev

Week 2 - Day 3: RDS, Aurora and DynamoDB

Week 2 – Day 3

This lesson combines 3 topics: RDS Fundamentals, Amazon Aurora, DynamoDB Basics.

Learning Objectives

  • Understand RDS architecture and supported engines
  • Distinguish Multi-AZ vs Read Replicas
  • Master backup, snapshot, encryption
  • Know when to use RDS vs DynamoDB vs Aurora
  • Understand Aurora's unique architecture (6 storage copies)
  • Distinguish Aurora Provisioned vs Serverless v2
  • Master Aurora Global Database
  • Know Aurora endpoints and replication
  • Understand the DynamoDB data model: table, item, attribute
  • Distinguish Partition Key vs Composite Key
  • Master Provisioned vs On-Demand capacity
  • Understand Global Tables, DAX, Streams

Part 1: RDS Fundamentals

1. RDS Overview

Amazon RDS (Relational Database Service) = managed relational database service.

Supported Engines

  • MySQL
  • PostgreSQL
  • MariaDB
  • Oracle
  • SQL Server
  • Amazon Aurora (MySQL/PostgreSQL-compatible, AWS proprietary — details tomorrow)
  • IBM Db2 (added 2023)

RDS managed features

  • Automated provisioning, patching, backup
  • Monitoring (CloudWatch)
  • Multi-AZ high availability
  • Read replicas
  • Encryption at rest (KMS), in transit (TLS)
  • Maintenance windows
  • No SSH into the underlying EC2 (managed)

2. RDS Architecture

Single-AZ deployment

┌────VPC────────────┐│││┌────AZ-a────┐│││││││RDS││││(Primary)││││││││Storage││││(EBS)│││└──────────────┘│└──────────────────────┘
  • NOT HA — if the AZ fails, the DB is down
  • Dev/test environments

Multi-AZ deployment

┌────VPC────────────────────────────┐│││┌────AZ-a────┐┌────AZ-b────┐│││││││││Primary◄──┼──►Standby││││(Active)││(Syncrepl)││││││││││EBS││EBS│││└──────────────┘└───────────────┘│└───────────────────────────────────────┘
  • Synchronous replication from primary to standby
  • Automatic failover when the primary fails (~1-2 minutes)
  • DNS endpoint stays the same, the app reconnects automatically
  • Standby does not serve read traffic (HA backup only)
  • Double the cost (2 instances running)

Multi-AZ DB Cluster (new in 2022, MySQL & PostgreSQL)

  • 1 writer + 2 reader instances across 3 AZs
  • Readers can serve read traffic (unlike regular Multi-AZ)
  • Faster failover (~35s vs 1-2 minutes for regular Multi-AZ)
  • Higher cost (3 instances)

3. Read Replicas

Definition

Read Replica = a read-only copy of the primary DB, used to scale read workload.

Characteristics

  • Asynchronous replication from the primary
  • Has lag (usually a few seconds, can grow if the primary is busy)
  • Up to 15 read replicas per primary (MySQL/MariaDB/PostgreSQL/SQL Server — since 10/2022; Oracle: 5; Aurora: 15)
  • Can be promoted to a standalone DB (breaks replication)
  • Can be cross-region (CRR for RDS)
  • Can be cross-account (via snapshot copy)

Use cases

  • Scale read workload (reporting, analytics)
  • DR scenario (cross-region read replica → promote)
  • Migration (test new region with a replica before cutover)

Multi-AZ vs Read Replica

Multi-AZRead Replica
PurposeHAScale reads
ReplicationSynchronousAsynchronous
Serve readsNo (standby idle)Yes
FailoverAutoManual promote
AZDifferent AZSame/different AZ or Region
Cost impact2x+1x per replica

Cross-Region Read Replica

  • Replicate to another Region
  • Cross-region data transfer charges apply
  • Use case: DR, regional read scaling

4. RDS Storage

Volume types

  • gp3 (new default): General SSD
  • gp2 (legacy): General SSD tied to size
  • io1: Provisioned IOPS SSD
  • Magnetic (legacy, deprecated)

Storage scaling

  • Storage Autoscaling: grows automatically when needed (max threshold set by you)
  • Modify storage: increase manually anytime (no downtime)
  • Cannot decrease (requires dump + restore into a new DB)

Maximum storage

  • MySQL, MariaDB, PostgreSQL, Oracle: up to 64 TiB
  • SQL Server: up to 16 TiB
  • Note: since 12/2025, Oracle/SQL Server can go up to 256 TiB with additional storage volumes (details out of exam scope)

5. RDS Backup

Automated Backups

  • Daily full backup + continuous transaction logs
  • Retention 0-35 days (default 7 days)
  • Stored in S3 (managed by AWS)
  • Point-in-Time Recovery (PITR): restore to any second within retention
  • Deleted automatically when the DB is deleted (unless you take a manual snapshot first)

Manual Snapshots

  • User-initiated, retain indefinitely until deleted
  • Cross-region copy support
  • Cross-account share (via KMS key sharing if encrypted)
  • Use for backup before a major change, retain beyond 35 days

Restore process

  • Restore from backup/snapshot = creates a new DB instance (no in-place restore)
  • New endpoint → app must be updated
  • Can restore to a point-in-time (5-minute granularity)

Database Cloning (Aurora only)

  • Fast clone of an Aurora cluster (copy-on-write)
  • Use case: test environment with production data

6. RDS Encryption

At Rest

  • KMS encryption (CMK)
  • Applied at instance creation (CANNOT be enabled later)
  • Covers: storage, backups, snapshots, read replicas

Encrypt unencrypted RDS

  1. Create snapshot
  2. Copy snapshot with encryption enabled
  3. Restore DB from encrypted snapshot
  4. Migrate apps to new endpoint
  5. Delete old DB

In Transit

  • TLS/SSL connection
  • Engines support: MySQL, PostgreSQL, MariaDB, Oracle, SQL Server
  • Download the CA cert from AWS, configure the client

Transparent Data Encryption (TDE)

  • Oracle, SQL Server only
  • Database-level encryption (additional layer)

7. RDS Security

Network Isolation

  • Deploy in a VPC, private subnet
  • Security Group controls access port (3306, 5432, ...)
  • Do not expose publicly unless absolutely needed

IAM Database Authentication

  • MySQL & PostgreSQL only
  • Use IAM tokens (15-min lifetime) instead of passwords
  • No password management

Database Activity Streams (Oracle, SQL Server, PostgreSQL, MySQL)

  • Real-time stream of activity logs to Kinesis
  • Audit trail for compliance

Audit logs

  • Engine-specific audit logs sent to CloudWatch Logs

8. RDS Performance

Performance Insights

  • Visualize DB load and top queries
  • Free (with retention 7 days)
  • Paid (long-term retention)

Enhanced Monitoring

  • OS-level metrics (CPU per process, memory)
  • Granularity 1-60 sec
  • Costs $$ (CloudWatch logs)

Slow Query Logs

  • Engine-specific
  • Identify slow queries
  • Export to CloudWatch Logs

Instance class selection

  • db.t3/t4g: burstable, dev/test
  • db.m5/m6: general-purpose production
  • db.r5/r6: memory-optimized (in-memory cache, complex queries)
  • db.x2: high-memory (SAP HANA, in-memory analytics)

9. RDS Maintenance

Maintenance Window

  • Weekly time slot (30 min) for AWS to apply patches
  • Configurable (e.g., Sunday 3-3:30 AM)
  • Minor version auto-applied; Major version manual

Engine Version Upgrade

  • Minor upgrade: auto during maintenance window (configurable)
  • Major upgrade: manual (e.g., MySQL 5.7 → 8.0)
  • Test in staging first

10. RDS Proxy

Definition

RDS Proxy = a managed connection pooler between the app and RDS.

Benefits

  • Connection pooling: many app connections share fewer DB connections
  • Failover faster: 60-70% reduction in failover time
  • Serverless-friendly: Lambda (each cold start opens a new connection) puts load on the DB
  • IAM auth integration

Use case

  • Lambda → RDS (avoid connection storms)
  • Apps with connection spikes
  • Faster failover for HA

Cost

  • $/vCPU-hour of proxy capacity

11. RDS vs Aurora vs DynamoDB (quick comparison)

RDSAuroraDynamoDB
TypeRelationalRelational (MySQL/PG compat)NoSQL (key-value, document)
ManagedYesYes (more so)Yes
Multi-AZStandby (idle)6 copies across 3 AZsAuto multi-AZ
Read scalingRead replicas (15; Oracle 5)Read replicas (15)Auto
PerformanceStandard3-5x MySQLSingle-digit ms
CostLowerHigherPay-per-use or provisioned
Use caseTraditional RDBHigh-perf RDBNoSQL, high-scale

12. RDS Connection Patterns

Pattern 1: Single-AZ with Snapshots

  • Dev/test
  • Daily snapshots
  • Cheap

Pattern 2: Multi-AZ Production

  • HA primary + standby
  • Automated failover
  • Standard production

Pattern 3: Multi-AZ + Read Replicas

  • Write to primary
  • Read traffic to replicas
  • Reporting workload separate

Pattern 4: Cross-Region DR

  • Primary in Region A
  • Cross-region read replica in Region B
  • Promote replica in DR scenario

Part 2: Amazon Aurora

1. Aurora Overview

Amazon Aurora = an AWS proprietary relational database, MySQL & PostgreSQL compatible.

Unique characteristics

  • Performance: 5x faster than MySQL, 3x faster than PostgreSQL (according to AWS)
  • Storage: Auto-scaling 10 GB → 128 TB
  • Replication: 6 copies of data across 3 AZs (built-in HA)
  • Failover: < 30 seconds (vs 1-2 minutes for RDS Multi-AZ)
  • 15 read replicas (RDS is also 15 since 10/2022, except Oracle at 5)
  • Continuous backup to S3 (no perf impact)
  • Database cloning (copy-on-write, instant)

Cost

  • ~20% more expensive than RDS standard
  • Trade-off: significantly better performance + features

2. Aurora Storage Architecture

6 copies across 3 AZs

┌───────────AZ-1───────────┐│StorageNode1││StorageNode2│Quorum:4/6forwrite└────────────────────────────┘Quorum:3/6forread▲│syncreplication│┌───────────AZ-2───────────┐│StorageNode3││StorageNode4│└────────────────────────────┘▲│┌───────────AZ-3───────────┐│StorageNode5││StorageNode6│└────────────────────────────┘

Self-healing

  • Continuous scanning, auto-repair corrupted blocks
  • Losing up to 2 copies still allows writes (write quorum 4/6); losing up to 3 copies still allows reads (read quorum 3/6)
  • AZ failure → no data loss, no write disruption

Storage cluster volume

  • Shared storage volume
  • All compute instances (writer, readers) read the same storage
  • → Failover does not require copying data

3. Aurora Cluster Architecture

┌──────────────────────────┐│AuroraCluster│││Appwrite─►│WriterInstance││(Primary)││││││writes││▼││┌──────────────────┐│││SharedStorage││││(6copies,3AZ)│││└──────────────────┘││▲▲▲│││││││ReaderReaderReader││(R/O)(R/O)(R/O)│└──────────────────────────┘▲│Appreads

Components

  • Writer (Primary) Instance: handles writes
  • Reader Instances: serve reads, up to 15
  • Shared Storage: replicated 6 copies

Failover

  • Auto-promote reader → writer (< 30s)
  • Failover priority: configurable per reader (tier 0-15, lower wins)
  • DNS endpoint updates → app reconnects

4. Aurora Endpoints

4 types of endpoints

EndpointPurpose
Cluster Endpoint (Writer)Always points to primary, for write workload
Reader EndpointLoad-balance reads across all reader instances
Custom EndpointSubset of instances (e.g., reporting subset)
Instance EndpointSpecific instance (rarely used)

Example

my-cluster.cluster-xxx.us-east-1.rds.amazonaws.com           ← Writer
my-cluster.cluster-ro-xxx.us-east-1.rds.amazonaws.com        ← Reader (LB)
my-cluster.cluster-custom-xxx.us-east-1.rds.amazonaws.com    ← Custom
instance-1.xxx.us-east-1.rds.amazonaws.com                   ← Specific

5. Aurora Replication

Read Replicas (within Region)

  • Auto-scale 0-15 replicas
  • Async replication (sub-10ms lag typical)
  • Same shared storage → faster than RDS read replica
  • Reader endpoint load-balances

Aurora Global Database (Cross-region)

  • 1 primary region + up to 10 secondary regions (old limit: 5 — the exam may still use it)
  • Sub-second replication lag (much better than CRR)
  • Read-only replicas in secondary regions
  • Disaster recovery: promote secondary → primary in < 1 minute (RTO)
  • RPO < 1 second
Use case
  • Multi-region applications
  • DR with low RTO/RPO
  • Read scaling globally

Aurora Global Database Architecture

PrimaryRegion(us-east-1):├──Writerinstance──►writes└──Upto15readerinstances││Aurorareplication(sub-second)│▼SecondaryRegion(eu-west-1):└──Upto16read-onlyinstances└──Disaster:promote→becomenewprimary

Write Forwarding (Global Database)

  • Reader instance in secondary region can forward writes to primary
  • App treats secondary as local writer (with latency penalty)
  • Use case: multi-region writes without app complexity

6. Aurora Serverless v2

Definition

Aurora Serverless v2 = on-demand auto-scaling Aurora, scales instantly from 0 ACU to 256 ACU.

Characteristics

  • ACU (Aurora Capacity Unit): 2 GiB memory + CPU + networking
  • Min: 0 ACU with auto-pause (since 11/2024; previously min 0.5 ACU, no scale to zero)
  • Max: configurable up to 256 ACU (raised from 128 in late 2024)
  • Scale in seconds (vs minutes for Provisioned)
  • Pay per ACU-hour consumed

v1 vs v2

Aurora Serverless v1Aurora Serverless v2
ScaleSlow (minutes), pauses to 0Fast (seconds), scale to 0 with auto-pause (since 11/2024)
EngineMySQL 5.7, PostgreSQL 10MySQL 8, PostgreSQL 13+
Read replicasNoYes (up to 15)
Multi-AZNoYes
StatusDeprecated, removingCurrent (recommended)

Use case Serverless v2

  • Unpredictable workload
  • Intermittent traffic (dev/test, occasional spikes)
  • Multi-tenant apps with variable load
  • New app where size unknown

Use case Provisioned

  • Predictable steady workload
  • Cost-conscious (Reserved Instance discount)

7. Aurora Backup

Automated Backup

  • Continuous backup to S3 (no impact on performance)
  • Retention 1-35 days
  • PITR to any second within retention

Manual Snapshots

  • User-initiated, kept until deleted
  • Cross-region copy
  • Cross-account share

Database Cloning

  • Copy-on-write clone of cluster
  • Instant (no data copy initially)
  • Storage diverges as clones change
  • Use case: dev/test with prod data, what-if analysis
  • Cost: only diverged blocks

8. Aurora Backtrack (MySQL-compatible only)

Definition

"Undo" cluster to previous point in time without restoring from backup.

Characteristics

  • Max backtrack window: 72 hours
  • Fast (no restore involved)
  • In-place operation (no new cluster)
  • Cost: $/hour of backtrack window enabled

Use case

  • "Oops, I dropped wrong table" — backtrack 5 minutes
  • A/B testing rollback
  • Faster than restore from snapshot

9. Aurora Auto Scaling (Read Replicas)

Features

  • Auto-scale number of read replicas based on:
    • Average CPU utilization
    • Average connections
  • Min/Max settings

Setup

Aurora Auto Scaling Policy:
  Target Metric: AverageCPUUtilization
  Target Value: 60%
  Min Replicas: 1
  Max Replicas: 8

10. Aurora Machine Learning Integration

Features

  • Aurora MySQL/PostgreSQL invokes SageMaker or Comprehend from SQL
  • Real-time inference in DB query
  • Use case: fraud detection, sentiment analysis inside a query
SELECT product, predict_fraud(product, user_id, amount)
FROM transactions;

11. Cost Comparison Examples

Single-AZ RDS MySQL db.r5.large (16 GB RAM)

  • ~$0.24/hour = $176/month

Aurora MySQL db.r5.large (1 writer + 1 reader Multi-AZ)

  • ~$0.29/hour × 2 = ~$420/month
  • Storage: $0.10/GB-month (vs $0.115 for RDS gp3)

Aurora Serverless v2 (1-4 ACU average)

  • ~$0.12/ACU-hour × 2 avg × 730 hrs = $175/month
  • Pay only what you use

12. RDS vs Aurora Decision

Workload?│├──Heavyreadscaling(>5replicasneeded)│└──Aurora(upto15)│├──Need<30sfailover│└──Aurora│├──Multi-regionwithsub-secondRPO│└──AuroraGlobalDatabase│├──Variable/unpredictableload│└──AuroraServerlessv2│├──NeedMySQL/PostgreSQLspecifically(notOracle,SQLServer)│└──Aurora(compatible+faster)│├──NeedOracle/SQLServer│└──RDS(Auroradoesnotsupportthem)│├──Cost-sensitive,lowworkload│└──RDSSingle-AZ│└──Standardproduction,predictable└──RDSMulti-AZorAurora(dependson$)

Part 3: DynamoDB Basics

1. DynamoDB Overview

Amazon DynamoDB = fully managed NoSQL key-value & document database.

Characteristics

  • Serverless: no servers to manage
  • Single-digit ms latency at any scale
  • Auto-scaling: handle millions of requests/sec
  • Multi-AZ replication built-in (3 copies)
  • NoSQL: no schema, flexible structure
  • HTTP API (no JDBC/connection-based)
  • Encryption at rest by default

Use cases

  • High-traffic web/mobile apps
  • Gaming leaderboards
  • IoT data ingestion
  • Real-time bidding
  • Shopping carts
  • Session storage
  • User profiles

Not for

  • Complex JOIN queries (NoSQL)
  • Strong relational integrity needs
  • Ad-hoc queries (need to design access patterns upfront)
  • BI / analytics (use Redshift)

2. Data Model

Hierarchy

Table├──Item(=rowinSQL)│├──Attribute(=column)││├──Name││└──Value(scalar,list,map,set)│└──...└──...

Example

Table: Users

Item 1:
{
  "UserId": "u-001",       // Partition Key
  "Name": "Alice",
  "Email": "alice@example.com",
  "Age": 30,
  "Interests": ["coding", "music"]    // List attribute
}

Item 2:
{
  "UserId": "u-002",
  "Name": "Bob",
  "Email": "bob@example.com",
  "Age": 25
  // Note: no "Interests" — schema-less!
}

Attribute types

  • Scalar: String, Number, Binary, Boolean, Null
  • Set: String Set, Number Set, Binary Set
  • Document: List, Map (nested structure)

Max sizes

  • Item size: 400 KB
  • Attribute name: 64 KB
  • Partition key: 2048 bytes (string), 38 bytes (number)
  • Sort key: 1024 bytes

3. Primary Key

2 types

Simple Primary Key (Partition Key only)
  • 1 attribute uniquely identifies item
  • Hash function distributes items across partitions
PrimaryKey:UserId└──u-001└──u-002└──u-003
Composite Primary Key (Partition Key + Sort Key)
  • Partition Key + Sort Key combination must be unique
  • Items with the same PK grouped together, sorted by SK
PrimaryKey:UserId+OrderIdItems:├──(u-001,order-100)├──(u-001,order-101)←Sameuser,differentorder├──(u-001,order-102)├──(u-002,order-200)└──(u-002,order-201)

Partition Key best practice

  • High cardinality (many distinct values) → spread evenly
  • Avoid hot partitions: don't use timestamp/sequential as PK
  • Common patterns: UserId, ProductId, SessionId, UUID

4. Read/Write Capacity Modes

Provisioned Capacity

  • Specify RCU (Read Capacity Units) and WCU (Write Capacity Units)
  • Pay for capacity reserved
  • Auto-scaling available (scale RCU/WCU based on utilization target)
Capacity calculation
  • 1 WCU = 1 write/sec for item up to 1 KB
    • Transactional write: 2 WCU per write
  • 1 RCU = 1 strongly-consistent read/sec for item up to 4 KB
    • Eventually consistent: 2 reads/sec per RCU
    • Transactional read: 2 RCU per read
Use case
  • Predictable traffic
  • Cost-optimization (Reserved Capacity option)

On-Demand Capacity

  • Pay per request ($/million reads, $/million writes)
  • No capacity planning — auto-handle any traffic
  • More expensive per request than provisioned
  • Instant scale (no need to provision)
Use case
  • Unpredictable traffic
  • New apps where traffic unknown
  • Spiky traffic (0 → millions in seconds)

Switching between modes

  • Provisioned → On-Demand: up to 4 times per rolling 24 hours; On-Demand → Provisioned: any time (older materials: once every 24 hours)

5. Read Consistency Models

Eventually Consistent (default)

  • Read might return stale data (latest update not propagated yet)
  • Faster, cheaper
  • Lag typically < 1 second

Strongly Consistent

  • Read returns latest data (after writes)
  • Slower (higher latency)
  • 2x cost in RCU

When to use Strongly Consistent

  • Read after write must see update (e.g., post-payment check)
  • Financial transactions
# boto3 example
table.get_item(
    Key={'UserId': 'u-001'},
    ConsistentRead=True   # ← strongly consistent
)

6. Indexes

Local Secondary Index (LSI)

  • Same partition key as base table, different sort key
  • Created at table creation, cannot add later
  • Max 5 LSIs per table
  • Uses base table's capacity
Use case
  • Different sort orders for same PK
  • E.g., Orders sorted by date, by amount

Global Secondary Index (GSI)

  • Different partition key (and optional different sort key)
  • Can create anytime (no downtime)
  • Max 20 GSIs per table
  • Own provisioned capacity (separate RCU/WCU)
  • Eventually consistent only
Use case
  • Query by non-PK attribute
  • E.g., Users by Email (PK is UserId)

Example

Base Table:
PK: UserId, SK: OrderId

LSI:
PK: UserId, SK: OrderDate   ← same PK, different SK

GSI:
PK: ProductId, SK: OrderId  ← different PK

7. DynamoDB Streams

Definition

Streams = ordered log of item changes (insert, modify, delete) in table.

Characteristics

  • 24-hour retention
  • Near real-time (< 1 sec lag)
  • Enable per table
  • Compatible with Kinesis Data Streams (newer)

View types

  • KEYS_ONLY: only key attributes
  • NEW_IMAGE: entire new item
  • OLD_IMAGE: entire old item
  • NEW_AND_OLD_IMAGES: both

Use cases

  • Trigger Lambda on changes (CDC pattern)
  • Replicate to other databases
  • Audit trail
  • Aggregations / analytics
  • Notifications (SNS on item change)

8. DAX (DynamoDB Accelerator)

Definition

DAX = fully managed in-memory cache for DynamoDB, microsecond latency for reads.

Characteristics

  • Write-through cache: writes go through DAX to DynamoDB
  • 10x performance for cached reads
  • Compatible with DynamoDB API (no code change)
  • Multi-AZ cluster
  • TTL configurable (5 min default)

When to use DAX

  • Read-heavy workload (>80% reads)
  • Repeated reads of same items
  • Need sub-millisecond response

When NOT to use DAX

  • Write-heavy
  • Eventually consistent reads are fine with regular DynamoDB
  • Strongly-consistent reads (DAX is eventually consistent)

Cost

  • DAX cluster (1 primary + readers): ~$0.04/hour per node

9. Global Tables

Definition

Global Tables = multi-region, multi-active replication for DynamoDB.

Characteristics

  • Active-active: write to ANY region, replicated to all others
  • Sub-second replication lag (typical)
  • Conflict resolution: last writer wins (based on timestamp)
  • Requires Streams enabled
  • Cost: charged per region capacity + cross-region data transfer

Use case

  • Multi-region apps with low-latency for global users
  • DR (any region can become primary)
  • Compliance (data in multiple regions)

Architecture

RegionA(us-east-1)◄────►RegionB(eu-west-1)││└────►RegionC(ap-southeast-1)(writetoany,replicatetoall)

10. DynamoDB Backups

Continuous Backup (PITR - Point in Time Recovery)

  • Enable per table
  • Restore to any second in last 35 days
  • No performance impact
  • Cost: $0.20/GB-month

On-Demand Backup

  • User-initiated full backup
  • Retain indefinitely
  • No performance impact
  • Used for compliance, long-term archive

Restore

  • Always restore to new table (cannot in-place)
  • Includes indexes (LSI, GSI), provisioned capacity, encryption settings

11. DynamoDB Transactions

ACID transactions

  • Up to 100 actions per transaction
  • Up to 4 MB data
  • Works across multiple tables in same region
  • 2x RCU/WCU cost vs regular reads/writes

Operations

  • TransactWriteItems: atomic write to 1+ items
  • TransactGetItems: atomic read of 1+ items

Use case

  • Financial transfers (debit + credit atomically)
  • Order processing (inventory + payment + confirmation)
  • Anything requiring "all or nothing"

12. TTL (Time to Live)

Definition

TTL = auto-delete items at specified expiry time.

Setup

  • Designate an attribute (e.g., ExpiresAt = epoch timestamp)
  • DynamoDB checks periodically (within 48 hours of expiry)
  • Free operation (no WCU charge)

Use case

  • Session storage (auto-cleanup expired sessions)
  • Temporary data (cache, logs)
  • Compliance (auto-delete old data)

Review Questions

  1. Does a Multi-AZ standby serve read traffic?

    Show answer

    No — the RDS Multi-AZ standby is a pure failover target and does not serve read traffic. The standby syncs synchronously from the primary, guaranteeing zero data loss on failover. To scale reads you need Read Replicas (replicate asynchronously, can be cross-Region, and can be promoted to standalone). Failover usually completes in 60-120 seconds — the Route 53 CNAME is updated.

  2. What is the maximum number of read replicas per RDS primary?

    Show answer

    15 read replicas per RDS primary instance for MySQL, MariaDB, PostgreSQL, SQL Server (raised from 5 to 15 in 10/2022); Oracle alone is still 5. Each read replica can have its own read replicas (cascading). Aurora supports up to 15 read replicas per cluster. Read Replicas can be cross-Region — supporting geographic distribution and DR.

  3. What is the difference between an automated backup and a manual snapshot?

    Show answer

    Automated backup: retention 1-35 days, deleted automatically when the retention period ends or when the DB instance is deleted, enables point-in-time recovery (PITR). Manual snapshot: retained forever until you delete it manually, even after the DB is deleted. Use a manual snapshot before a major upgrade, before deleting a DB, or when you need backups longer than 35 days.

  4. What steps are needed to encrypt an RDS instance that is running unencrypted?

    Show answer

    You cannot encrypt it directly. You must: (1) Create a snapshot of the unencrypted instance, (2) Copy the snapshot with encryption (choose a KMS key), (3) Restore from the encrypted snapshot into a new DB instance, (4) Update the application's connection string. Optional: delete the old DB after verifying. Downtime = restore time (you can use a read replica to reduce downtime).

  5. What problem does RDS Proxy solve for Lambda?

    Show answer

    Connection pooling. Lambda functions are stateless and scale rapidly — each Lambda invocation can open a new DB connection, causing connection exhaustion when thousands of Lambdas run concurrently (RDS max connections is limited). RDS Proxy maintains a connection pool to the DB, and Lambda connects to the Proxy — the Proxy multiplexes many Lambda connections over few actual DB connections. It also improves failover time (failover is handled in the Proxy, Lambda does not see it).

  6. How many copies does Aurora replicate data into, across how many AZs?

    Show answer

    Aurora automatically replicates data into 6 copies across 3 AZs (2 copies/AZ). A write needs only 4/6 copies to acknowledge; a read needs 3/6. The shared storage volume self-heals — losing 2 copies still allows writes, losing 3 copies still allows reads. This is why Aurora has higher durability and availability than standard RDS Multi-AZ.

  7. What is the Aurora Global Database RTO on failover?

    Show answer

    < 1 minute (usually under 1 minute, no more than 1 minute). Aurora Global Database replication lag is usually < 1 second. Managed failover (promote secondary region to primary): under 1 minute. Unplanned failover (primary region fails): about 1 minute. Comparison: RDS Multi-AZ failover is 60-120s, but within the same Region.

  8. Can Aurora Serverless v2 scale to zero?

    Show answer

    Yes — since 11/2024, Aurora Serverless v2 supports scale to 0 ACU with auto-pause (set min capacity = 0); it resumes automatically when a connection arrives (with a cold start of a few seconds). Before 11/2024, the min was 0.5 ACU and it did not scale to 0 — older exams/materials may still say so. The max is currently 256 ACU. Aurora Serverless v1 (legacy, deprecated) could also pause to 0 but scaled much more slowly.

  9. What is the maximum Aurora Backtrack window?

    Show answer

    72 hours (3 days) maximum backtrack window. Backtrack lets you "rewind" an Aurora cluster to any point within that window — no snapshot restore needed (much faster, usually a few minutes). Supported only for MySQL-compatible Aurora, not PostgreSQL. Useful when you discover data corruption or an accidental delete within 72 hours.

  10. What is the difference between the Cluster Endpoint and the Reader Endpoint?

Show answer

Cluster Endpoint (Writer Endpoint): always points to the primary instance — used for write operations. It automatically fails over to the new primary on a failover event. Reader Endpoint: load balances reads across all read replicas — used for read-only queries. You do not need to know each replica's IP/hostname. Aurora also provides custom endpoints to route traffic to a subset of replicas for specific workloads.

  1. What is the maximum DynamoDB item size?
Show answer

400 KB per item. If you need to store larger data (images, files), store it in S3 and keep only the S3 key in the DynamoDB item. Table size is unlimited; only item size is limited. Attribute names also count toward item size — use short names to optimize storage and RCU/WCU.

  1. What is the core difference between a GSI and an LSI?
Show answer

LSI (Local Secondary Index): uses the same Partition Key but a different Sort Key — can only be created at table creation, cannot be added later. Shares throughput with the base table. GSI (Global Secondary Index): has a completely different Partition Key — can be created/deleted at any time. Has its own throughput (provisioned separately or on-demand). Maximum 5 LSIs and 20 GSIs per table.

  1. 1 strongly consistent RCU = how many reads/sec for a 4 KB item?
Show answer

1 read/second for an item up to 4 KB with strong consistency. Eventually consistent read: 2 reads/sec for a 4 KB item (double). Larger items: 1 strongly consistent RCU = 1 read/4 KB — an 8 KB item needs 2 RCUs, a 1 KB item needs 0.5 RCU (rounded up = 1 RCU). Transactional reads consume 2 RCUs per read.

  1. Is DAX suited for read-heavy or write-heavy workloads?
Show answer

Read-heavy. DAX (DynamoDB Accelerator) is an in-memory cache for DynamoDB — it reduces read latency from milliseconds to microseconds and reduces RCU consumption. It is not suited for write-heavy workloads because write-through DAX still has to write to DynamoDB. It is also not suited when the application needs strongly consistent reads (DAX is eventually consistent only) or when data changes constantly (low cache hit rate).

  1. What is the Global Tables conflict resolution?
Show answer

DynamoDB Global Tables use "last writer wins" (LWW) with timestamps. If the same item is written in two Regions at the same time, the write with the latest timestamp (by wall clock) wins. AWS recommends designing applications to avoid conflicts: assign a primary region to each user/tenant, or use conditional writes with a version counter. There is no built-in CRDT or merge logic.

Hands-on Exercises

Part 1: RDS Fundamentals

  • Create an RDS MySQL db.t3.micro Single-AZ, enable backup 7 days
  • Modify → enable Multi-AZ, observe failover behavior (force reboot with failover)
  • Create a Read Replica in the same AZ and cross-region
  • Test PITR: restore DB to 1 hour ago
  • Enable Performance Insights, observe top queries
  • Set up RDS Proxy for Lambda integration

Part 2: Amazon Aurora

  • Create an Aurora MySQL cluster with 1 writer + 1 reader
  • Test failover: force reboot writer, observe < 30s failover
  • Create an Aurora Serverless v2 cluster with 0.5-4 ACU, observe scaling
  • Set up Aurora Global Database (1 primary region + 1 secondary)
  • Test database cloning: clone production cluster, modify clone
  • Backtrack the cluster to 5 minutes ago

Part 3: DynamoDB Basics

  • Create a DynamoDB table with composite PK (UserId + OrderId), On-Demand capacity
  • Insert 100 items, query by PK
  • Add a GSI to query by Email
  • Enable Streams, create a Lambda trigger that logs changes
  • Enable PITR, test restore to 1 hour ago
  • Enable Global Tables across 2 regions, test writing from region B

References


Next lesson →