Handle API throttling with Tenacity
Thomas BERDY, backend developer at SEELK
kozlek
thomas-berdy
kozlek
thomas.berdy@seelk.co
Founded in 2016, fast growth to a team of 40 Amazon experts
International operations on Amazon Europe, USA and Australia
+10M€ GMV, +3M€ media spend in EU5 + US
We manage all Amazon models
Now part of
Joined Webedia Group in 2019 to become the european leader by 2021
+20 accounts handled on Seller Central
+20 accounts handled on Vendor Central
+5 accounts handled in hybrid mode
Seelk, 100% Amazon focus
API usage at Seelk
What is API throttling?
Limit the access rate to API endpoints
Avoid servers crashes when traffic spikes
Distribute the server resources between users
✅
✅
✅
Often linked to a pricing model
✅
A solution: Tenacity
A framework to handle the retry mechanism
Ship with a configurable retry decorator
3 main settings: retry, wait, and stop
🖼
🛠
🚦
Step by step • a Spotify API client
Retrieve an artist
List his albums
For each albums, retrieve the tracklist
1)
2)
3)
Retrieve the data of every tracks
4)
Step by step • a Spotify API client
Step by step • a retry strategy
When should I retry my call?
How much time should I wait between two calls?
When should I stop retrying?
🤔
⏱
🚦
Step by step • Configuring Tenacity to follow your strategy (1)
When should I retry my call?
📡When there is a Network error
🚦Where there is a Throttling error
Step by step • Configuring Tenacity to follow your strategy (2)
How much time should I wait between two calls?
📡Network error -> retry right away
🚦Throttling error -> retry after the time indicated by Spotify
Step by step • Configuring Tenacity to follow your strategy (3)
Assemble everything
📡Combine retry conditions
⏱Wait the required time + some random seconds
✋Stop after a chosen number of trials
📝Log the amount of time to sleep
Step by step • Add your decorator to your client
Final touch
🧩Make use of decorators to keep the code clean and reusable
🚦Adjust the max_retries setting depending on the endpoint
Step by step • It’s working!
Benefits of Tenacity usage at Seelk
🚀From ~1200 successful requests per hour to 1720, for a theoretical maximum of 1800 requests per hour
⏱Reduce the application crashes by 80%
Any questions?
thomas.berdy@seelk.co
🍭 Goodies 🍬
Goodies • Async support