Graphite's Strategic Pivot: Migrating Next.js from S3 to AWS ECS for Enterprise Scalability
Share this article
At AWS re:Invent 2023, Graphite engineers shared an unconventional infrastructure journey that challenges common Next.js hosting assumptions. As their code review platform surged beyond beta, the team confronted limitations of their original single-page application (SPA) architecture—static files served from S3 behind CloudFront. While simple and cheap, this approach couldn't support their evolving need for dynamic rendering, faster builds, and sophisticated deployment workflows.
The Next.js Imperative
Graphite's migration to Next.js wasn't merely a framework switch—it was an architectural overhaul. "Create React App served us well initially," the team noted, "but bundle splitting and incremental static regeneration became non-negotiables." After evaluating options, Next.js emerged as the solution, but the hosting question remained unresolved. Surprisingly, Vercel—Next.js's creator—was ruled out despite its seamless integration.
Hosting Showdown: Vercel vs. Amplify vs. ECS
The team evaluated three paths:
1. Vercel: Offered superior developer experience but conflicted with Graphite's requirement to keep all infrastructure within their AWS VPC. Cost projections also raised concerns, despite recent pricing adjustments.
2. AWS Amplify: Provided AWS-native integration but lacked enterprise-grade deployment controls and build visibility.
3. Amazon ECS: Containerization aligned with existing backend services, enabling unified Terraform templates and shared load balancers.
"ECS seemed counterintuitive for a frontend framework," engineers admitted, "but performance benchmarks shocked us." Rigorous testing revealed containerized Next.js on ECS matched edge function speeds for their splash page, debunking assumptions about latency penalties.
Six Strategic Advantages of ECS for Next.js
- Cost Efficiency: Maintained near-S3 operational costs while unlocking dynamic capabilities
- Deployment Sophistication: Blue-green deployments via ECS eliminated production downtime
- Infrastructure Uniformity: Identical Terraform templates for frontend/backend reduced cognitive load
- Scalability On Demand: Container orchestration handled traffic spikes seamlessly
- VPC Security: All services remained within Graphite's hardened network perimeter
- Cold Start Optimization: Careful container tuning minimized server-side rendering delays
Hard-Won Best Practices
Graphite's engineers emphasized critical operational insights:
# Sample Terraform snippet for ECS service deployment
resource "aws_ecs_service" "nextjs_app" {
name = "graphite-nextjs"
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.app.arn
desired_count = 3
deployment_controller {
type = "CODE_DEPLOY" # Enables blue-green deployments
}
}
- Infrastructure as Code Discipline: Terraform templates ensured environment parity from development to production
- Resource Tuning Vigilance: Engineers averted six-figure AWS bills twice through container sizing optimizations
- ECS Feature Maximization: Service discovery simplified microservice communication patterns
The Containerized Future
Graphite's journey underscores that optimal infrastructure evolves with organizational maturity. While Vercel or Amplify might suit early-stage startups, Graphite's growth demanded the deployment control and cost predictability of containerization. Their verdict? "Don't fear containers for frontend apps—with proper benchmarking, they can match edge performance while granting operational flexibility no platform-as-a-service can offer."
As server-side rendering complexity increases, Graphite's ECS experiment provides a compelling template for teams weighing vendor convenience against architectural sovereignty. Sometimes the road less traveled—especially when paved with containers—leads exactly where you need to go.
Source: Graphite Engineering Team (https://graphite.com/blog/why-we-use-aws-instead-of-vercel)