Let's say we want to send an email to user after successful registration into users table.
Is it possible to configure throttling configuration so that we could limit number of triggers per secs/mins ?
We support a retry after header so that you can implement your own backoff
algorithm.
@tirumarai can you help?
On Fri, 28 Dec 2018 at 12:23 AM, Truong Hoang Dung notifications@github.com
wrote:
Let's say we want to send an email to user after successful registration
into users table.
Is it possible to configure throttling configuration so that we could
limit number of triggers per secs/mins ?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/hasura/graphql-engine/issues/1268, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAIAWPN45dLYTvHTLSBmlgdvTcvt97mOks5u9RckgaJpZM4ZjFne
.
@coco98 The use case is in case we want to send bulk email to many users at once.
In this case, could Hasura send event triggers in bulks, too ?
For example, Gmail has a limit about some dozens of email could be sent per seconds/minutes/hours,...
It could be useful if we could control this from event triggers, too.
@revskill10 Like @coco98 mentioned, you can achieve this via 'Retry-After' header in your webhook. Hasura will reschedule your event incase it finds a 'Retry-After' header in your webhook response. Achieving a bulk threshold will involve having a table in your db though.
Suppose you want to process 100 requests/minute, then you can have a table say 'throttle' with columns 'begin_timestamp' and 'count'. In your email trigger function:
1) make a query to 'throttle' and check if there is a 'begin_timestamp' which is less than 60 seconds than current_time.
2) If there is such a timestamp, then check 'count'. If there is no such timestamp, then create an entry with begin_timestamp = current_time and count = 0
3) If count is less than 100, then process the request and increment the count. If count is more than 100 then return with HTTP status code 429 and Retry-After header of 60 seconds.
If you do the above steps in a transaction then this will guarantee that you achieve between 100req/min and 50req/min (considering tolerable clock-skew). If you don't do this in a transaction then it will still be fine unless you have very high volume of concurrent requests.
Let me know if this is clear.
^ Updated the math a bit.
I'm closing this issue. If something is not clear or if you have additional questions, please feel free to re-open it 🙂
Most helpful comment
@revskill10 Like @coco98 mentioned, you can achieve this via 'Retry-After' header in your webhook. Hasura will reschedule your event incase it finds a 'Retry-After' header in your webhook response. Achieving a bulk threshold will involve having a table in your db though.
Suppose you want to process 100 requests/minute, then you can have a table say 'throttle' with columns 'begin_timestamp' and 'count'. In your email trigger function:
1) make a query to 'throttle' and check if there is a 'begin_timestamp' which is less than 60 seconds than current_time.
2) If there is such a timestamp, then check 'count'. If there is no such timestamp, then create an entry with begin_timestamp = current_time and count = 0
3) If count is less than 100, then process the request and increment the count. If count is more than 100 then return with HTTP status code 429 and Retry-After header of 60 seconds.
If you do the above steps in a transaction then this will guarantee that you achieve between 100req/min and 50req/min (considering tolerable clock-skew). If you don't do this in a transaction then it will still be fine unless you have very high volume of concurrent requests.
Let me know if this is clear.