40 per second rate limit after a CKSubscription

(This question is also posted deep inside a thread on the CloudKit forum. But since it relates to Notifications perhaps this is a better place for it.)


CloudKit has a feature whereby in response to a CKQuerySubscription the user will receive a push notification alert when certain CKRecords in CloudKit are changed. If they tap on that push notification alert then the app will open. CloudKit also has a limit of 40 queries per second - a number which is often quoted as large enough for almost any needs. But it's not because:


1) suppose an app has 10,000 users

2) all users subscribe to receive an alert notification when there is a change in a single important record

3) if that record changes only once every month

4) when that record changes many of the 10,000 will open their app at the exact same time after receiving the alert notification, or at most within few seconds of each other

5) If the app then tries to download that changed record the 40/second limit will be hit and it will take over 5 minutes to download the change to the 10,000.

6) This assumes the app does a masterful job of queueing the 10,000 based upon the error CKErrorRequestRateLimited


How do you deal with this issue?


One solution is to include the entire record information in the notification and not query CloudKit after the notification. You could do that using alertLocalizationArgs or desiredKeys. But the value of each key "may be truncated (to 100 characters) when added to the push notification" and desiredKeys is limited to 3 keys. Does anyone know the limit to the number of keys you can have in alertLocalizationArgs and the allowable size of a total notification? Help!

Accepted Reply

So I used a TSI and was told:

- throttling occurs when the total number of fetches exceeds 40 in a second

- An APN (notification) from a CKQuerySubscription firing can be either 2k or 4k (unclear - they are checking this).

- The notification can contain many alertLocalizationArgs.

- Each alertLocalizationArg can be 100 characters long.


So what I am doing is breaking up my CKRecord (the one I want the app to fetch) into 100 character long strings and placing each string in an alertLocalizationArgs. Then in didReceiveNotificationResponse: I am reconstructing the CKRecord and using that temporarily. I will not do a fetch if the user taps the alert. If the user opens the app normally then I will do a fetch and replace this temporary CKRecord with the real fetched CKRecord. This way a CKQuerySubscription will not result in many simultaneous fetchs exceeding the 40/second limit.

Replies

So I used a TSI and was told:

- throttling occurs when the total number of fetches exceeds 40 in a second

- An APN (notification) from a CKQuerySubscription firing can be either 2k or 4k (unclear - they are checking this).

- The notification can contain many alertLocalizationArgs.

- Each alertLocalizationArg can be 100 characters long.


So what I am doing is breaking up my CKRecord (the one I want the app to fetch) into 100 character long strings and placing each string in an alertLocalizationArgs. Then in didReceiveNotificationResponse: I am reconstructing the CKRecord and using that temporarily. I will not do a fetch if the user taps the alert. If the user opens the app normally then I will do a fetch and replace this temporary CKRecord with the real fetched CKRecord. This way a CKQuerySubscription will not result in many simultaneous fetchs exceeding the 40/second limit.