name: scaling-patterns description: | Scaling patterns: horizontal/vertical scaling, async processing, data partitioning, connection pooling, rate limiting, backpressure. Use when scaling services. allowed-tools: Read, Grep, Glob
Scaling Patterns
When to use
- Scaling a service beyond current capacity
- Choosing between horizontal and vertical scaling
- Implementing async processing, sharding, or rate limiting
Core principles
- Measure before scaling — profile first, scale second
- Stateless services scale horizontally — move state to databases/caches
- Connection pooling is mandatory — direct connections exhaust DB limits
- Backpressure prevents cascading failure — reject early rather than queue forever
- Rate limiting protects everyone — including your own services from each other
References available
references/horizontal-scaling.md— stateless services, load balancing, autoscaling configsreferences/vertical-scaling.md— when vertical is enough, instance sizing, connection pool tuningreferences/resource-optimization.md— CPU/memory profiling, bottleneck identification, LRU cache, I/O optimizationreferences/async-processing.md— queues (SQS, RabbitMQ, Kafka), worker patterns, backpressure, circuit breakerreferences/background-jobs.md— BullMQ job scheduling, retry with exponential backoff, DLQ management, cron workersreferences/data-partitioning.md— sharding strategies, partition key design, consistent hashing, PostgreSQL native partitioningreferences/shard-management.md— shard rebalancing, cross-shard queries, scatter-gather, operational concerns
Scripts available
scripts/estimate-capacity.sh— input RPM and data size, output infra recommendations