How can I implement a concurrency-safe counter for API requests in Xano?

Answered

I'm working on a system where I create a "production" record with an expected number of images. Then, I trigger the generation of AI images for that production, which are returned to a webhook URL. At this webhook endpoint, I need to accurately count the number of images received to determine when all expected images have been processed.

However, I'm facing an issue where multiple webhook requests occur simultaneously, causing the count additions to overlap and resulting in an inaccurate total. I've considered using the database lock feature, but I understand it only works within database transactions, and I guess different webhook requests don't occur in the same transaction.

Is there a recommended approach or best practice in Xano for implementing an atomic counter or similar mechanism that can accurately track concurrent webhook requests? I'm looking for a solution that can handle high-volume, simultaneous callbacks without losing count accuracy.

Any guidance, examples, or best practices for handling this type of webhook-based counting scenario in Xano would be greatly appreciated.

Thank you!

1 reply