Skip to content

Databases

First PublishedByAtif Alam

AWS offers managed database services that handle provisioning, patching, backups, and replication — letting you focus on your application instead of database administration.

RDS runs managed relational databases. AWS handles the underlying infrastructure; you interact with it like a normal database.

EngineNotes
PostgreSQLOpen-source, feature-rich, widely used
MySQLOpen-source, popular for web apps
MariaDBMySQL fork, community-driven
OracleEnterprise, bring-your-own-license or license-included
SQL ServerMicrosoft, license-included or BYOL
AuroraAWS-built, MySQL/PostgreSQL-compatible, higher performance
TaskSelf-managed (EC2)RDS
OS patchingYouAWS
Database installationYouAWS
Automated backupsYouAWS (daily snapshots, transaction logs)
Multi-AZ failoverYouAWS (automatic)
Read replicasYouAWS (one-click)
MonitoringYouCloudWatch integration
Encryption at restYouOne checkbox
Terminal window
aws rds create-db-instance \
--db-instance-identifier my-postgres \
--db-instance-class db.t3.medium \
--engine postgres \
--engine-version 16.1 \
--master-username admin \
--master-user-password 'SecureP@ss123!' \
--allocated-storage 100 \
--storage-type gp3 \
--vpc-security-group-ids sg-db \
--db-subnet-group-name my-db-subnets \
--multi-az \
--backup-retention-period 7 \
--storage-encrypted
ClassTypeUse Case
db.t3.* / db.t4g.*BurstableDev/test, small workloads
db.m5.* / db.m6g.*General purposeProduction web apps
db.r5.* / db.r6g.*Memory-optimizedLarge datasets, caching
db.x2g.*Memory-intensiveSAP HANA, in-memory analytics

Multi-AZ creates a standby replica in a different AZ. If the primary fails, RDS automatically fails over to the standby — typically within 60–120 seconds.

Write/Read Sync replication
Client ──────► Primary (AZ-a) ──────────────► Standby (AZ-b)
(not accessible until failover)
  • Synchronous replication — zero data loss on failover.
  • Automatic failover — RDS updates the DNS endpoint; your app reconnects automatically.
  • Not a read replica — the standby doesn’t serve read traffic (use read replicas for that).

Read replicas offload read traffic from the primary. They use asynchronous replication — there’s a small lag.

Write Read
Client ──────► Primary ──────────► Read Replica 1 (same region)
│──────────► Read Replica 2 (same region)
└──────────► Read Replica 3 (cross-region)
FeatureMulti-AZRead Replica
PurposeHigh availability (failover)Read scaling
ReplicationSynchronousAsynchronous
Accessible for reads?No (standby only)Yes
Cross-region?NoYes
Can be promoted?Auto (on failure)Manual (becomes standalone DB)
FeatureAutomated BackupsManual Snapshots
ScheduleDaily (configurable window)On-demand
Retention1–35 daysIndefinite (until you delete)
Point-in-time restoreYes (any second within retention)To the snapshot time only
Cross-region copyYesYes
  • Network: Place in a private subnet. Only allow app security groups to connect.
  • Encryption at rest: Enable with KMS (cannot enable after creation — must be set at launch).
  • Encryption in transit: Use SSL/TLS connections (enforce with rds.force_ssl parameter).
  • IAM authentication: Use IAM roles instead of passwords (supported for MySQL and PostgreSQL).

Amazon Aurora is an AWS-built relational database that’s compatible with MySQL and PostgreSQL but offers higher performance and better availability.

FeatureRDS (PostgreSQL/MySQL)Aurora
PerformanceStandardUp to 5x MySQL, 3x PostgreSQL
StorageEBS (fixed, up to 64 TB)Auto-scaling (up to 128 TB), 6-way replicated
ReplicasUp to 5 read replicasUp to 15 read replicas (faster failover)
Failover60–120 seconds~30 seconds
CostLower~20% more than RDS

Aurora Serverless automatically scales capacity up and down based on demand — ideal for variable or unpredictable workloads:

No traffic ──► Scales to 0 ACUs (paused) ──► Traffic arrives ──► Scales up
  • Pay per ACU-second (Aurora Capacity Unit). Minimum 0.5 ACU for v2.
  • Good for: Dev/test, infrequent workloads, new apps with unknown traffic patterns.
  • Not ideal for: Steady high-traffic production (standard Aurora is cheaper).

DynamoDB is a fully managed NoSQL key-value and document database. It’s designed for single-digit millisecond latency at any scale.

