Adding some wait time between API requests to avoid overloading the server In Shopify a product can belong to a collection.
I have written a method which accepts an organisation. It would then get a list of collections that this organisation has from Shopify. Finally, it has to loop through each collection to get the products that belong to this collection.
I don't want to overload Shopify server by sending too many requests, so I have added 75 ms wait between each request. But since this method is async, I am not quite sure if the responses are handled correctly? Do I need any sort of mutext or locking mechanism to ensure each response is being handled correctly?
public async Task&lt;List&lt;ShopifyCollection&gt;&gt; GetShopifyCollections(Organisation organisation)
{
    int waitInMilliSeconds = 50;
    var shopifyCollections = new List&lt;ShopifyCollection&gt;();
    var customCollections = await GetAllCustomCollections(organisation);

    foreach (var cc in customCollections)
    {
        shopifyCollections.AddCollection(cc.Id, cc.Title);
    }

    foreach (var curCollection in shopifyCollections)
    {
        var products = await GetCollectionProducts(organisation, curCollection.CollectionId);
        curCollection.ProductIds = products.Where(p =&gt; p.Id != null &amp;&amp; p.Id &gt; 0).Select(p =&gt; p.Id.Value).ToList();
        await Task.Delay(waitInMilliSeconds);   // &lt;-- do not overload Shopify 
    }

    return shopifyCollections;
}
Create throttling for API calls is just one aspect of making your API integration resilient. There are many other types of failures to handle. Instead of weaving the error handling into your code, you should consider using something like Polly https://github.com/App-vNext/Polly
There a more details on it here http://www.thepollyproject.org/2018/03/06/policy-recommendations-for-azure-cognitive-services/