Database / Supabase Intermediate to Advanced Interview Questions
How does pg_net let Postgres make asynchronous HTTP calls without blocking a transaction?
Calling an external HTTP endpoint synchronously from inside a Postgres transaction is risky: the transaction has to hold its locks and wait for a network round trip that might be slow or fail, tying up a database connection and potentially blocking other queries on the same rows for the duration.
pg_net avoids this by queuing the HTTP request in an internal table and returning immediately, letting a background worker process actually perform the request outside of the calling transaction. A call like select net.http_post(url := 'https://example.com/webhook', body := jsonb_build_object('event', 'new_order')); returns a request ID right away; the transaction that issued it can commit without waiting on the network at all, and the result of the HTTP call can be checked later from the net._http_response table if needed.
This makes pg_net a natural fit for firing webhooks from a trigger — a new row insert can kick off an external notification without the insert itself being slowed down or rolled back by an unrelated third-party service being slow or down.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
