Compute, storage and databases

EC2, ECS on Fargate, EKS, S3 with presigned URLs, and RDS with Multi-AZ, backups and parameter groups.

17 min read☁️ AWS for Backend Engineers

Three questions a service asks of the cloud: where does the JVM run, where do the files go, and where is the database. AWS has several answers to each, and the interesting part is not the product names but the operational trade each one makes — what you stop having to do, and what you stop being able to do.

Compute: EC2, ECS, EKS, and where a JVM belongs

EC2 is a virtual machine. You choose an instance type (m6g.large is family, generation and size), an AMI (the machine image), a subnet, a security group, and an instance profile that gives it a role. It is this repository's production host in a different data centre: a JVM under systemd, nginx in front, and you own the OS.

The operational weight is yours: patching, the unit files, the disk and the backup timer. Everything the CI/CD course's Linux lesson covered applies. EC2 is the right answer for one or two services on a small team, and for anything with a licensing or hardware constraint. An auto scaling group with a launch template and a load balancer gives you two of everything, and self-healing.

ECS runs containers without a cluster to manage. You write a task definition (the image, CPU and memory, environment, the task role and the log configuration) and a service that keeps N tasks running behind a target group.

With Fargate there are no instances at all. You pay per task-second for the CPU and memory you declared, and the Docker course's MaxRAMPercentage is what sizes the JVM to it. ECS is the least-surprising way to run a handful of Spring Boot services on AWS. The Docker knowledge transfers whole, the Kubernetes vocabulary is not needed, and deployments are rolling, with health checks and circuit breakers built in.

EKS is managed Kubernetes. AWS runs the control plane, and you run the nodes (or Fargate does). Everything in the Kubernetes course applies unchanged: Deployments, Services, probes, HPA.

On top of that comes AWS-specific glue:

  • the load balancer controller turns an Ingress into an ALB;
  • IRSA or Pod Identity turns a service account into a role;
  • the EBS and EFS CSI drivers provide volumes.

Choose EKS when the organisation is standardising on Kubernetes or already has the skills. A team of three with four services does not need it.

Lambda runs a function per event, such as an S3 upload, an SQS message or an HTTP request through API Gateway. It charges per invocation and per millisecond.

Java's cold start is the known cost: a JVM plus a framework takes seconds. SnapStart snapshots the initialised JVM and restores it in hundreds of milliseconds, and Spring Cloud Function or a plain handler class keeps the start small. Lambda is right for event-driven glue and for spiky, infrequent work. It is wrong for a service with steady traffic, where a container is cheaper and simpler to observe.

Storage: S3, and the patterns that use it well

