Ann Baum
This is great, thank you Rodrigo Mansueli! You could definitely use this for whitelisting IPs on Supabase as well!
I'm curious- you say it isn't a great idea to rate limit GET requests using this strategy - but then what's to stop someone ddos-ing you (making many repeated requests to the db) simply by selected data frequently?
This is great – we just implemented rate limiting pretty much exactly as described here.
Only small gotcha was the check_rate_limit() function – we forgot that we use HEAD requests to validate username availability during signup, important to exclude those in addition to GET!
One additional gotcha here that we just ran into – an unexpected side effect of:
CREATE UNLOGGED TABLE request_log ( id BIGINT GENERATED BY DEFAULT AS IDENTITY, ip inet NOT NULL, timestamp timestamptz DEFAULT NOW() );
was that while the request_log table was unlogged, the sequence created by id (request_log_id_seq) was logged. this led to us running into a bug when we attempted to update our Postgres: postgrespro.com/list/thread-id/2707900
we were able to resolve (courtesy of Supabase infra team identifying the issue + Claude identifying the fix!) by altering the table to use an unlogged sequence instead.