This project demonstrates a highly robust, multi-threaded worker pool utilizing Python's ThreadPoolExecutor. It features a custom Token-Bucket Rate Limiter and safely handles shared state without lost-update race conditions.
Concurrent Rate-Limited Worker Pool | Python, ThreadPoolExecutor, Threading
- Built a multi-threaded worker pool with a custom token-bucket rate limiter using Semaphores and a background refill thread, enforcing a strict global request rate across concurrent workers without burst overruns.
- Implemented Lock-protected shared state to safely aggregate results across threads, preventing lost-update race conditions on shared counters under simulated partial failures.
- Token-Bucket Rate Limiter: A background thread refills tokens at a fixed rate, ensuring strict API request limits are not exceeded globally across the entire pool.
- Race Condition Prevention: Uses
threading.Lockto guarantee atomic increments on state aggregation. - Simulated External API: Simulates network latency and partial failures.
- Concurrency: Scales out processing utilizing Python's
ThreadPoolExecutor.
# Clone the repository
git clone https://github.com/YourUsername/concurrent-worker-pool.git
cd concurrent-worker-pool
# Run the pool execution simulation
python worker_pool.pyThis project is designed to showcase advanced backend engineering capabilities with concurrent Python environments.