
EC2, RDS and S3: the three services most web apps need
Most web apps don't need a long AWS service list. Compute, a managed database, and object storage cover the basics. Here's how the three fit together.
Most teams starting on AWS reach for a long service list before they have a single user. You rarely need it. A large share of production web applications run on three services: EC2 for compute, RDS for the database, and S3 for objects. Understanding why those three, and how they fit together, is worth more than knowing the names of thirty others.
This is a short walk through that stack: what each layer owns, how a request moves through it, and the design decisions that decide whether it holds up under load.
Why split the stack at all
A single server running your app, your MySQL instance, and your uploads directory works fine until it does not. The failure modes are predictable:
- The database competes with the app for memory and CPU, so a slow query becomes a slow page.
- User uploads sit on the instance disk, which means you cannot add a second instance without the two disagreeing about what files exist.
- Backups, patching, and failover are all your problem, and all manual.
- Scaling means buying a bigger box, because the pieces cannot move independently.
Splitting into three services separates things with genuinely different scaling curves. Compute is bursty and disposable. The database is stateful and needs careful, vertical scaling. Object storage grows monotonically and is read far more than it is written. Each of those wants a different kind of infrastructure.
The layout

One VPC, two subnets. The instance sits in a public subnet with a security group that allows only 80 and 443. The database sits in a private subnet with no route to the internet, accepting connections only from the instance's security group. S3 lives outside the VPC entirely, reached over the AWS network rather than through your subnets.
That is the whole picture. Everything else you will read about, load balancers, CDNs, caches, queues, is added later, and only when something specific pushes you to add it.
EC2: the disposable layer
Treat application instances as replaceable. If losing one instance means losing something, that something is in the wrong place.
Practical rules that follow from this:
Attach an IAM role, never an access key. The instance profile gives your application temporary, rotating credentials for S3 and anything else it calls. Long-lived keys in a config file are the single most common way AWS credentials leak into a Git repository.
Keep state off the instance. PHP's default session handler writes to local disk, which is fine with one instance and broken the moment there are two. Putting sessions in the database from the start costs nothing now and saves a migration later.
Bake or bootstrap, do not hand-configure. Either build an AMI with the runtime baked in, or install it from user data at boot. An instance you configured by SSH is an instance nobody can recreate.
Right-size, then leave it alone. A single t3.small or t3.medium runs a surprising amount of traffic. Watch CloudWatch for a week before deciding you need something bigger.
RDS: the layer you stop babysitting
RDS is a managed database, not a hosted one. The difference matters. You give up the operating system and root on the database host, and in exchange you get automated backups, point-in-time recovery, minor version patching, and synchronous replication.
The settings that carry the most weight:
Multi-AZ when it starts to matter. RDS can keep a synchronous standby in a second Availability Zone and promote it automatically on failure. Your application reconnects to the same endpoint, so failover is a connection blip rather than an outage. It roughly doubles the instance cost, so it is a switch you flip when the application becomes something people depend on, not on day one.
Security group chaining. The database security group should allow port 3306 or 5432 from the application's security group ID, not from a CIDR block. The rule then stays correct as instances come and go.
Secrets Manager for the password. Rotation becomes a configuration setting rather than a project.
S3: everything that is not a row
Anything a user uploads, anything you generate, anything you archive: it belongs in S3, not on an instance volume. Eleven nines of durability, no capacity planning, and it costs a fraction of block storage.
Two patterns are worth adopting early.
Presigned URLs. Do not route file uploads and downloads through your web servers. Have the application generate a time-limited presigned URL and let the browser talk to S3 directly. Your instances stop being a bandwidth bottleneck, and a 200 MB upload no longer occupies a PHP worker for a minute.
Keep the bucket private. Leave Block Public Access on and serve everything through presigned URLs. A bucket made public "just for the images" is how object storage turns into a data leak. If you later want public assets served fast, that is a job for a CDN in front of the bucket, not for a public bucket.
Add lifecycle rules while the bucket is still small. Moving objects to Infrequent Access after 30 days and Glacier after 90 costs nothing to configure and quietly saves real money at scale. Turn on versioning if the data matters, and pair it with a rule that expires old versions so history does not grow without limit.
Following one request
A user opens a product page. The request reaches the EC2 instance over HTTPS. The application queries RDS across the private subnet for the product record, signs a presigned URL for the product image, and renders the page. The browser fetches that image directly from S3. The user then uploads a review photo, and the browser sends it straight to S3 using another presigned URL, signed by the application with credentials it got from its instance role.
Notice what never happened. No traffic crossed the public internet to reach the database. No credentials were stored on disk. No uploaded file landed on the instance.
What usually goes wrong
- Database in a public subnet. Convenient during development, then it stays that way.
- Uploads on the instance. Discovered on the day the instance is replaced, or the day you add a second one.
- No connection pooling. Every PHP request opening a fresh database connection will exhaust
max_connectionslong before CPU becomes the limit. RDS Proxy or a pooler solves it.
- Backups never tested. RDS takes them automatically. Restoring one to a fresh instance, once, is what tells you they work.
- No cost alarm. Set a budget alert on day one. The charges that surprise people are rarely the instances.
Where to go next
This stack takes you a long way. When you outgrow it, the additions are predictable and they arrive in roughly this order: an Application Load Balancer with a second instance, when one server is no longer enough or you want zero-downtime deploys; CloudFront in front of S3, when asset latency starts to show; RDS Multi-AZ, when downtime becomes expensive; ElastiCache in front of hot queries; SQS to move slow work out of the request path.
None of that changes the shape of what is described here. It adds layers around it.
Start with three services, get the boundaries right, and add the fourth only when something specific is breaking.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article