Next.js Discord

Discord Forum

Complex Database Function and Purchase Management - What's the best approach?

Unanswered
MatheusDeveloper posted this in #help-forum
Open in Discord
Avatar
Hey folks, looking for advice on my project architecture!
Scenario
I have a complex database function in Supabase (code will be shared in comments) that:

Manages user subscriptions
Calculates access dates
Updates multiple related tables
Maintains audit logs

Main Doubt
Should I keep this complex logic in Supabase (database function) or move it to Next.js (serverless)?
What concerns me:

Receiving peaks of 1000 simultaneous purchases (payment platforms)
Can't lose any transactions
Need to maintain data consistency
Infrastructure costs

Note: I'll share the function code in a separate file for better readability.
Image

0 Replies