PostgreSQL connection pooling requirements at scale, staggering heartbeat schedules to spread API load, memory growth patterns, cost explosion risks, and the practical upper limits.
Strategies for scaling a Paperclip company from 5 agents to 50, understand the database and API rate limit constraints, and plan for horizontal scaling.
In Paperclip, the following scale without configuration changes:
FOR UPDATE SKIP LOCKED stays efficient up to hundreds of concurrent claimsheartbeat_runs and cost_events grow indefinitely; archive strategy covers this (pcl-50)The real scaling constraint is LLM API rate limits:
| Provider | Default rate limit |
|---|---|
| Anthropic | Varies by tier; starts ~50K tokens/min |
| OpenAI | Varies by tier; starts ~500K tokens/min |
| Groq | Very high; good for parallel scaling |
| Ollama | Hardware-limited |
Strategy: distribute agents across multiple API keys / providers:
// Some agents use claude-code, others use openai, others use groq
// Each uses a different API key → different rate limit bucket
{ "agent_1_adapter": "claude-code", "agent_2_adapter": "openai", "agent_3_adapter": "groq" }
For high-volume production (>10K issues/day):
CREATE INDEX CONCURRENTLY idx_issues_status_company
ON issues (company_id, status, priority, created_at)
WHERE status = 'open';
CREATE INDEX CONCURRENTLY idx_cost_events_month
ON cost_events (company_id, date_trunc('month', created_at));
cost_events by month (once >10M rows):-- Range partitioning
CREATE TABLE cost_events_2024_01 PARTITION OF cost_events
FOR VALUES FROM ('2024-01-01') TO ('2024-02-01');
Run multiple instances of the Paperclip API server:
FOR UPDATE SKIP LOCKED pattern ensures no double-work across instancesLoad Balancer
├── API Server 1 (heartbeat + API requests)
├── API Server 2 (heartbeat + API requests)
└── API Server 3 (heartbeat + API requests)
↓
PostgreSQL (single primary, read replicas)
□ Indexes on (company_id, status) for issues table
□ Indexes on (company_id, created_at) for cost_events
□ Multiple API key providers to spread rate limits
□ Read replica for reporting dashboards
□ Heartbeat interval tuned to task volume (not "every 1 min")
□ max_concurrent_agents set per company
□ Archive strategy for old runs and cost events