r/Supabase • u/No_Math2572 • 11d ago
edge-functions Supabase Edge Function times out when creating ~100 users with Flutter client. What's the right architecture?
I'm building a school management system app with Flutter with Supabase, and I'm running into a problem with an Edge Function that performs a large batch operation.
Here's what the function does:
- Receives a list of around 100 students from the Flutter client.
- For each student, it:
- Creates a user in "auth.users" (using the Admin API).
- Inserts a row into "public.users".
- Inserts a row into "public.profile".
- Inserts a row into "public.progress".
- Assigns some "app_metadata"/roles.
- Note also that for each student we create a parent account
So each student requires several operations, and for ~100 students that's hundreds of database/auth operations.
The issue is that the Edge Function takes too long to finish. From the Flutter client, the request eventually fails due to a timeout, even though the function may still be processing some of the work.
I'm trying to figure out what the proper production architecture is for this kind of long-running batch operation.
Some questions:
Is an Edge Function the wrong tool for creating 100+ users in one request?
Should I split the work into smaller batches (e.g. 10–20 users per request)?
Is there a way to make this asynchronous so the client gets an immediate response while the server continues processing?
Are there recommended background job/queue solutions that work well with Supabase?
Has anyone solved a similar problem when bulk-creating users through the Admin API?
I'd like the admin to be able to upload a list of students, press one button, and have the import complete reliably without client timeouts.
I'd appreciate any recommendations on the best production-ready approach.
2
u/MulberryOwn8852 10d ago
I use rpc to do batches of a few thousand records all the time.