S3 is object storage: a bucket, keys, objects up to 5 TB, eleven nines of durability, and an HTTP API. It is not a filesystem — no rename (copy and delete), no append, no directories except as a prefix convention — and treating it as one is the mistake behind most S3 performance tickets. The patterns a backend actually uses:

  • Presigned URLs for uploads and downloads: the service signs a URL that permits one PUT to one key for fifteen minutes, hands it to the client, and the bytes go directly to S3, never through the JVM — the system-design course's file-upload brief and its "object storage: never through your service" rule.
  • Prefixes for partitioning, uploads/2026/09/18/<uuid> rather than one flat namespace, and a key design that spreads hot writes across prefixes; the old per-prefix rate limits are gone, but listing is still per prefix.
  • Lifecycle rules: transition to Infrequent Access after 30 days, to Glacier after a year, expire after seven — cost and retention as configuration, not a cron job.
  • Versioning and Object Lock for the backups (the production course's backup lesson: a backup on the same machine is not a backup; a bucket in another region with Object Lock is).
  • Event notifications to SQS or Lambda on PutObject, which is how "process this upload" becomes an event rather than a poll.
  • Server-side encryption on by default, a bucket policy that denies unencrypted puts and plain HTTP, and Block Public Access at the account level, so a bucket cannot be made public by a typo.

EBS is the block disk attached to one EC2 instance in one zone — the volume a database on EC2 would use, snapshotted to S3 for backup. EFS is a shared NFS filesystem for the rare case several instances must write the same files. Neither is where uploads belong.

Databases: RDS, and what managed actually means

RDS runs PostgreSQL (or MySQL, and the others) and takes over operations you would otherwise own:

  • automated backups with point-in-time recovery;
  • a Multi-AZ standby with synchronous replication and automatic failover;
  • read replicas;
  • minor version patching in a maintenance window;
  • metrics into CloudWatch.

Aurora is AWS's own storage layer under a PostgreSQL-compatible engine, with faster failover and replicas that share storage. It costs more per instance, and less for I/O-heavy workloads.

What stays yours, and what the SQL course's lessons still decide:

  • Sizing and the pool. The instance class sets max_connections, and the connection-pooling lesson's arithmetic still applies: ten services with a pool of twenty each is two hundred connections to a database that may allow a hundred and fifty. RDS Proxy is the PgBouncer the course mentioned, managed, and it also makes Lambda-to-RDS survivable.
  • Failover is a reconnect. Multi-AZ failover changes what the endpoint's DNS resolves to. A JVM that cached the address, or a pool that holds dead connections, sees errors until it notices, for however long the failover takes (AWS does not guarantee a time). These settings make it notice quickly: socket and connect timeouts, so a dead connection fails fast instead of hanging; validation, so the pool discards it; and a short JVM DNS cache (networkaddress.cache.ttl), so the replacement connection resolves the endpoint afresh. The practice is to test a failover deliberately (the chaos lesson) before the first real one.
  • Backups are still yours to verify. Automated snapshots exist; a restore that has never been run is the production course's "restore is the product". Cross-region snapshot copies are the off-site copy.
  • Parameter groups are postgresql.conf; Performance Insights is the plan-level view the query-optimisation lesson reads; the migration is still Flyway, still before the switchover, still expand-contract.

DynamoDB is the other database: key-value and document, single-digit-millisecond at any scale, no joins, and a data model you design around access patterns before you write it; the data-store lesson's "start from the questions" rule is the whole of DynamoDB design. ElastiCache is Redis (or Valkey) managed, for the caching course's patterns and the distributed-locks lesson's limits.

Managed queues and streams

The messaging courses' brokers exist as services, and the choice between them is the Kafka-versus-RabbitMQ decision with an operations bill attached.

  • SQS is a queue, with nothing to run. Delivery is at-least-once (FIFO queues give exactly-once processing and ordering per message group, at lower throughput). The visibility timeout is the consumer's lease, and a dead-letter queue is configured per queue. It is the right default for "work to be done".
  • SNS is fan-out: a topic that pushes to many SQS queues, Lambdas or HTTP endpoints. SNS-to-SQS is the pub/sub shape without a broker.
  • EventBridge is SNS with routing rules on the event's content and a schema registry, for events between systems.
  • MSK is Kafka, managed: you size the brokers and AWS applies the patches. Everything in the Kafka course applies unchanged, at the price of running a cluster. MSK Serverless removes the sizing and caps the throughput.
  • Amazon MQ is RabbitMQ or ActiveMQ, for a workload that already speaks AMQP.

Spring reaches SQS and SNS through Spring Cloud AWS, and MSK through the same Spring Kafka as any broker.

The same concepts on Azure and GCP

Every service in this course has a counterpart, and the concepts transfer whole; the names do not:

ConceptAWSAzureGCP
Identity for a serviceIAM roleManaged identityService account
Private networkVPC, subnets, security groupsVNet, subnets, NSGsVPC, subnets, firewall rules
Virtual machinesEC2, Auto Scaling groupVirtual Machines, VM Scale SetCompute Engine, managed instance group
Containers without a clusterECS on FargateContainer AppsCloud Run
Managed KubernetesEKSAKSGKE
FunctionsLambdaAzure FunctionsCloud Functions / Cloud Run
Object storageS3Blob StorageCloud Storage
Managed PostgreSQLRDS, AuroraAzure Database for PostgreSQLCloud SQL, AlloyDB
Queue / pub-sub / streamsSQS / SNS / MSKService Bus / Event Grid / Event HubsPub/Sub / Pub/Sub / Managed Kafka
HTTP load balancerALBApplication GatewayCloud Load Balancing
Metrics, logs, alarmsCloudWatchAzure MonitorCloud Monitoring, Cloud Logging
SecretsSecrets ManagerKey VaultSecret Manager

The judgement transfers too: identity through roles rather than keys, everything private behind one load balancer, a managed database with the pool sized to it, object storage through signed URLs, and a bill read by tag. What differs is the defaults and the sharp edges, which is why a platform team's guidance is worth more than the vendor's tutorial.

Choosing, for a Spring Boot service

The serviceRuns onFiles inDatabase
one or two, small team, full controlEC2 + systemd, an ASG for twoS3 via presigned URLsRDS PostgreSQL, Multi-AZ
several containerised servicesECS on FargateS3RDS, with RDS Proxy if the pool arithmetic demands
an organisation on KubernetesEKSS3RDS or Aurora
event glue, spiky, infrequentLambda with SnapStartS3 events inDynamoDB, or RDS through the proxy

Every row has S3 for files and a managed database, because those are the two places where the operational work is largest and least differentiating. The compute choice is the one that follows the team.

Under the hood: why EBS survives an instance and instance store does not, and what actually happens during an RDS failover

Two mechanisms in this lesson get treated as interchangeable when they are not, and the difference matters the first time a disk or a database misbehaves.

EBS is network-attached storage; instance store is physically local. That one fact explains everything else about both.

An EBS volume lives on AWS's own storage servers. The EC2 instance reaches it over the network (an internal high-speed connection inside the data centre, but still a network hop). It is not a disk bolted to the machine the instance runs on.

That is why an EBS volume persists independently of the instance. Stopping or terminating the instance, or the underlying hardware failing, does not destroy the volume, because the volume was never physically part of that hardware. It can be detached and reattached to a different instance, and it is what a snapshot (itself stored in S3) captures.

Instance store is physical disk on the same host machine the instance runs on. It is faster for exactly the reason EBS has a network hop and instance store does not. That makes it the right choice for a cache, a scratch disk for a batch job, or a database's temp space, where speed matters and durability does not.

But its data is only as durable as that one physical machine. Stop the instance, or lose the host to a hardware failure, and the contents are gone: not recoverable, and not snapshotted automatically. Treating instance store as if it were EBS, and expecting data to survive a stop/start cycle, is a genuine, repeated production mistake, not a hypothetical one.

RDS Multi-AZ failover is not an instant switch. It is synchronous replication followed by a DNS change, and the real behaviour lives in the gap between "the standby is ready" and "traffic reaches it".

In a Multi-AZ deployment, every write to the primary is replicated synchronously to the standby in a different availability zone before RDS acknowledges the write as committed. That is the actual durability guarantee: a crash of the primary cannot lose an acknowledged write, because the standby already has it. It is also why Multi-AZ write latency is higher than single-AZ: the primary must wait for the standby's acknowledgement, not just its own disk.

When RDS detects that the primary has failed (or during planned maintenance, or a manual failover for a drill), it does not move an IP address at the network level the way some systems do. It flips the DNS CNAME that the RDS endpoint hostname resolves to, from the old primary's address to the newly promoted standby's address.

This is precisely why the lesson above says "failover is a reconnect": nothing at the TCP or connection-pool level knows a failover happened until it is forced to look up the hostname again. A pool holding open connections to the old primary, or a JVM or OS that cached the DNS resolution beyond its TTL, keeps sending traffic to an address that no longer answers as the primary. Fast timeouts, connection validation and a short JVM DNS cache defend against exactly that.

DNS is only consulted when a connection is opened. An established TCP connection keeps talking to the IP it connected to, whatever the record now says, so no TTL setting moves an open connection. It has to fail and be replaced.

Do not design around a specific number of seconds for how long this takes. AWS does not publish a guaranteed failover time, and it varies with the database engine, the size of the in-flight transaction log, and the reason for the failover. The mechanism is fixed: synchronous replication, then a CNAME flip, then a window where stale connections fail until they reconnect. Design the pool and the retry logic against that mechanism, not against an assumed duration.

Try it yourself

Reason through a disk choice under a constraint

A service runs a self-managed PostgreSQL instance on EC2. It is not RDS: assume a real constraint forces this, such as an extension RDS does not support. The team is deciding two things:

  1. Should the database's data directory go on an EBS volume or on the instance's local instance store?
  2. Should a Redis cache, used purely as a hit-rate optimisation, go on EBS or instance store? Nothing depends on its contents surviving.

Reason through both decisions using what this lesson says about how each storage type is physically attached. Then say which one you would get wrong by defaulting to "the faster option" without thinking about durability.

Why the database and the cache should make opposite choices

For the PostgreSQL data directory, EBS is close to non-negotiable. Instance store's contents vanish if the instance stops or the host fails, and a database's data directory is exactly what must survive both events. An instance-store PostgreSQL would be one host failure away from total data loss with no recovery path, because there was never a durable copy anywhere else. (This is also why RDS itself is built on network-attached storage, not instance store.)

For the Redis cache, the calculation inverts. If the cache is only a hit-rate optimisation and nothing depends on a specific key surviving a restart, then instance store's speed is close to free upside. (A cache is allowed to be wrong or empty: that is the "application, shared" row's own contract.) Losing its contents on an instance stop just means a burst of cache misses until it refills, not a correctness problem.

