<< All versions

Skill v1.0.0

currentAutomated scan100/100
bedkillerspacex-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

NeedSkill instead
Shard rebalance opspython-shard-rebalance
Scheduler/distributed jobspython-scheduler
Caching strategiescaching-strategies
Backpressurebackpressure-patterns
Implementation quality baselinecode-quality-standards

Domain Focus

AreaGuidance
Stateless appPush session to Redis/DB; JWT carefully; sticky only if temporary
WorkersHorizontal consumers; prefetch limits; idempotent tasks
PoolsDB/HTTP pools sized per instance x instances < DB max
DataPartition keys; avoid global locks; saga for multi-partition
GILMulti-process for CPU; async for IO; native ext awareness
PitfallsIn-memory-only caches per node; unbounded task fan-out; thundering herd

Workflow

1. Measure bottleneck

  1. Profile: CPU, GIL wait, DB, external IO, lock contention.
  2. Define SLI and target capacity (RPS, lag).
  3. Success: scale-out path that linearly helps the true bottleneck.

2. Make instances fungible

  1. Externalize sessions/files/uploads.
  2. Config via env; no local snowflake state.
  3. Health/readiness probes independent per instance.

3. Scale the right tier

  1. Web replicas behind LB for stateless HTTP.
  2. Workers scale on queue depth with max caps.
  3. DB: pool math + read replicas or cache before premature shards.

4. Protect dependencies

  1. Timeouts, bulkheads, circuit breakers.
  2. Load-shed when overloaded; prioritize critical traffic.
  3. Connection limits and retries with jitter.

5. Validate

  1. Load test with production-like data shape.
  2. Watch error budget and dependency saturation.
  3. Document scale playbook for on-call.

Verify with evidence

bash
# Pool math sketch
python - <<'PY'
instances = 10
pool_per = 20
print('max db conns from app', instances * pool_per)
PY
# Locust/k6 against staging only
# k6 run load.js
python -m pytest -q tests/idempotency
# Celery inspect (owned)
# celery -A app inspect active_queues
  1. Keep command output redacted (keys, tokens, customer IDs).
  2. Attach before/after evidence to the change or review ticket.
  3. Prefer automated tests or CI gates where regressions are likely.

Good / Bad

TopicGoodBad
SessionsRedis/DB storeLocal memory sticky forever
WorkersPrefetch + idempotencyAck late + duplicate side effects
DBPool budgetDefault pool x 100 pods
TestsStaging load with abortBlind prod hammer

Scale levers

LeverWhen
More web podsCPU/RPS bound stateless
More workersQueue lag
CacheHot reads
Read replicaRead-heavy SQL
ShardSingle primary write limit
Rewrite hot pathAlgorithmic 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).
All versions