Skip to main content
Contributor I
February 17, 2025
Solved

custom webhook events fired in async manner

  • February 17, 2025
  • 4 replies
  • 96 views

We have a custom webhook being fired when. a user subscribes and also when a user unsubscribes. But, the webhook events are fired in an aync manner and the user activity is not reliable.
eg. user subscribed and then unsubscribed as per below screen print, but the backend system received the unsubscribed event first and then the subscribed event, hence creating data inconsistency in the backend system.
how can we ensure the sequence of webhook events?
 

 

    Best answer by retention

    @manju - I’m obviously not sure about your specific use case.  But perhaps you can get the webhook, then lookup the associated metric event (given profile_ID and metric_ID) for the proper timestamp?  That way you are using the Klaviyo timestamp and not the runtime webhook time and so they should be in the order that Klaviyo knows about those metric events.

     

    4 replies

    manjuAuthor
    Contributor I
    February 17, 2025

    is there any way of getiing the webhook_id for the Webhook.

    MANSIR2094
    Expert Problem Solver IV
    Expert Problem Solver IV
    February 17, 2025

    Hello ​@manju , thank you for reaching out...…

    Webhook events are asynchronous by nature, so their order isn’t guaranteed. To ensure correct sequencing, implement an event queue with timestamps or unique event IDs. Store events temporarily and process them in the correct order before updating your backend. If your system supports it, use Klaviyo's event_id or timestamp to manage event processing.

     

    For retrieving webhook_id, check Klaviyo’s webhook payload or API documentation for available metadata. If implementation is complex, feel free to reach out for tailored guidance

    .

     

    Mansir Digital Portfolio
    retention
    Partner - Platinum
    retentionAnswer
    2025 Champion
    February 17, 2025

    @manju - I’m obviously not sure about your specific use case.  But perhaps you can get the webhook, then lookup the associated metric event (given profile_ID and metric_ID) for the proper timestamp?  That way you are using the Klaviyo timestamp and not the runtime webhook time and so they should be in the order that Klaviyo knows about those metric events.

     

    Joseph Hsieh // retentioncommerce.com // X: @retention
    hani
    Problem Solver II
    2025 Champion
    February 17, 2025

    Webhook events are asynchronous, so you cannot guarantee they will come in the order received.

    I would either recommend:

    1. Implementing a system where you hold all the events and then pre-process them to ensure consistency or;
    2. At each event, you can query Klaviyo for the events to get the timestamp, to know wether or not to process the event. 
    Hani Rifai | Head of Engineering & Martech | Step One