# Aerostack vs. Traditional Infrastructure Setup

> See how Aerostack replaces 8 separate infrastructure services with one SDK. Side-by-side comparison against traditional backend setups.

When building custom APIs, developers traditionally face days of infrastructure configuration. Here's how Aerostack changes that equation.

## The Traditional Approach

Building a production-ready API with database, cache, queue, and storage typically involves:

### Step 1: Database Setup (2-4 hours)
```bash
# Configure read replicas for scaling
```

**Challenges:**
- Connection pool management
- Migration versioning across environments
- Backup and disaster recovery
- Monitoring and alerting
- Cost optimization (reserved instances, auto-scaling)

### Step 2: Cache Setup (1-2 hours)
```bash
# Set up monitoring and alerts
```

**Challenges:**
- Key namespace collisions
- TTL strategy management
- Memory optimization
- Failover configuration

### Step 3: Message Queue Setup (3-5 hours)
```bash
# Set up monitoring dashboards
```

**Challenges:**
- Worker process management
- Error handling and retries
- Job prioritization
- Scaling workers based on queue depth

### Step 4: Object Storage (1-2 hours)
```bash
# Set up access logging
```

**Challenges:**
- Permission management (IAM policies)
- CDN cache invalidation
- Cost optimization (storage classes)

### Step 5: Deployment and DevOps (2-3 hours)
```bash
# Configure authentication
```

**Total Time:** **1-3 days** minimum for experienced developers

---

## The Aerostack Approach

### Write Your API (2-5 minutes)

```javascript

  const { query, category } = event.data;
  
  // Cache is ready
  const cached = await sdk.cache.get(`search:${query}`);
  if (cached) return cached;
  
  // Database is ready
  const products = await sdk.db.query(
    'SELECT * FROM products WHERE name LIKE ? AND category = ?',
    [`%${query}%`, category]
  );
  
  // Cache with TTL
  await sdk.cache.set(`search:${query}`, products, 3600);
  
  // Enqueue background job
  await sdk.queue.enqueue('update-search-stats', { query, count: products.length });
  
  return { results: products };
}
```

**What's included automatically:**
✅ Database (auto-scoped to your project)  
✅ Cache (namespace isolation, TTL support)  
✅ Queue (workers auto-managed)  
✅ Secrets (encrypted storage)  
✅ Rate limiting (per-endpoint configuration)  
✅ Authentication (API keys or public access)  
✅ Global edge deployment  
✅ Monitoring and logging  

**Total Time:** **2-5 minutes** (write code → deploy)

---

## Side-by-Side Comparison

| Feature | Traditional Setup | Aerostack |
|---------|-------------------|----------|
| **Database** | 2-4 hours (provision, configure, migrate) | `sdk.db.query()` |
| **Cache** | 1-2 hours (provision, configure namespaces) | `sdk.cache.set/get()` |
| **Queue** | 3-5 hours (provision, workers, retries) | `sdk.queue.enqueue()` |
| **Storage** | 1-2 hours (buckets, CDN, permissions) | `sdk.storage.upload()` |
| **Secrets** | 30 min (vault setup, env vars) | `sdk.secrets.get()` |
| **AI Models** | 1-2 hours (API keys, billing, rate limits) | `sdk.ai.chat()` - 30+ models |
| **Authentication** | 2-4 hours (implement JWT, refresh tokens) | Built-in API keys |
| **Rate Limiting** | 1-2 hours (implement middleware) | Built-in per-endpoint |
| **Monitoring** | 2-3 hours (logging, metrics, alerts) | Built-in dashboard |
| **Deployment** | 1-2 hours (CI/CD, environments) | One-click deploy |
| **Total Time** | **1-3 days** | **2-5 minutes** |

---

## Real-World Scenario: E-commerce Product Search

### Traditional Infrastructure (AWS)

**Infrastructure needed:**
- RDS PostgreSQL (database)
- ElastiCache Redis (cache)
- SQS + Lambda (queue)
- S3 + CloudFront (storage)
- Secrets Manager (API keys)
- API Gateway + Lambda (API)
- CloudWatch (monitoring)

**Monthly cost estimate:** $200-500 for low-medium traffic

**Time to production:** 2-3 days for setup + ongoing maintenance

### Aerostack

**All infrastructure included in one SDK:**
```javascript

  const { query, filters, page = 1 } = event.data;
  
  const cacheKey = `search:${query}:${JSON.stringify(filters)}:${page}`;
  const cached = await sdk.cache.get(cacheKey);
  if (cached) return cached;
  
  const results = await sdk.db.query(`
    SELECT * FROM products 
    WHERE name LIKE ? 
    AND category = ? 
    AND price BETWEEN ? AND ?
    ORDER BY popularity DESC
    LIMIT 20 OFFSET ?
  `, [`%${query}%`, filters.category, filters.minPrice, filters.maxPrice, (page - 1) * 20]);
  
  await sdk.cache.set(cacheKey, results, 3600);
  
  // Track search analytics async
  await sdk.queue.enqueue('track-search', { query, results: results.length });
  
  return { results, page };
}
```

**Monthly cost:** Included in Aerostack subscription

**Time to production:** 5 minutes

---

## When to Choose Each

### Choose Traditional Infrastructure When:
- ❌ You need complete control over every infrastructure detail
- ❌ You have existing infrastructure investments
- ❌ You're building infrastructure-first architecture
- ❌ You have a dedicated DevOps team managing infrastructure

### Choose Aerostack When:
- ✅ You want to focus on business logic, not DevOps
- ✅ You need production-ready infrastructure immediately
- ✅ You're building a SaaS with 10-100 custom endpoints
- ✅ You value time-to-market and developer experience
- ✅ You want predictable pricing without infrastructure surprises
- ✅ You need pre-built APIs (auth, ecommerce) + custom logic

---

## Developer Experience

### Traditional Setup
```bash
# Every new developer needs:
- Access to AWS/GCP console
- Understanding of infrastructure architecture
- Knowledge of connection strings, secrets
- Setup local development environment
- Configure multiple services
Time: 1-2 days onboarding
```

### Aerostack
```javascript
// Every developer gets:

// Everything just works
await sdk.db.query('...');
await sdk.cache.set('...');
await sdk.queue.enqueue('...');

// Time: 5 minutes to first API
```

---

## Try Aerostack Free

Ready to skip the infrastructure setup?
