Duplicated Event Messages

I have 5 products in operation with a web app that subscribes to the event streams from each product’s devices and logs or acts on those events. Recently I have noticed that there are duplicate events being received. Sometimes these are duplicates (2 the same) and some times triplicates (3 the same) and very occasionally quadruplicates (4 the same). I know that they are the same because the message contain a date/time stamp in the data body when they were created. The duplicates are across all products and are random.

In the past I have seen duplicates where the web app subscribed to both a user account and the product account - every event was duplicated. This issue was addressed a while back once all devices were moved to be products.

There is a possibility that the device is resending the event message [each device has a store and send mechanism which only deletes the messages when there is a confirmed publish].

Just wondering if anyone else has seen duplicated messages at their web apps?

Yes, there is no automatic duplicate removal and it can occur in several cases:

  • If the event is successfully sent, but the ACK is lost, then the event will be retransmitted and a duplicate will occur.
  • If the event is sent WITH_ACK, and there is no response for 20-ish seconds, false will be returned from Particle.publish() but at least one more attempt will be made, so you could get a duplicate there.
  • If you do something like subscribe to the event as a way to help eliminate lost events, if the subscription is lost, there could be a duplicate event.

Thanks - I using devices that are all photons and I am just testing for Particle.publish() true rather than using the WITH_ACK flag. Is this what you meant by the first 2 bullets? I only delete the message from the message queue if the publish is successful so it could be that the publish is reported as false (unsuccessful) but actually is? Of course it better that messages are sent than not but also trying to not confuse users looking at event logs!

It is possible for Particle.publish to return false but for the event to still go out later. It definitely can happen on the Electron. It’s probably less likely on the Photon, but it probably could still occur if you published and had the cloud disconnect in the middle of the publish. Particle.publish could return false but the event may go out again after reconnection. I think.