scalelisted
Install: claude install-skill diegosouzapw/awesome-omni-skill
# Cloudflare Scaling Skill
Strategies for scaling Cloudflare architectures beyond default limits while maintaining cost efficiency.
## Scaling Decision Matrix
| Bottleneck | Symptom | Solution |
|------------|---------|----------|
| D1 read latency | >50ms queries | Add KV cache layer |
| D1 write throughput | Queue backlog | Batch writes, add queue buffer |
| D1 storage | Approaching 10GB | Archive to R2, partition tables |
| KV read latency | Cache misses | Key prefixing, predictable keys |
| KV write rate | 1 write/sec/key limit | Shard keys, batch writes |
| R2 throughput | Slow uploads | Presigned URLs, multipart |
| Worker memory | 128MB limit | Streaming, chunked processing |
| Worker CPU | 30s timeout | Queues, Workflows, DO |
| Subrequests | 1000/request limit | Service Bindings RPC |
| Queue throughput | Consumer lag | Increase concurrency, batch size |
## Caching Strategies
### Cache Hierarchy
```
Request → Edge Cache → KV Cache → D1 → Origin
(Tiered) (Global) (Primary)
```
### KV Cache Patterns
#### Write-Through Cache
```typescript
async function getWithCache<T>(
kv: KVNamespace,
db: D1Database,
key: string,
query: () => Promise<T>,
ttl: number = 3600
): Promise<T> {
// Try cache first
const cached = await kv.get(key, 'json');
if (cached !== null) {
return cached as T;
}
// Cache miss - fetch from D1
const fresh = await query();
// Write to cache (non-blocking)
kv.put(key, JSON.stringify(fresh), { expiration