Back to EC2 & Compute
Q6Question 6 of 7

RDS and How It Differs From Running a Database Yourself on EC2

Key Concepts
  • RDS is a managed relational database where AWS handles provisioning, backups, patching, failover, and replication.
  • Automated backups take daily snapshots and continuous transaction logs, enabling point-in-time recovery to any second.
  • Engine and OS patching is applied automatically during a maintenance window you choose.
  • Multi-AZ keeps a synchronous standby in another AZ and fails over automatically in about one to two minutes.
  • Read replicas are asynchronous copies for offloading read-heavy reporting from the primary instance.
  • Running a database on EC2 gives full OS and engine control but requires you to manage backups, patching, failover, and replication manually.
  • RDS trades some control for reliability and reduced operational burden, which is usually the right trade for banking workloads.

Definition

RDS is a managed relational database where AWS does backups, patching, failover, and replication for you, while a database on EC2 means you do all of that operational work yourself.
  • RDS (Relational Database Service) – A managed service that runs relational database engines (PostgreSQL, MySQL, MariaDB, Oracle, SQL Server) with automated operational tasks.
  • Automated Backups – Daily snapshots and continuous transaction log capture, enabling point-in-time recovery to any second within the retention window.
  • Multi-AZ – A synchronous standby replica in another Availability Zone with automatic failover, providing high availability with no code changes.
  • Read Replicas – Asynchronous copies of the primary that offload read-only queries, scalable within the same or other Regions.
  • Database on EC2 – A self-managed database installed on a virtual machine where you control everything but own all the operational burden.

Running a database on EC2 is like buying an empty building and doing everything yourself at National Bank of India: install the vault door, hire guards, arrange nightly backups to another location, patch the locks when a flaw is found, and if the building burns down, scramble to rebuild. RDS is like renting a fully managed vault from a specialist security firm: they install and maintain the door, take nightly backups automatically, patch the locks on schedule, keep a mirror vault in another building that takes over instantly if the first fails, and give you extra reading rooms so many clerks can read ledgers at once.

Understanding the Concepts

What is RDS?

Amazon RDS (Relational Database Service) is a managed service that runs relational database engines. You choose an engine (PostgreSQL, MySQL, MariaDB, Oracle, or SQL Server), an instance size, and storage, and AWS handles the heavy operational tasks. The core value is removing undifferentiated work so your team focuses on schema and queries instead of operations.

JAVA
import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.awssdk.services.rds.model.CreateDbInstanceRequest;

public class CreateLedgerDatabase {
    public static void main(String[] args) {
        RdsClient rds = RdsClient.create();
        rds.createDBInstance(CreateDbInstanceRequest.builder()
                .dbInstanceIdentifier("nbi-ledger")
                .engine("postgres")
                .engineVersion("15.4")
                .dbInstanceClass("db.r6g.large")     // memory optimized for DB
                .allocatedStorage(100)                 // 100 GB gp3
                .masterUsername("nbi_admin")
                .masterUserPassword("initial-password") // rotate immediately
                .multiAZ(true)                         // synchronous standby
                .storageEncrypted(true)                // encryption at rest
                .build());
        System.out.println("RDS instance creation initiated");
    }
}

How do automated backups work?

RDS takes daily snapshots and continuously captures transaction logs, giving point-in-time recovery so you can restore the database to any second within your retention window (up to 35 days). On EC2 you would script your own pg_dump or snapshot process, store and test them, and build your own point-in-time recovery, which is error-prone.

BASH
# Restore to a specific point in time (e.g., just before an accidental DELETE)
aws rds restore-db-instance-to-point-in-time \
  --source-db-instance-identifier nbi-ledger \
  --target-db-instance-identifier nbi-ledger-restored \
  --restore-time "2024-01-15T10:23:45Z"
# Creates a new instance restored to exactly that second

How does patching work in RDS vs EC2?

RDS applies engine minor-version and operating-system patches during a maintenance window you choose, so security fixes land without you building a patch pipeline. On EC2 you track CVEs, test patches, and apply them yourself – miss one and you have a known vulnerability.

TEXT
# RDS maintenance window configuration
Maintenance window: Sun:02:00-Sun:03:00 (IST, low traffic)
Auto minor version upgrade: enabled
# AWS patches the engine and OS during this window
# Application reconnects automatically after brief restart

# On EC2 you would need:
# 1. Monitor CVE announcements
# 2. Test patch in staging
# 3. Schedule downtime window
# 4. Apply patch manually
# 5. Verify database starts correctly
# 6. Monitor for regressions

