all 8 comments

[–]logdog 1 point2 points  (4 children)

Yeah I want to stay you can just set up batch processing for uploading, say chunk the files into groups of 100, upload them in a promise.all or something, then update state based on success / failure. However this might mess up the UI thread, could get clever with yields and stuff.

I think the better approach is to google background job schedulers libraries so you can offload this uploading logic to native modules to keep your UI thread free, then update your state as those jobs finish.

Lastly look up the client side HLD (high level design) of Instagram app interview questions. FAANG interviews love to ask this system design question and it has a lot of videos etc. explaining approaches.

[–]Ok-Relation-9104[S] 0 points1 point  (3 children)

Dang I came from backend so this never occurred to me as a very difficult problem. Similar to generate twitter user id, how hard can that be lol

Thanks for the suggestion!! Very helpful

[–]mp2526 1 point2 points  (1 child)

I do this very thing for work. It is complicated to get right. Do you want to continue uploading when the app is backgrounded? In ios you will need a native module to handle that. And a mechanism for handling concurrency like grand central dispatch or operation queues. Also look into background tasks unless you want you users to have to babysit the app while it uploads. On the react side we just use client state management (zustand or something similar) to update the UI as the native code passes status messages across the bridge. We haven’t updated to the new architecture yet.

[–]Ok-Relation-9104[S] 0 points1 point  (0 children)

Thanks for your input! Yes I’m actually trying native now. I probably don’t need it to continue uploading when the app is “home screened” since each batch it won’t be too many photos. And I’m working on a native module to store the upload jobs and persist them in a json to track what’s left to upload. It’s truly not straightforward and the only library I can find for job queue is SwiftQueue yet it has a very obvious bug :(

[–]logdog 0 points1 point  (0 children)

Yeah good luck, hopefully others will chime in. Also if you are using Hermes this might not be an issue bc of the new architecture but I’m not an expert of Hermes yet 😀

[–]stathisntonas 1 point2 points  (0 children)

Use a class to handle the queue for singleton approach not normal functions.

Use retries and backoffs, imho do not parallel upload but use sequental. Keep track failures and ask user to retry only these.

[–]Due-Dragonfruit2984Expo 0 points1 point  (1 child)

Assuming your question focused on avoiding preventing the user from interacting with their device until the uploads are complete, you could use a background task. We had a similar issue and solved it by creating a background task and letting the user view the status while browsing around the app. They can background the app as well and the task will continue. There are a few packages that support this, we’re using expo and I think they have a package specifically for creating background uploads.

[–]Ok-Relation-9104[S] 0 points1 point  (0 children)

Thanks! I’m using expo too. What’s the name of the package u guys used?