┌──────────────────────────────────────────────┐
│ Table: Orders │
│ │
│ Partition Key (PK) Sort Key (SK) Attrs │
│ ───────────────── ────────────── ───── │
│ user_123 order_2026-001 {amt: 50}│
│ user_123 order_2026-002 {amt: 30}│
│ user_456 order_2026-001 {amt: 99}│
└──────────────────────────────────────────────┘
ConceptWhat It Is
TableA collection of items (like a relational table, but schema-less)
ItemA single record (like a row). Max 400 KB.
AttributeA field on an item (like a column). No fixed schema — items can have different attributes.
Partition key (PK)The primary key that determines which partition stores the item. Must distribute evenly.
Sort key (SK)Optional. Combined with PK to form a composite primary key. Enables range queries.
GSI (Global Secondary Index)An alternate key structure for querying by different attributes. Separate throughput.
LSI (Local Secondary Index)Same partition key, different sort key. Must be defined at table creation.
Terminal window
# Create a table
aws dynamodb create-table \
--table-name Orders \
--attribute-definitions \
AttributeName=user_id,AttributeType=S \
AttributeName=order_id,AttributeType=S \
--key-schema \
AttributeName=user_id,KeyType=HASH \
AttributeName=order_id,KeyType=RANGE \
--billing-mode PAY_PER_REQUEST
# Put an item
aws dynamodb put-item --table-name Orders --item '{
"user_id": {"S": "user_123"},
"order_id": {"S": "order_2026-001"},
"amount": {"N": "49.99"},
"status": {"S": "shipped"}
}'
# Get an item (by exact key)
aws dynamodb get-item --table-name Orders --key '{
"user_id": {"S": "user_123"},
"order_id": {"S": "order_2026-001"}
}'
# Query (all orders for a user)
aws dynamodb query --table-name Orders \
--key-condition-expression "user_id = :uid" \
--expression-attribute-values '{":uid": {"S": "user_123"}}'
ModeHow It WorksBest For
On-demandPay per request. No capacity planning.Unpredictable traffic, new tables
ProvisionedSet read/write capacity units (RCUs/WCUs). Can auto-scale.Predictable traffic (cheaper at scale)

Streams capture a time-ordered sequence of item changes (insert, update, delete). Use them to:

  • Trigger Lambda functions on data changes (event-driven architecture).
  • Replicate data to another table, Elasticsearch, or S3.
  • Build audit logs of all changes.

DynamoDB’s best practice is to store multiple entity types in a single table using overloaded partition and sort keys:

PK SK Attributes
USER#123 PROFILE {name: "Alice", email: "..."}
USER#123 ORDER#2026-001 {amount: 50, status: "shipped"}
USER#123 ORDER#2026-002 {amount: 30, status: "pending"}
PRODUCT#abc METADATA {name: "Widget", price: 9.99}
PRODUCT#abc REVIEW#user_123 {rating: 5, text: "Great!"}

This enables efficient queries with a single table — “get user profile + all orders” is one Query call.

RDSDynamoDB
ModelRelational (SQL)Key-value / document (NoSQL)
SchemaFixed schema (ALTER TABLE)Flexible (no schema enforcement)
QueriesAny SQL query (JOINs, aggregations)Key lookups and range queries only
ScalingVertical (bigger instance) + read replicasHorizontal (automatic partitioning)
LatencyLow millisecondsSingle-digit milliseconds
Best forComplex queries, transactions, relationshipsHigh-throughput, simple access patterns, serverless
PricingPer instance-hourPer request or provisioned capacity
ScenarioChoose
Complex SQL queries, JOINs, reportingRDS (or Aurora)
Simple key-value lookups at massive scaleDynamoDB
Relational data with ACID transactionsRDS
Serverless app (Lambda + API Gateway)DynamoDB (native integration, pay-per-request)
Unknown or rapidly changing schemaDynamoDB
Time-series data with simple queriesDynamoDB (or Timestream)
ServiceTypeUse Case
ElastiCacheIn-memory (Redis/Memcached)Caching, session storage, leaderboards
NeptuneGraph databaseSocial networks, fraud detection, knowledge graphs
TimestreamTime-seriesIoT, application metrics, DevOps monitoring
DocumentDBMongoDB-compatibleDocument workloads, MongoDB migration
KeyspacesCassandra-compatibleWide-column, high-throughput
RedshiftData warehouseAnalytics, BI, large-scale SQL queries
  • RDS manages relational databases (PostgreSQL, MySQL, Aurora). Use Multi-AZ for HA, read replicas for scale.
  • Aurora is AWS’s high-performance relational engine — faster than standard RDS, auto-scaling storage, more replicas.
  • DynamoDB is a NoSQL key-value store with single-digit ms latency. Design around access patterns, not relationships.
  • Use on-demand capacity for unpredictable workloads, provisioned for steady traffic.
  • Always encrypt at rest, place databases in private subnets, and restrict access via security groups.