understanding service_role key

I am unsure weather i should use service_role key or not, my use case is that there is a table public.user_balance which stores the user balance and the corresponding id to that user.

and another table public.balance_cards which stores a value and a uuid.

the functionality i want to achieve is, an authenticated user sends a uuid if the uuid matches an available uuid from balance_cards the value in that row should be added to the users's balance in public.user_balance and deleted as well, so the user cant use the same row to recharge their account many times.


Someone suggested me to use service_role for this use case and said its more secure.

I want to know what is your approaches and if i can use the database to achieve this securely without needing service_role.
Was this page helpful?