Rate-Limit-Aware Price and Stock Synchronization for Distributor APIs
- System Architecture
- Distributed Systems
- Performance Optimization
Technology stack
- Python
- Django
- Celery
- Redis
- PostgreSQL
Challenge
Retailers needed current prices and stock from distributors. Several APIs returned data only for requested items and shared a request limit across all retailers on the platform.
Large catalog scans could run past the broker’s one-hour visibility timeout and be delivered again. An incomplete run could also remove valid prices during cleanup.
My Approach
- Documented the architectural trade-offs in an ADR and used ports and adapters to decouple price and stock retrieval from ordering.
- Split long jobs into short, resumable batches using keyset pagination to stay within the broker’s visibility timeout.
- Used an upsert-only loader to preserve valid prices during partial runs.
- Enforced each distributor’s request budget with a Redis rate limiter shared by all workers.
- Added heartbeats and a read-only monitor of broker state to distinguish active, waiting and orphaned runs.
Outcome
Querying by product size brought one distributor’s catalog discovery to about 41 minutes, compared with an estimated 68 hours for an item-by-item scan. Starting from the distributor’s known assortment reduced a store’s initial load from about 6,000 API calls to about 600.
The same synchronization engine serves four distributor APIs. Adding a distributor requires an adapter and a registry entry.