Deploying SnapLink: Building a Scalable, Production Cloud Infrastructure on AWS
Building a URL shortener is easy. Designing one that can survive traffic spikes, isolate failures, deploy without interrupting users, and remain reproducible through infrastructure-as-code is a very different problem. For SnapLink, I wanted to solve that second problem. The application started as a containerized FastAPI + PostgreSQL + Redis system running locally with Docker Compose. I then evolved it into an AWS deployment using ECS Fargate, Application Load Balancer, Amazon RDS, ElastiCache Redis, Amazon ECR, Terraform, and GitHub Actions. This article walks through the engineering decisions behind that transition—from container hardening and network isolation to automated deployments, autoscaling, caching, observability, and load testing.
01The Objective: Beyond Local Docker Compose
Almost any developer can run a web service locally with a simple docker compose up -d. Spinning up FastAPI, PostgreSQL, and Redis on a single laptop works nicely for debugging, but in a production environment, a single containerized host fails immediately when faced with real-world failure modes:
- • Single host: single point of failure (SPOF)
- • Manual restarts during crashes or updates
- • Databases and app share compute resources
- • No automatic horizontal scaling for traffic spikes
- • Hardcoded local credentials and shared ports
- • Serverless container management via ECS Fargate
- • Multi-AZ redundancy with zero single points of failure
- • Managed persistent data (RDS PostgreSQL + ElastiCache)
- • Horizontal task autoscaling based on CPU/traffic
- • Fully automated, auditable CI/CD and IaC provisioning
The core mission of SnapLink was to design and execute a true cloud deployment pipeline: writing every piece of infrastructure as code using Terraform, securing the network boundary, and automating the entire build-scan-deploy cycle with GitHub Actions.
02Containerization Strategy & Security Hardening
A scalable deployment begins at the container image level. Bloated Docker images with compilation toolchains or root privileges increase attack surfaces and slow down ECS deployment task launches.
# Stage 1: Build & Dependencies
FROM python:3.12-slim AS builder
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends gcc libpq-dev
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt
# Stage 2: Minimal Production Runtime
FROM python:3.12-slim AS runner
WORKDIR /app
# Security: Run as unprivileged non-root user
RUN addgroup --system --gid 1001 appgroup && \
adduser --system --uid 1001 --gid 1001 appuser
COPY --from=builder /root/.local /home/appuser/.local
COPY app/ ./app/
ENV PATH=/home/appuser/.local/bin:$PATH \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
USER appuser
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]03Infrastructure as Code: Modular Terraform Architecture
Configuring cloud resources manually in the AWS Management Console is error-prone, untracked, and cannot be recreated consistently across environments. Everything in SnapLink is provisioned through Terraform, organized into clean, reusable modules.

terraform/
├── environments/
│ ├── dev/ # Development environment tfvars & remote state
│ └── prod/ # Production environment sizing & HA configs
└── modules/
├── vpc/ # Custom VPC, 2 public & 2 private subnets, IGW, NAT GW
├── alb/ # Internet-facing ALB, target groups, health probes
├── ecs/ # Fargate Cluster, Task Definitions, Auto-scaling policies
├── rds/ # Managed PostgreSQL in private DB subnet group
├── redis/ # Amazon ElastiCache Redis cluster
└── ecr/ # Container Registry with lifecycle retention rulesThe VPC module provisions subnets across two distinct AWS Availability Zones (AZs). Public subnets host only the Application Load Balancer and NAT Gateways, while ECS Fargate tasks and databases are isolated in private subnets with no public IPv4 addresses.
State locking ensures concurrent deployments do not corrupt the state file. When scaling down or tearing down test environments, a single terraform destroy handles dependencies cleanly without orphaned cloud assets.
04Automated CI/CD Pipeline: Zero-Downtime Delivery
Continuous integration and continuous deployment are managed through GitHub Actions workflows (ci.yml and cd.yml). Every commit is verified through automated quality gates before triggering a rolling update on AWS ECS Fargate.

ECS Fargate deploys using a minimum healthy percent of 100% and a maximum percent of 200%. The ALB only routes live traffic to new tasks after their /ready endpoint returns HTTP 200, ensuring users never see 502/503 errors during releases.
05High Availability & Autoscaling with ECS Fargate
URL shorteners face an asymmetric workload: write operations (creating links) are infrequent, but read operations (redirecting users) come in huge, spiky surges. The deployment handles this through a multi-tiered scaling strategy:

AWS Target Tracking scaling policies monitor both average CPU utilization and Application Load Balancer Request Count per Target. When traffic surges, ECS spins up additional Fargate tasks across AZs in seconds.
Redirect requests follow a strict cache-first pattern (Redis → PostgreSQL → Redis). With a cache hit ratio >95%, the PostgreSQL database is insulated from intense read spikes, keeping latency under 10ms.
06Network Security & Secrets Management in the Cloud
Production cloud deployments require strict isolation boundaries. SnapLink enforces security across both the network and credential layers:
Strict ingress rules prevent lateral movement: the ALB accepts public HTTP/HTTPS traffic; ECS tasks accept traffic ONLY from the ALB's security group; RDS and Redis accept connections ONLY from the ECS security group.
Zero secrets or database credentials are baked into Docker images or committed to git. Secrets are pulled at runtime by the ECS task execution role from AWS Secrets Manager.
Configured separate IAM Task Execution Roles (pulling images from ECR, CloudWatch log streams) and Task Roles (application-level AWS SDK permissions), following least-privilege principles.
07Observability & Validating Scalability with k6
You cannot optimize what you do not measure. A scalable deployment is incomplete without observability and empirical load testing.
To validate the deployment under production pressure, I wrote load testing scripts with k6 simulating traffic ramp-ups up to 4,000 requests per second:
| Workload Metric | Target / Specification |
|---|---|
| Write Throughput (Link Creation) | ~4 requests/sec |
| Average Read Throughput | ~400 requests/sec |
| Peak Read Throughput | Up to ~4,000 requests/sec |
| Cache Hit Ratio Target | >95% (Redis In-Memory) |
| Autoscaling Trigger | CPU > 70% or ALB Target Req Surge |
08Deployment Takeaways & Future Improvements
Building and deploying SnapLink reinforced that writing application code is only half the battle. Designing infrastructure that is reproducible, scalable, secure, and self-healing requires rigorous adherence to cloud and DevOps fundamentals:
- ✓ AWS ACM SSL/TLS Certificates
- ✓ CloudWatch Alarm SNS notifications
- → Blue/Green CodeDeploy deployments
- → Read Replicas for Amazon RDS
- → AWS WAF rate-limiting protection
- → Distributed Redis caching cluster