Architecture
Overview
PoolSwitch is built around one shared routing engine.
That core is reused in two product surfaces:
- Embedded clients
- Proxy server
In both modes, the same components handle state and failover.
Components
- Embedded clients: direct in-process clients for Python and Node.js
- Proxy server: HTTP wrapper around the same routing engine for multi-language access
- Storage: memory, Redis, and SQLite persistence for key state
- Strategies: algorithms like
round_robin,least_used, andquota_failover - Core pool: central state transitions for success, cooldown, and key lifecycle
- Quota and retry: provider-agnostic quota evaluation and exponential backoff retry policies
Request lifecycle
- PoolSwitch selects a healthy key.
- It injects the provider auth header.
- It sends the upstream request.
- It classifies the upstream result:
- success
- retryable rate limit
- quota exhaustion
- network failure
- It updates key state, cooldowns, failovers, and metrics.
- It returns the final parsed result or final error.
Retry model
Retries occur only before a successful upstream response is accepted by the caller.
- Network failures: retry with exponential backoff
429: retry and prefer a different key- Quota exhaustion: place the key into cooldown and fail over
- Safe methods are configurable through
retryable_methods
Metrics
Prometheus-compatible /metrics includes:
poolswitch_requests_totalpoolswitch_failovers_totalpoolswitch_key_usage_totalpoolswitch_key_errors_totalpoolswitch_request_latency_secondspoolswitch_key_cooldown_active