I’m primarily a frontend developer and on the frontend side, I’m well familiar with the logic of debouncing. For example debouncing user input and calling a function only after user stopped typing.
Now I’m in a little bit different situation and I need something like this but on the backend and the “input” are incoming requests.
I don’t have any control over the “client” here as it’s external 3rd party service calling my webhook. The service is firing too many requests.
It fires a POST request every time a deal entity changed. Sometimes it fires 5 – 6 requests in close succession. In that case I want to process only the last one.
Here’s the frontend logic I would do on client side:
const timers = {};
const handleInput = (deal) => {
clearTimeout(timers[deal.id]);
timers[deal.id] = setTimeout(() => {
// actual logic here, set deal into database or whatever
}, 1000);
};
This would solve the problem. The edge case scenario that the input would keep firing requests consecutively and the logic would never trigger because it would always cancel and reschedule is not really realistic here.
How should I go about this on the backend? Which service is friendly for logic like this? CloudFlare workers? Netlify Functions?
I need some very easy to use storage that can be managed in between requests I assume.
Thanks!