title: Shopify API : Call limit
body: <p>Im getting "Too many requests" 429(code) error while making burst api calls.</p>
  
  <p>Here is what I'm doing.</p>
  
  <p>Make 39 requests simultaneously and wait for requests to complete. If any request's response is received, immediately make new another request. With completion of any request the number of requests in shopify bucket should decrease and new made request should be processed. But I still get "Too many requests" error.</p>
  
  <p>Here is the code snippet</p>
  
  <pre><code>    // aquire a permit to enter into block
      boundedSemaphore.acquire();
  
      // Hit the shopify api
      Response response = RestUtils.invoke(URL, operation,
              MediaType.APPLICATION_JSON_TYPE, headerMap, queryParameterMap,
              MediaType.APPLICATION_JSON_TYPE, signatureMethod);
  
      // Check response       
      if (!RestUtils.isValidStatusCode(response.getStatus())) {
          throw new SystemException("Status :" +response.getStatus());
      }
      if (response.getHeaderString(X_SHOPIFY_SHOP_API_CALL_LIMIT)
              .equalsIgnoreCase("39/40"))
          Thread.sleep(10000);
  
      // release permit for other threads to enter            
      boundedSemaphore.release();
  </code></pre>
  
  <p>At any given time there are no more than 39 requests active from my side. </p>
  
  <p>The boundedSemaphore is java.util.concurrent.Semaphore with max 39 permits. Only 39 threads can enter this particular block at a time. With completion of any request the semaphore will release a permit and new thread will aquire it and will make a new request.</p>
  
  <p>Shopify bucket size is 40 requests with the leak rate of 2 requests per second so no request should trip with "Too many requests" error.</p>
  
  <p>Does anyone know what is the cause of this issue.</p>