The mistake this exercise is built to catch is picking the faster option, instance store, reflexively for whichever workload "needs performance", without asking what happens when (not if) that storage disappears with the instance. The database needs the durability that comes with the network hop. The cache needs the local disk's speed, precisely because it does not need durability at all.

Misconceptions

  • "EBS and instance store are just 'AWS's two disk options,' interchangeable by price or size." They differ in where the physical disk lives. EBS is network-attached storage that outlives the instance, so it suits anything that must survive a stop or a host failure. Instance store is physically part of the host and is lost when the host is. That makes it fast, but only appropriate for data that is fine to lose: caches, scratch space, or data replicated somewhere durable.
  • "Multi-AZ failover means there is no gap: it's automatic, so the application doesn't need to handle it." Multi-AZ makes failover automatic: RDS detects the failure and promotes the standby without a human acting. But automatic is not instant or transparent. The mechanism is a DNS CNAME change, and any connection or pool that does not re-resolve the hostname keeps talking to an address that stopped being the primary. The application still needs a pool that recycles and revalidates connections. Without one, the outage happens anyway, slightly delayed and self-inflicted.

Sources

  • Amazon EBS User Guide, "Amazon EBS volumes" — network-attached block storage that persists independently of the instance lifecycle.
  • Amazon EC2 User Guide, "Instance store" — physically attached, ephemeral storage tied to the host.
  • Amazon RDS User Guide, "Multi-AZ deployments for high availability" — synchronous replication to the standby and the DNS endpoint change during failover.
Progress is saved on this device and to your account when signed in.