How does Multi-AZ provide high availability?

With Multi-AZ, RDS keeps a synchronous standby replica in a different Availability Zone. Every committed write goes to both the primary and the standby before it is acknowledged, so the standby is always current. If the primary fails, RDS automatically fails over to the standby, usually in one to two minutes, and the application reconnects to the same DNS endpoint.

JAVA
public class MultiAZFailover {
    // The application connects to ONE endpoint
    static final String DB_URL =
            "jdbc:postgresql://nbi-ledger.abcdef.ap-south-1.rds.amazonaws.com:5432/ledger";

    // After a failover, the same DNS endpoint points to the promoted standby
    // No code change, no config change needed
    // Connection pool detects the brief outage and reconnects automatically

    // On EC2 you would need:
    // 1. Set up streaming replication manually
    // 2. Build a failover script (or use Patroni/pg_auto_failover)
    // 3. Manage DNS updates
    // 4. Test failover regularly
}

How do read replicas scale reads?

A read replica is an asynchronous copy you can send read-only queries to, offloading heavy reporting from the primary. You can have multiple replicas, in the same or other Regions. Replication lag is typically under a second.

JAVA
import java.sql.DriverManager;
import java.sql.Connection;

public class ReadReplicaRouting {
    // Primary endpoint for writes
    static final String WRITE_URL =
            "jdbc:postgresql://nbi-ledger.abcdef.ap-south-1.rds.amazonaws.com:5432/ledger";

    // Read replica endpoint for reporting
    static final String READ_URL =
            "jdbc:postgresql://nbi-ledger-replica.abcdef.ap-south-1.rds.amazonaws.com:5432/ledger";

    public static void main(String[] args) throws Exception {
        // Transfers write to primary
        Connection writeConn = DriverManager.getConnection(WRITE_URL, "transfer_app", "pass");

        // Month-end reports read from replica – no impact on live transfers
        Connection readConn = DriverManager.getConnection(READ_URL, "report_ro", "pass");
    }
}

How is RDS different from a database on EC2?

| Aspect | RDS (Managed) | Database on EC2 (Self-Managed) |
|---|---|---|
| Backups | Automated daily snapshots + continuous logs; point-in-time recovery | You script pg_dump, test restores, manage retention |
| Patching | Automated in maintenance window | You track CVEs, test, and apply manually |
| High Availability | Multi-AZ with automatic failover (checkbox) | You set up replication + failover scripting |
| Read Scaling | Read replicas with a click | You configure streaming replication manually |
| OS Access | No shell access | Full root/admin access |
| Engine control | Supported versions and parameter groups only | Any version, any extension, any tuning |
| Cost | Instance + storage + backup retention | Instance + storage + your operations team time |

JAVA
public class RDSvsEC2Decision {
    // Use RDS when:
    // - Standard engine version is sufficient
    // - You want automated backups, patching, failover
    // - You want to minimize operational burden

    // Use EC2 when:
    // - You need OS-level access or custom kernel tuning
    // - You need an unsupported engine version or extension
    // - You need full control over replication topology
}

What are common mistakes?

The first mistake is not enabling Multi-AZ for production databases. A single-AZ RDS instance means a hardware failure or AZ outage causes downtime. Multi-AZ adds cost but provides the automatic failover that banking requires.

The second mistake is using the master user for application connections. The master is for administration; create least-privilege users per service.

The third mistake is ignoring backup retention and restore testing. Having backups is useless if you have never tested restoring from them.

BASH
# Test a point-in-time restore quarterly
aws rds restore-db-instance-to-point-in-time \
  --source-db-instance-identifier nbi-ledger \
  --target-db-instance-identifier nbi-ledger-restore-test \
  --restore-time "2024-01-15T10:00:00Z"
# Verify data integrity on the restored instance
# Then delete the test instance

What about Aurora?

Amazon Aurora pushes the managed model further with a distributed storage layer. Aurora separates compute from storage, replicates data six ways across three Availability Zones, and provides faster failover (typically under 30 seconds) than standard RDS Multi-AZ. It is compatible with PostgreSQL and MySQL.

For banking workloads that need the highest availability and performance, Aurora is often the best choice within the managed-database spectrum.

DIAGRAM
# Aurora architecture
┌────────── Aurora Cluster ──────────┐
│                                     │
│  Writer Instance ──→ Shared         │
│  Reader Instance ──→ Distributed    │
│  Reader Instance ──→ Storage Layer  │
│                      (6 copies      │
│                       across 3 AZs) │
│                                     │
│  Failover: ~30 seconds              │
│  Standard RDS Multi-AZ: ~90 seconds │
└─────────────────────────────────────┘

