vercel / nextjs-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with Next.js.
https://subscription-payments.vercel.app/
MIT License
6.39k stars 1.3k forks source link

Discussion: Using NextJs routes over Supabase edge functions for Stripe webhooks. #256

Closed Innders closed 11 months ago

Innders commented 11 months ago

Discussion

Both NextJs and Supabase have serverless functions that allow you to catch Stripe webhooks and sync Supabase with your products, prices and subscriptions.

But why specifically does this template use NextJs routes? It may purely be because this is a NextJs repo and it's good to see examples built using the technology and nothing deeper than that.

However I have put together a pros and cons list for using Supabase instead and would love to know everyones thoughts.

PROS and CONS for moving Stripe webhook functions to Supabase.

  1. PRO Reduced complexity: It's 2 steps (Stripe ➝ Supabase) vs 3 steps (Stripe ➝ Vercel ➝ Supabase)
  2. PRO Faster and more reliable: Supabase provides direct access to the database, eliminating an extra step in the chain compared to Vercel.
  3. PRO More secure: By reducing the number of providers from two to one, Supabase minimizes the attack surface area, making it a more secure option.
  4. CON more expensive: While Vercel offers unlimited serverless functions, it is unlikely that the Supabase limits will ever be exceeded, making the cost difference less significant.
  5. PRO Better documentation and guides: Supabase provides comprehensive documentation and guides, particularly regarding integration with Stripe, offering a more user-friendly experience for developers.
  6. CON more work: Everything is already setup and working out of the box and rewriting everything again may be a complete waste of time.

These are the main points I can think of based off my research, but please correct me if I'm wrong and add to it!

Thanks

ajayvignesh01 commented 11 months ago

For your points 1 through 3, supabase edge functions don’t have direct access to the database, you have to connect to them using supabase js. They are essentially Deno edge functions. So, it doesn’t matter vercel or supabase functions.

For your point 4, vercel doesn’t have unlimited serverless functions. It might actually be cheaper to run Supabase edge functions for this purpose.

For point 5, check out Supabase wrappers.

Innders commented 11 months ago

Okay so all my points were misconceptions... That was exactly the clarification and correction I was looking for, so thanks! 🙏