---
title: "Discussion on \"Rate Limiting Supabase Requests with PostgreSQL and pg_headerkit\" | Hashnode"
description: "Discussion on \"Rate Limiting Supabase Requests with PostgreSQL and pg_headerkit\". Learn how to enhance Supabase API performance with rate limiting using PostgREST and pg_headerkit. Ensure fair resource allocation."
url: "https://hashnode.com/posts/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit/64f717aafee4891c8d66ce22"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Rate Limiting Supabase Requests with PostgreSQL and pg\_headerkit](https://blog.mansueli.com/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit?utm_source=hashnode&utm_medium=feed)

Learn how to enhance Supabase API performance with rate limiting using PostgREST and pg\_headerkit. Ensure fair resource allocation.

Sep 5, 2023 · 7 min read · blog.mansueli.com  
Updated Feb 20, 2025  
Read the article

-   [#postgresql](https://hashnode.com/tag/postgresql)
-   [#ratelimit](https://hashnode.com/tag/ratelimit)
-   [#supabase](https://hashnode.com/tag/supabase)
-   [#databases](https://hashnode.com/tag/databases)
-   [#apis](https://hashnode.com/tag/apis)

## Written by

[Rodrigo Mansueli](https://hashnode.com/@mansueli)

@mansueli

  
[View profile](https://hashnode.com/@mansueli)

Supabase Tips

Support Engineer @Supabase | StackOverflow

## Responses 3

Markdown supported · ⌘↵ to post

[Ann Baum](https://hashnode.com/@anngbaum)

[Feb 20, 2025](https://hashnode.com/posts/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit/64f717aafee4891c8d66ce22/comment/67b7453cf4fec39b69d5b17b)

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](https://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.

[Kerren Ortlepp](https://hashnode.com/@kerren)

[Jan 6, 2025](https://hashnode.com/posts/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit/64f717aafee4891c8d66ce22/comment/677c3c262e631447410cdd45)

This is great, thank you [Rodrigo Mansueli](https://hashnode.com/@mansueli)! You could definitely use this for whitelisting IPs on Supabase as well!

[Matt C](https://hashnode.com/@matt405)

[Nov 27, 2024](https://hashnode.com/posts/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit/64f717aafee4891c8d66ce22/comment/674792bcc7ecd3e901153d23)

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?

[Matt C](https://hashnode.com/@matt405)

[Nov 28, 2024](https://hashnode.com/posts/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit/64f717aafee4891c8d66ce22/comment/674792bcc7ecd3e901153d23#reply-67483e1117d01afc9cbd0949)

Oh, and thank you for your excellent article! Hoping this can be used to protect my prod DB from abuse

[Rodrigo Mansueli](https://hashnode.com/@mansueli)

[Nov 28, 2024](https://hashnode.com/posts/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit/64f717aafee4891c8d66ce22/comment/674792bcc7ecd3e901153d23#reply-67484af90f39ce959d1c56c4)

Thanks [Matt C](https://hashnode.com/@matt405). Supabase (hosted) uses DDoS protection from Cloudflare on the API Gateway, so you'll have some protection for it.

You can still do it, but the extra latency for read calls might be an overkill and hurt your performance more than an acceptable limit IMHO.

[Matt C](https://hashnode.com/@matt405)

[Nov 28, 2024](https://hashnode.com/posts/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit/64f717aafee4891c8d66ce22/comment/674792bcc7ecd3e901153d23#reply-6748af6e6459b97f3326d207)

[Rodrigo Mansueli](https://hashnode.com/@mansueli) thanks I appreciate your reply. I've instead set up insert/update rate limiting as above and an IP deny list which is checked during the pre-request. I've got some simple logs to monitor request methods per IP and might try and implement some kind of alerting so I can then add those IPs to the denylist if needed. Would be nice it was possible to trigger this via the logging mechanisms automatically

[Ann Baum](https://hashnode.com/@anngbaum)

[Aug 22, 2024](https://hashnode.com/posts/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit/64f717aafee4891c8d66ce22/comment/66c743aa1b6225a7d840afed)

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!

[Rodrigo Mansueli](https://hashnode.com/@mansueli)

[Aug 22, 2024](https://hashnode.com/posts/rate-limiting-supabase-requests-with-postgresql-and-pgheaderkit/64f717aafee4891c8d66ce22/comment/66c743aa1b6225a7d840afed#reply-66c74d89ed8ebfeb1d3622bc)

Thanks for the feedback, Ann. Great to see you here!

I'll update the article to include HEAD there.
