
Building a Full-Stack Application on AWS: React, Node.js, Redis and MySQL on EC2
A walkthrough of a secure three-tier architecture on AWS using Route 53, EC2 with Nginx, ElastiCache for Redis and RDS for MySQL, with public and private subnets and tightly scoped security groups.
Introduction
Deploying a full-stack application on AWS involves more than launching a server. You have to decide how traffic reaches your app, where your data lives, and how each component is locked down.
This article walks through a practical architecture for a React + Node.js + MySQL application with Redis caching, built on EC2, RDS and ElastiCache inside a custom VPC.
Architecture Overview
The design follows a classic three-tier pattern inside a single VPC (
10.0.0.0/16 ):- Presentation and application tier: an EC2 instance in a public subnet running Nginx, a React frontend and a Node.js backend
- Caching tier: Amazon ElastiCache for Redis in a private subnet
- Data tier: Amazon RDS for MySQL in a private subnet
Supporting services (IAM, CloudWatch, WAF, S3 and Systems Manager) provide access control, monitoring, protection and management.
Request Flow
- Users reach the application through Amazon Route 53, which resolves your domain name to the server.
- Traffic goes to the EC2 public IP, where Nginx acts as a reverse proxy and handles HTTP/HTTPS requests.
- Nginx serves the React frontend and forwards API requests to the Node.js backend.
- The backend uses Redis for caching, which reduces database load and improves response times.
- The backend reads and writes to RDS MySQL for persistent storage.
Network Design
VPC
A single VPC with the CIDR block
10.0.0.0/16 gives you an isolated network with room to grow.Public subnet ( 10.0.1.0/24 )
This subnet holds the EC2 instance and is the only part of the application reachable from the internet. Nginx sits in front of both the React app and the Node.js API, so only one entry point is exposed.
Private subnet ( 10.0.2.0/24 )
ElastiCache and RDS live here. They have no public IP and cannot be reached from the internet. Only the application server can talk to them.
Tip: RDS requires a DB subnet group that spans at least two Availability Zones, even if you run a single instance. Plan a second private subnet if you intend to enable Multi-AZ later.
Security Group Rules
Security groups are the main layer of defense in this setup.
Port | Protocol | Source | Purpose |
|---|---|---|---|
80 | HTTP | 0.0.0.0/0 | Public web traffic (redirect to HTTPS) |
443 | HTTPS | 0.0.0.0/0 | Secure public web traffic |
22 | SSH | Your IP only | Administrative access |
3306 | MySQL | EC2 security group | Database access from the app |
6379 | Redis | EC2 security group | Cache access from the app |
Two practices matter most here:
- Never open SSH to the world. Restrict port 22 to your own IP, or use AWS Systems Manager Session Manager and close port 22 entirely.
- Reference security groups instead of IP ranges for the database and cache rules. This way only resources attached to the EC2 security group can connect, even if IP addresses change.
Component Roles
Nginx (reverse proxy)
Nginx terminates HTTP/HTTPS, serves the built React files and proxies API calls to Node.js:
server {
listen 80;
server_name example.com;
root /var/www/react-app/build;
index index.html;
location / {
try_files $uri /index.html;
}
location /api/ {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}Node.js backend
The backend handles business logic and sits between the cache and the database. A common pattern is cache-aside: check Redis first, query MySQL on a miss, then store the result in Redis with a TTL.
Amazon ElastiCache for Redis
Redis keeps frequently accessed data in memory, such as sessions, query results and rate-limit counters. This reduces latency and protects the database from repetitive reads.
Amazon RDS for MySQL
RDS provides a managed relational database with automated backups, patching and optional Multi-AZ failover, so you don't have to run MySQL yourself on EC2.
Supporting AWS Services
- AWS IAM: Use roles for EC2 instead of hard-coded access keys, and follow least privilege.
- Amazon CloudWatch: Collect logs and metrics, and set alarms for CPU, memory, disk and error rates.
- AWS WAF: Add a web application firewall to block common attacks such as SQL injection and XSS, and to rate-limit abusive traffic.
- Amazon S3: Store static assets, user uploads and database or application backups.
- AWS Systems Manager: Patch, manage and access instances without opening SSH.
Best Practices and Improvements
This architecture is a solid starting point. As traffic and requirements grow, consider these upgrades:
- Add an Application Load Balancer with an Auto Scaling group for high availability and horizontal scaling. WAF attaches to the ALB directly.
- Enable HTTPS with AWS Certificate Manager and redirect all HTTP traffic to HTTPS.
- Enable Multi-AZ for RDS and a replica group for ElastiCache.
- Store secrets in AWS Secrets Manager or Parameter Store rather than in environment files.
- Serve static assets through CloudFront and S3 to cut load on the EC2 instance.
- Use a NAT Gateway or VPC endpoints if private resources need outbound access.
- Run the Node.js app under PM2 or systemd so it restarts automatically.
Conclusion
By combining a public subnet for the web tier with private subnets for caching and data, and by tightly scoping security groups, you get a secure and maintainable foundation for a full-stack application on AWS. From here you can evolve toward load balancing, auto scaling and managed containers without redesigning the network.
If you found this useful, let me know what you'd like covered next, such as Terraform automation, CI/CD pipelines or a containerized version on ECS.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article