I have compiled a little bit approaches:
Approach 1
Client Side:
/services
updateUserRewardWithSomeComplexOperation(){
// fetch all data via Supabase SDK
// call api to get the response with updated data based on business logic computation
// update the data via Supabase SDK
}
Server Side
APIs can be written in Next.js Server of a particular app
APIs can be written in a separate Express Server (shared with all the apps)
Approach 2
Use Postgres Functions to compute business logic directly in the DB
Refer:
https://supabase.com/docs/guides/database/functions
https://supabase.com/docs/reference/javascript/rpc
Need to write functions directly in Postgres inside the SQL section of Supabase Dashboard
Support for Function Hooks (call a function automatically when a particular row/col changes)
Need to write logic in SQL and not JS
Can execute directly on client side via JS SDK
Please let me know your views upon this.