<< All versions
Skill v1.0.0
currentAutomated scan100/100bedkillerspacex-boop/codex-skill-library/python-scale-out
──Details
PublishedOctober 24, 2026 at 08:48 AM
Content Hashsha256:134389196f56ebc2...
Git SHAeed9fd055798
──Files
Files (1 file, 4.1 KB)
SKILL.md4.1 KBactive
SKILL.md · 130 lines · 4.1 KB
version: "1.0.0" name: python-scale-out description: > Scale-out architecture notes for Python services: horizontal workers, shared-nothing vs shared state, session stickiness avoidance, queue-based fan-out, connection pools, and cache/data partitioning. Use when capacity planning or refactoring monoliths for horizontal scale on owned infrastructure.
Python Scale-Out
Scope And Authorization
- In scope: design and load tests for systems you operate.
- Out of scope: load testing third-party production without permission.
- Prefer staging capacity tests; production experiments with flags and abort criteria.
- Pair implementation changes with
code-quality-standards.
When To Use
- API/worker CPU-bound or connection-bound bottlenecks.
- Moving from single VM to multi-instance Kubernetes/ECS.
- Introducing read replicas, shards, or cache tiers for Python apps.
- Celery/RQ/arq worker autoscaling design.
Do Not Use As Primary
| Need | Skill instead | |
|---|---|---|
| Shard rebalance ops | python-shard-rebalance | |
| Scheduler/distributed jobs | python-scheduler | |
| Caching strategies | caching-strategies | |
| Backpressure | backpressure-patterns | |
| Implementation quality baseline | code-quality-standards |
Domain Focus
| Area | Guidance | |
|---|---|---|
| Stateless app | Push session to Redis/DB; JWT carefully; sticky only if temporary | |
| Workers | Horizontal consumers; prefetch limits; idempotent tasks | |
| Pools | DB/HTTP pools sized per instance x instances < DB max | |
| Data | Partition keys; avoid global locks; saga for multi-partition | |
| GIL | Multi-process for CPU; async for IO; native ext awareness | |
| Pitfalls | In-memory-only caches per node; unbounded task fan-out; thundering herd |
Workflow
1. Measure bottleneck
- Profile: CPU, GIL wait, DB, external IO, lock contention.
- Define SLI and target capacity (RPS, lag).
- Success: scale-out path that linearly helps the true bottleneck.
2. Make instances fungible
- Externalize sessions/files/uploads.
- Config via env; no local snowflake state.
- Health/readiness probes independent per instance.
3. Scale the right tier
- Web replicas behind LB for stateless HTTP.
- Workers scale on queue depth with max caps.
- DB: pool math + read replicas or cache before premature shards.
4. Protect dependencies
- Timeouts, bulkheads, circuit breakers.
- Load-shed when overloaded; prioritize critical traffic.
- Connection limits and retries with jitter.
5. Validate
- Load test with production-like data shape.
- Watch error budget and dependency saturation.
- Document scale playbook for on-call.
Verify with evidence
bash
# Pool math sketchpython - <<'PY'instances = 10pool_per = 20print('max db conns from app', instances * pool_per)PY# Locust/k6 against staging only# k6 run load.jspython -m pytest -q tests/idempotency# Celery inspect (owned)# celery -A app inspect active_queues
- Keep command output redacted (keys, tokens, customer IDs).
- Attach before/after evidence to the change or review ticket.
- Prefer automated tests or CI gates where regressions are likely.
Good / Bad
| Topic | Good | Bad | |
|---|---|---|---|
| Sessions | Redis/DB store | Local memory sticky forever | |
| Workers | Prefetch + idempotency | Ack late + duplicate side effects | |
| DB | Pool budget | Default pool x 100 pods | |
| Tests | Staging load with abort | Blind prod hammer |
Scale levers
| Lever | When | |
|---|---|---|
| More web pods | CPU/RPS bound stateless | |
| More workers | Queue lag | |
| Cache | Hot reads | |
| Read replica | Read-heavy SQL | |
| Shard | Single primary write limit | |
| Rewrite hot path | Algorithmic bottleneck |
Output Checklist
- [ ] Bottleneck identified with evidence
- [ ] Instances share no critical local state
- [ ] Pool/connection budgets documented
- [ ] Workers idempotent and capped
- [ ] Load test results attached
- [ ] On-call scale playbook updated
Rules
- Only load-test authorized environments.
- Horizontal scale is not a fix for O(n^2) queries - fix hotspots too.
- Keep security controls when adding nodes (mTLS, network policy).