Solved

Best way to guarantee idempotency of a particular notification

  • 11 May 2023
  • 7 replies
  • 282 views

Assume that a system has an event: user_application_approved with data payload { userId: UUID, email: } 

Lets say the backend system sends a duplicate event for some reason… how can CustomerIO prevent triggering a duplicate campaign action (sending an email) for the EXACT same event. Is there a way to achieve this? Or are we at the mercy of the backend not sending duplicate events? 

 


 

icon

Best answer by shanbady 16 June 2023, 18:59

View original

7 replies

Userlevel 4

Hi @rushil23 ,

 

To prevent duplicate events from being processed, you can provide an id with your events, to deduplicate events. If two events contain the same id, we won’t process the event multiple times.

 

This section of our help documentation goes over this in more detail: https://customer.io/docs/journeys/events/#deduplicating-events

 

I hope this was helpful!

Hey @penny: we tried that; I’m still seeing duplicate events. 

FYI: We’re using the NodeJS library - https://www.npmjs.com/package/customerio-node

 

Userlevel 4

Hi @rushil23,

 

Happy to help! Per our help doc link above, as well as our API documentation for this particular endpoint: https://customer.io/docs/api/track/#operation/track.

 

For the event ID, it needs to be: 

string <ulid>

An identifier used to deduplicate events. This value must be a ULID. If an event has the same value as an event we previously received, we won't show or process the duplicate.

 

Could you please try using and ULID and see if this resolves the issue for you? :) 

Yup, works, thanks! 

@Penny on my end I still can’t get this to work. I created a campaign that basically increments an attribute every time someone enters the campaign (campaign trigger is set to an event). The event I’m sending looks like so:

{

“name”:”session_end”

id: "5908981DCF3BCC6CE2797DF1DF"

...

}

 

I believe the id im using is a valid ulid but every time i resend the event, the user goes through the campaign again and the attribute is incremented.

Userlevel 4

Hi @shanbady ,

I can confirm that the ULID you shared above is a valid one. 

Would you mind checking your API request body payload to check it is properly formatted? 

When I send the following payload to my test workspace:

{

"name": "session_end",

"id": "5908981DCF3BCC6CE2797DF1DF"

}

 

I can confirm that only 1 event is successfully logged in my Customer.io workspace (even though I sent the same request multiple times.) :) 

But if you still face any difficulty, please share the full API request payload (redacting any sensitive information and your API keys) and we’d be happy to dig deeper into this for you. :) 

@Penny I sorted out the issue with the help of support. It turns out I was sending the id as part of the “data” field:

{

"name": "session_end",

“data”: {

        "id": "5908981DCF3BCC6CE2797DF1DF"

….

    }

}

 

When I should be sending it with the “name” attribute:

 

{

"name": "session_end",

"id": "5908981DCF3BCC6CE2797DF1DF",

“data”: {

….

    }

}

 

Also - It turned out that the official python sdk does not support sending an id. To get around this, I subclassed the CustomerIO class and overrode the “track” method so you can pass along the event id like so:

 

 

Reply