What happens when API rate limit is exceeded?

Suppose we have a system that looks like the following:

// taking place inside of a promise
Spark.getDevice(serialNumber).then(function(device) {
  device.getVariable('varName').then((data) => {
    // update a record
    // updatedRecord = {some: stuff}
  }).then(() => {
    // check another variable every so often
    if( ! waitedLongEnough() ) {
      return resolve(updatedRecord);
    }
    device.getVariable('varName2').then((data) => {
      // put some more data in updatedRecord
      return resolve(updatedRecord);
    }).catch((err) => {
      // error getting varName2
      addNewFailedCall();
      return resolve(updatedRecord);
    });
  }).catch((err) => {
    // error getting varName1
    addNewFailedCall();
    return resolve(updatedRecord);
  });
}).catch( (err) => {
  // error getting device
  return reject(err);
});

This code gets called roughly once per minute for each chip, for approximately 100 chips. The calls are distributed over a 20-second window.

What happens if the API rate limit is exceeded by this code? Will an error be returned/thrown? Will the SDK just not do anything?

Hi @cmn_jcs,

At the moment there is a safeguard rate limit on the api of around 30-60 requests per second from any one IP address. Requests above that limit get dropped or get error responses. This limit is somewhat flexible, and it’s meant to be mostly a protective measure.

If you want to pull bulk data from your devices, I would recommend opening one events socket, and having your device publish data updates. This will be faster / closer to realtime data access, and will have significantly less complexity / overhead, and you’ll avoid any request rate limiting, etc, etc. :slight_smile:

I hope that helps!

Thanks,
David

Ok, thanks for the info. This is part of a status system; we’re using active polling to confirm that systems are online and are less concerned about the particular data. Once the normal online/offline reporting system is reliable, we’ll probably fall back to using that.

Hi @cmn_jcs,

Alternatively, you could have all your devices subscribe to a “ping” event or something similar, and have them publish a “pong” in response. Then you could publish one message, and get a list of all online devices in the same way, etc, etc.

Thanks,
David

3 Likes