Scaling & Infrastructure¶
Infrastructure design for growth from 100 to 100,000+ users
Growth Timeline¶
gantt
title Scaling Roadmap
dateFormat YYYY-MM
section Users
0-100 Beta :a1, 2026-06, 2M
100-1K Early :a2, after a1, 4M
1K-10K Growth :a3, after a2, 6M
10K-100K Scale :a4, after a3, 12M
section Infrastructure
Single Instance :b1, 2026-06, 2M
Multi-Region :b2, after b1, 4M
Auto-Scaling :b3, after b2, 6M
Enterprise Ready :b4, after b3, 12M
Phase 1: MVP (0-100 Users)¶
Timeline: Months 1-2 Monthly Cost: ~$50-100
graph TB
subgraph "Simple Stack"
CF[Cloudflare
DNS + CDN] Vercel[Vercel
Frontend] Railway[Railway
FastAPI] Supabase[(Supabase
PostgreSQL)] Qdrant[(Qdrant Cloud
Vectors)] end CF --> Vercel CF --> Railway Railway --> Supabase Railway --> Qdrant style CF fill:#f97316,color:#fff style Vercel fill:#000,color:#fff style Railway fill:#6366f1,color:#fff style Supabase fill:#22c55e,color:#fff style Qdrant fill:#3b82f6,color:#fff
DNS + CDN] Vercel[Vercel
Frontend] Railway[Railway
FastAPI] Supabase[(Supabase
PostgreSQL)] Qdrant[(Qdrant Cloud
Vectors)] end CF --> Vercel CF --> Railway Railway --> Supabase Railway --> Qdrant style CF fill:#f97316,color:#fff style Vercel fill:#000,color:#fff style Railway fill:#6366f1,color:#fff style Supabase fill:#22c55e,color:#fff style Qdrant fill:#3b82f6,color:#fff
Infrastructure Details¶
| Component | Service | Plan | Monthly Cost |
|---|---|---|---|
| DNS/CDN | Cloudflare | Free | $0 |
| Frontend | Vercel | Hobby | $0 |
| Backend | Railway | Starter | $5-20 |
| Database | Supabase | Free | $0 |
| Vectors | Qdrant Cloud | Free | $0 |
| Auth | Clerk | Free (500 MAU) | $0 |
| Payments | Stripe | Pay-as-go | 2.9% + $0.30 |
| Resend | Free (100/day) | $0 | |
| TOTAL | ~$50 |
Phase 2: Early Adopters (100-1,000 Users)¶
Timeline: Months 3-6 Monthly Cost: ~$300-500
graph TB
subgraph "Edge Layer"
CF[Cloudflare
WAF + Rate Limit] end subgraph "Compute" Vercel[Vercel Pro] Railway[Railway Teams
2 replicas] end subgraph "Data" Supabase[(Supabase Pro)] Redis[(Upstash Redis)] Qdrant[(Qdrant Starter)] R2[(Cloudflare R2)] end CF --> Vercel CF --> Railway Railway --> Supabase Railway --> Redis Railway --> Qdrant Vercel --> R2 style CF fill:#f97316,color:#fff style Vercel fill:#000,color:#fff style Railway fill:#6366f1,color:#fff style Supabase fill:#22c55e,color:#fff style Redis fill:#ef4444,color:#fff style Qdrant fill:#3b82f6,color:#fff style R2 fill:#f97316,color:#fff
WAF + Rate Limit] end subgraph "Compute" Vercel[Vercel Pro] Railway[Railway Teams
2 replicas] end subgraph "Data" Supabase[(Supabase Pro)] Redis[(Upstash Redis)] Qdrant[(Qdrant Starter)] R2[(Cloudflare R2)] end CF --> Vercel CF --> Railway Railway --> Supabase Railway --> Redis Railway --> Qdrant Vercel --> R2 style CF fill:#f97316,color:#fff style Vercel fill:#000,color:#fff style Railway fill:#6366f1,color:#fff style Supabase fill:#22c55e,color:#fff style Redis fill:#ef4444,color:#fff style Qdrant fill:#3b82f6,color:#fff style R2 fill:#f97316,color:#fff
Scaling Actions¶
| Trigger | Action | Cost Impact |
|---|---|---|
| 500+ users | Upgrade Supabase to Pro | +$25/mo |
| 50+ concurrent | Add Railway replica | +$10/mo |
| 10K+ vectors | Upgrade Qdrant | +$25/mo |
| 1K+ emails/day | Upgrade Resend | +$20/mo |
| Heavy caching | Add Upstash Redis | +$10/mo |
Phase 3: Growth (1,000-10,000 Users)¶
Timeline: Months 7-12 Monthly Cost: ~$1,000-2,000
graph TB
subgraph "Edge (Global)"
CF[Cloudflare Pro
WAF + Bot Protection] Workers[Workers
Edge Functions] end subgraph "US Regions" LB1[Load Balancer] App1[App Server 1] App2[App Server 2] App3[App Server 3] end subgraph "Data Layer" PG[(PostgreSQL
Primary)] PGR[(PostgreSQL
Read Replica)] Redis[(Redis Cluster)] Qdrant[(Qdrant Cloud
Production)] R2[(R2 Storage)] end subgraph "Async" Queue[BullMQ
Job Queue] Workers2[Background
Workers] end CF --> Workers Workers --> LB1 LB1 --> App1 & App2 & App3 App1 & App2 & App3 --> PG App1 & App2 & App3 --> PGR App1 & App2 & App3 --> Redis App1 & App2 & App3 --> Qdrant App1 --> Queue Queue --> Workers2 style CF fill:#f97316,color:#fff style Workers fill:#f97316,color:#fff style LB1 fill:#6366f1,color:#fff style App1 fill:#6366f1,color:#fff style App2 fill:#6366f1,color:#fff style App3 fill:#6366f1,color:#fff style PG fill:#22c55e,color:#fff style PGR fill:#22c55e,color:#fff style Redis fill:#ef4444,color:#fff style Qdrant fill:#3b82f6,color:#fff style R2 fill:#f97316,color:#fff style Queue fill:#eab308,color:#000 style Workers2 fill:#eab308,color:#000
WAF + Bot Protection] Workers[Workers
Edge Functions] end subgraph "US Regions" LB1[Load Balancer] App1[App Server 1] App2[App Server 2] App3[App Server 3] end subgraph "Data Layer" PG[(PostgreSQL
Primary)] PGR[(PostgreSQL
Read Replica)] Redis[(Redis Cluster)] Qdrant[(Qdrant Cloud
Production)] R2[(R2 Storage)] end subgraph "Async" Queue[BullMQ
Job Queue] Workers2[Background
Workers] end CF --> Workers Workers --> LB1 LB1 --> App1 & App2 & App3 App1 & App2 & App3 --> PG App1 & App2 & App3 --> PGR App1 & App2 & App3 --> Redis App1 & App2 & App3 --> Qdrant App1 --> Queue Queue --> Workers2 style CF fill:#f97316,color:#fff style Workers fill:#f97316,color:#fff style LB1 fill:#6366f1,color:#fff style App1 fill:#6366f1,color:#fff style App2 fill:#6366f1,color:#fff style App3 fill:#6366f1,color:#fff style PG fill:#22c55e,color:#fff style PGR fill:#22c55e,color:#fff style Redis fill:#ef4444,color:#fff style Qdrant fill:#3b82f6,color:#fff style R2 fill:#f97316,color:#fff style Queue fill:#eab308,color:#000 style Workers2 fill:#eab308,color:#000
Infrastructure Upgrades¶
| Component | Previous | Upgraded | Monthly Cost |
|---|---|---|---|
| CDN | Cloudflare Free | Cloudflare Pro | $20 |
| Compute | Railway 2x | 3+ app servers | $100-200 |
| Database | Supabase Pro | Supabase Team | $200-400 |
| Cache | Upstash Basic | Redis Cluster | $50-100 |
| Vectors | Qdrant Free | Qdrant Production | $100-200 |
| Storage | R2 Free | R2 Paid | $50-100 |
| Monitoring | Basic | Sentry + Datadog | $50-100 |
Phase 4: Scale (10,000-100,000 Users)¶
Timeline: Year 2+ Monthly Cost: ~$5,000-15,000
graph TB
subgraph "Global Edge"
CF[Cloudflare Enterprise]
CDN1[US Edge]
CDN2[EU Edge]
CDN3[APAC Edge]
end
subgraph "US-East"
K8S1[Kubernetes Cluster]
Auto1[Auto-Scaling]
end
subgraph "US-West"
K8S2[Kubernetes Cluster]
Auto2[Auto-Scaling]
end
subgraph "Data (Multi-Region)"
PGP[(Primary DB
US-East)] PGS[(Standby DB
US-West)] Redis1[(Redis US-E)] Redis2[(Redis US-W)] Qdrant1[(Qdrant
Distributed)] end CF --> CDN1 & CDN2 & CDN3 CDN1 --> K8S1 CDN2 --> K8S1 CDN3 --> K8S2 K8S1 --> PGP K8S2 --> PGS K8S1 --> Redis1 K8S2 --> Redis2 PGP -.->|Replication| PGS style CF fill:#f97316,color:#fff style CDN1 fill:#f97316,color:#fff style CDN2 fill:#f97316,color:#fff style CDN3 fill:#f97316,color:#fff style K8S1 fill:#6366f1,color:#fff style K8S2 fill:#6366f1,color:#fff style Auto1 fill:#6366f1,color:#fff style Auto2 fill:#6366f1,color:#fff style PGP fill:#22c55e,color:#fff style PGS fill:#22c55e,color:#fff style Redis1 fill:#ef4444,color:#fff style Redis2 fill:#ef4444,color:#fff style Qdrant1 fill:#3b82f6,color:#fff
US-East)] PGS[(Standby DB
US-West)] Redis1[(Redis US-E)] Redis2[(Redis US-W)] Qdrant1[(Qdrant
Distributed)] end CF --> CDN1 & CDN2 & CDN3 CDN1 --> K8S1 CDN2 --> K8S1 CDN3 --> K8S2 K8S1 --> PGP K8S2 --> PGS K8S1 --> Redis1 K8S2 --> Redis2 PGP -.->|Replication| PGS style CF fill:#f97316,color:#fff style CDN1 fill:#f97316,color:#fff style CDN2 fill:#f97316,color:#fff style CDN3 fill:#f97316,color:#fff style K8S1 fill:#6366f1,color:#fff style K8S2 fill:#6366f1,color:#fff style Auto1 fill:#6366f1,color:#fff style Auto2 fill:#6366f1,color:#fff style PGP fill:#22c55e,color:#fff style PGS fill:#22c55e,color:#fff style Redis1 fill:#ef4444,color:#fff style Redis2 fill:#ef4444,color:#fff style Qdrant1 fill:#3b82f6,color:#fff
Enterprise Features¶
| Feature | Implementation | Purpose |
|---|---|---|
| Multi-Region | US-East + US-West | Disaster recovery |
| Auto-Scaling | Kubernetes HPA | Handle traffic spikes |
| Read Replicas | PostgreSQL streaming | Query distribution |
| CDN Caching | Cloudflare Cache | Reduce origin load |
| Queue System | BullMQ + Redis | Async processing |
| Monitoring | Datadog + PagerDuty | 24/7 alerting |
Database Scaling Strategy¶
graph LR
subgraph "Phase 1"
P1[Single Instance
Supabase Free] end subgraph "Phase 2" P2[Supabase Pro
+ Connection Pooling] end subgraph "Phase 3" P3[Primary + Read Replica
+ PgBouncer] end subgraph "Phase 4" P4[Multi-Region
+ Sharding] end P1 --> P2 --> P3 --> P4 style P1 fill:#22c55e,color:#fff style P2 fill:#3b82f6,color:#fff style P3 fill:#6366f1,color:#fff style P4 fill:#f97316,color:#fff
Supabase Free] end subgraph "Phase 2" P2[Supabase Pro
+ Connection Pooling] end subgraph "Phase 3" P3[Primary + Read Replica
+ PgBouncer] end subgraph "Phase 4" P4[Multi-Region
+ Sharding] end P1 --> P2 --> P3 --> P4 style P1 fill:#22c55e,color:#fff style P2 fill:#3b82f6,color:#fff style P3 fill:#6366f1,color:#fff style P4 fill:#f97316,color:#fff
Query Optimization¶
| Strategy | When | Impact |
|---|---|---|
| Indexing | Day 1 | 10-100x faster queries |
| Connection Pooling | 100+ users | Reduce connections 90% |
| Read Replicas | 1,000+ users | Distribute read load |
| Query Caching | 5,000+ users | Reduce DB hits 50%+ |
| Sharding | 50,000+ users | Horizontal scale |
Caching Strategy¶
flowchart TD
Request[User Request] --> Edge{Edge Cache?}
Edge -->|HIT| EdgeResponse[Cloudflare Response]
Edge -->|MISS| Redis{Redis Cache?}
Redis -->|HIT| RedisResponse[Cached Data]
Redis -->|MISS| DB[(Database)]
DB --> Cache[Cache Result]
Cache --> Response[Response]
style Request fill:#3b82f6,color:#fff
style Edge fill:#f97316,color:#fff
style EdgeResponse fill:#22c55e,color:#fff
style Redis fill:#ef4444,color:#fff
style RedisResponse fill:#22c55e,color:#fff
style DB fill:#6366f1,color:#fff
style Cache fill:#eab308,color:#000
style Response fill:#22c55e,color:#fff
Cache Layers¶
| Layer | TTL | Use Case |
|---|---|---|
| Browser | 1 hour | Static assets |
| CDN (Cloudflare) | 5 min | API responses, images |
| Application (Redis) | 1-5 min | User sessions, deal data |
| Database | N/A | Query result caching |
Cost Projection¶
graph LR
subgraph "Monthly Costs by Phase"
A["Phase 1
$50-100"] B["Phase 2
$300-500"] C["Phase 3
$1K-2K"] D["Phase 4
$5K-15K"] end A --> B --> C --> D style A fill:#22c55e,color:#fff style B fill:#3b82f6,color:#fff style C fill:#6366f1,color:#fff style D fill:#f97316,color:#fff
$50-100"] B["Phase 2
$300-500"] C["Phase 3
$1K-2K"] D["Phase 4
$5K-15K"] end A --> B --> C --> D style A fill:#22c55e,color:#fff style B fill:#3b82f6,color:#fff style C fill:#6366f1,color:#fff style D fill:#f97316,color:#fff
| Users | Compute | Database | Services | Total/Month |
|---|---|---|---|---|
| 100 | $20 | $25 | $50 | $95 |
| 1,000 | $100 | $100 | $150 | $350 |
| 10,000 | $500 | $400 | $500 | $1,400 |
| 50,000 | $2,000 | $2,000 | $1,500 | $5,500 |
| 100,000 | $5,000 | $5,000 | $3,000 | $13,000 |
Performance Targets¶
| Metric | Phase 1 | Phase 2 | Phase 3 | Phase 4 |
|---|---|---|---|---|
| Page Load | <3s | <2s | <1.5s | <1s |
| API Response | <500ms | <300ms | <200ms | <100ms |
| Uptime | 99% | 99.5% | 99.9% | 99.99% |
| Error Rate | <5% | <2% | <0.5% | <0.1% |
Monitoring & Alerting¶
| Tool | Purpose | Phase |
|---|---|---|
| Vercel Analytics | Frontend metrics | 1+ |
| Sentry | Error tracking | 1+ |
| Uptime Robot | Availability | 1+ |
| Datadog | Full observability | 3+ |
| PagerDuty | On-call alerting | 3+ |
See Security Architecture for security scaling See System Design for technical details