1 of 20

Handle API throttling with Tenacity

2 of 20

Thomas BERDY, backend developer at SEELK

kozlek

thomas-berdy

kozlek

thomas.berdy@seelk.co

3 of 20

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

4 of 20

API usage at Seelk

5 of 20

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

6 of 20

A solution: Tenacity

A framework to handle the retry mechanism

Ship with a configurable retry decorator

3 main settings: retry, wait, and stop

🖼

🛠

🚦

7 of 20

8 of 20

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)

9 of 20

10 of 20

Step by step a Spotify API client

11 of 20

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?

🤔

🚦

12 of 20

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

13 of 20

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

14 of 20

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

15 of 20

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

16 of 20

Step by step It’s working!

17 of 20

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%

18 of 20

Any questions?

thomas.berdy@seelk.co

19 of 20

🍭 Goodies 🍬

20 of 20

Goodies Async support