What should a senior engineer know?

RDS trades some control for reliability. You cannot get OS shell access, you are limited to supported engine versions and parameters exposed through parameter groups, and very specialized tuning or unsupported extensions may force you onto EC2. For most banking workloads the reliability and reduced operational burden of RDS far outweigh that lost control.

A senior engineer also knows about RDS Proxy, which pools database connections to handle Lambda's connection-bursting pattern, and about cross-Region read replicas for disaster recovery. They right-size RDS instances using Performance Insights and CloudWatch, and they use encryption at rest with KMS and in-transit with SSL.

BASH
# Enable Performance Insights for query-level monitoring
aws rds modify-db-instance \
  --db-instance-identifier nbi-ledger \
  --enable-performance-insights \
  --performance-insights-retention-period 731  # 2 years for banking audit

Visual Overview

DIAGRAM
┌──────────── RDS vs EC2 Database ──────────────┐
│                                                │
│  RDS (Managed by AWS):                         │
│  ┌─────────────────────────────────────┐       │
│  │ You manage: Schema, Queries, Users   │      │
│  ├─────────────────────────────────────┤       │
│  │ AWS manages:                         │      │
│  │ ├── Automated backups (daily + logs) │      │
│  │ ├── Patching (maintenance window)    │      │
│  │ ├── Multi-AZ failover (automatic)    │      │
│  │ ├── Read replicas (one click)        │      │
│  │ ├── Encryption (KMS)                 │      │
│  │ └── Monitoring (Performance Insights)│      │
│  └─────────────────────────────────────┘       │
│                                                │
│  EC2 Database (Managed by you):                │
│  ┌─────────────────────────────────────┐       │
│  │ You manage: EVERYTHING               │      │
│  │ ├── OS installation and patching     │      │
│  │ ├── Engine installation and upgrades │      │
│  │ ├── Backup scripting and testing     │      │
│  │ ├── Replication setup                │      │
│  │ ├── Failover scripting               │      │
│  │ ├── Monitoring setup                 │      │
│  │ └── Security hardening               │      │
│  └─────────────────────────────────────┘       │
│                                                │
│  Multi-AZ Failover:                            │
│  Primary (AZ-a) ←──sync──→ Standby (AZ-b)     │
│       │                         │              │
│    failure                   promoted           │
│       └── DNS endpoint → now points to AZ-b    │
│           Application reconnects automatically  │
└────────────────────────────────────────────────┘

Key Takeaway

Amazon RDS is a managed relational database service. I pick an engine like PostgreSQL, an instance size, and storage, and AWS takes over the operational heavy lifting – provisioning, backups, patching, failover, and replication. The whole point is that it removes the undifferentiated work of running a database so my team can focus on schema and queries instead of operations.

The concrete differences from running a database myself on EC2 come down to four things. Automated backups: RDS takes daily snapshots and continuously captures transaction logs, giving me point-in-time recovery to any second in the retention window, whereas on EC2 I would script and test all of that myself. Patching: RDS applies engine and operating-system patches in a maintenance window I choose, whereas on EC2 I track and apply every patch by hand. Multi-AZ: RDS keeps a synchronous standby in another Availability Zone and fails over to it automatically in about ninety seconds, whereas on EC2 I would build my own replication and failover. And read replicas: RDS gives me asynchronous read-only copies to offload heavy reporting from the primary.

The trade-off, and the senior point I always raise, is control. With RDS I do not get operating-system shell access, I am limited to supported engine versions and the parameters exposed through parameter groups, and a very specialized or unsupported configuration can force me onto EC2. For the vast majority of banking workloads that lost control is well worth the reliability and reduced operational burden.

At National Bank of India I ran the core ledger on RDS PostgreSQL with Multi-AZ enabled. When an Availability Zone had an outage, RDS automatically promoted the synchronous standby and repointed the endpoint, and our transfer service reconnected within about ninety seconds with no code change and no data loss. I used read replicas for month-end reports and let RDS handle patching in a quiet maintenance window. Doing all of that manually on EC2 would have meant a full operations team and far more risk.

Remember one sentence: RDS does backups, patching, Multi-AZ failover, and read replicas for you, while a database on EC2 means you own all of that operational work yourself.

---

Share
Use ← → arrow keys to navigate