user2259674
user2259674

Reputation: 121

How to handle out of order Box events?

I read the documentation about Box event, and was kind of lost about how to handle out-of-order box event correctly.

According to the doc,

Events will occasionally arrive out of order. For example a file-upload might show up before the Folder-create event. You may need to buffer events and apply them in a logical order.

Let's say, I get two ITEM_UPLOAD events back from box server, which are for uploading file_1 and file_2, and ITEM_UPLOAD event for uploading file_2 comes earlier than the one for uploading file_1.

However, what really happens at server side is that uploading file_1 is slightly earlier than uploading file_2, and the timing difference is so little that the "created_at" and "recorded_at" values for both events are same. The resolution of those two time stamps are second level.

at the point, I can not tell exactly which one happens firstly, because there is no good measurement as a reference to judge.

Could you please give me some information to work out this situation?

many thanks.

=========================================================

ITEM_UPLOAD event might not be a good example here. What if I am more concerned about ITEM_RENAME event? Let's say our app can rename local file based on the ITEM_RENAME event. Somehow I get two ITEM_RENAME events on same file which are out of order but with same timestamp. How can I know which name value I should use in the two events without caching all box objects' meta data (like sequence_id)?

Upvotes: 0

Views: 192

Answers (1)

Peter
Peter

Reputation: 2599

I think you'll need to provide additional details about why you'd care. In your example, if 2 files are uploaded and arrive at the same second, why would you care what order they come across in the event stream?

The more challenging problems are when a folder-create and a file-upload event arrive out of order. If you are trying to use the events to create the file locally, and the folder_id that the file says it is in hasn't gotten to you yet in the events stream, then you don't really know where to put this new file.

Similar problems can happen in microprocessor design, when you have multiple cores handling different parts of a problem. You essentially have to be able to set aside the piece of work until later, and process it when you have enough information assembled.

What usually works is to process items as you get them, and if you don't have enough information to process the item, set it aside and check it when you are next idle. As you note, waiting a second or two is usually long enough, though items can get out of sequence by as much as several seconds.

Upvotes: 1

Related Questions