Back to Blog
SnapLink // Scalable AWS Deployment

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.

September 29, 2026
·6 min read·Pratik Patil
AWSTerraformECS FargateDockerCI/CDPostgreSQLRedisDevOps

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:

⚠️ Local Compose Environment
  • • 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
🚀 Production Cloud Deployment
  • • 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.

Multi-Stage Docker Builds
Separated build dependencies (C-compilers, pip wheels) from the lightweight runtime image. This slashed image sizes and eliminated unused system binaries.
Non-Root Container Execution
Explicitly defined an unprivileged system user inside the container (`USER appuser`) so that container escapes cannot compromise the underlying host environment.
Container Vulnerability Scanning (Trivy)
Automated vulnerability scanning inside CI with Aqua Security's Trivy before any image is tagged or pushed to Amazon ECR, catching CVEs early.
Dockerfile — Multi-Stage Hardening PatternBackend/Dockerfile
# 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.

Scalable URL Shortener AWS Architecture Diagram
AWS Architecture: Public ALB routing to private ECS Fargate tasks with RDS PostgreSQL and ElastiCache Redis
TERRAFORM MODULE REPOSITORY LAYOUT
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 rules
Reproducible Multi-AZ Networking

The 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.

Immutable State & Clean Destruction

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.

SnapLink Automated CI/CD Deployment Flow
GitHub Actions Pipeline: Automated Validation, Security Scanning, ECR Push, and Rolling ECS Deployment
AUTOMATED PIPELINE SEQUENCE
1. Git Push / PRDeveloper pushes code to master branch
2. Automated LintingRuff / Flake8 validates code style & syntax
3. Pytest SuiteUnit & integration tests cover APIs, cache & DB models
4. Docker BuildMulti-stage production image built in CI runner
5. Trivy ScanScans image for critical/high vulnerabilities
6. Push to Amazon ECRImage tagged with commit SHA and latest
7. Update ECS Task DefNew container definition registered with AWS
8. Fargate Rolling UpdateNew tasks spin up, pass health checks; old tasks drain
Zero-Downtime Rolling Deployments

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:

High Level Architecture Overview
High-Level Scalable Topology: Load Balancer, Containerized Service Mesh, In-Memory Caching, and Relational Store
ECS Horizontal Task Autoscaling

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.

ElastiCache Redis Read-Shield

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.

Dual Health Check ProtocolALB + Container Level
● GET /health (Liveness)
Verifies that the Uvicorn/FastAPI process is running and able to respond to HTTP requests.
● GET /ready (Readiness)
Pings PostgreSQL and Redis connections to ensure dependencies are healthy before taking traffic.

06Network Security & Secrets Management in the Cloud

Production cloud deployments require strict isolation boundaries. SnapLink enforces security across both the network and credential layers:

Network Segmentation via Security Groups

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.

AWS Secrets Manager Integration

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.

Separation of IAM Roles

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.

AMAZON CLOUDWATCH OBSERVABILITY STACK
Compute Metrics
ECS Task CPU & Memory Utilization, Task counts, Container restarts
ALB Telemetry
Target Response Time, HTTP 2xx/3xx/4xx/5xx count, Active connection count
Data Store Health
RDS IOPS, DB connections, Redis Cache Hit Ratio & Evictions

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 MetricTarget / Specification
Write Throughput (Link Creation)~4 requests/sec
Average Read Throughput~400 requests/sec
Peak Read ThroughputUp to ~4,000 requests/sec
Cache Hit Ratio Target>95% (Redis In-Memory)
Autoscaling TriggerCPU > 70% or ALB Target Req Surge
K6 STAGED LOAD PROGRESSION
100 RPS (Warmup)→500 RPS→1,000 RPS→2,000 RPS (Autoscale)→4,000 RPS (Peak Test)

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:

Key Takeaway #1
Modular Terraform saves hours of debugging by decoupling networking from application compute.
Key Takeaway #2
Shifting security left with Trivy and non-root containers prevents vulnerabilities before they reach production.
Deployment Roadmap
  • ✓ 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