r/GoogleAppsScript • u/Plus-Quarter-1459 • May 09 '26
Question How are you handling the Apps Script 6-minute execution limit for bulk Work
Hey everyone,
I wanted to open a discussion on handling one of the most notorious bottlenecks in Apps Script development: the 6-minute execution wall (and the dreaded “Resource Exhausted” errors).
The Context:
My team recently built and launched a sheet-based Workspace management add-on called AdminSheet Pro. Our biggest technical hurdle wasn’t the Directory API logic itself, but dealing with massive enterprise and Higher-Ed domains. When you are trying to bulk update 10,000+ users or migrate massive nested groups, hitting that 6-minute wall is almost guaranteed.
We noticed that a lot of other sheet-based tools in the ecosystem just slap a warning label on their UI saying something like: “Organizations with 10k+ users may experience timeouts due to Apps Script runtime limits.” We felt that defeated the purpose of building a “bulk” tool, so we decided to try and engineer a native workaround.
Our Approach: “Intelligent Pacing”
Instead of trying to brute-force the API or migrating the entire execution engine off Apps Script to GCP, we engineered a state-management architecture we call Intelligent Pacing.
Essentially:
- We track row-level execution state continuously.
- We anticipate the execution wall around the 5.5-minute mark.
- We gracefully pause the script, save the state, and use triggers to spin up the next batch seamlessly in the background.
We made a conscious design choice to prioritise guaranteed completion over raw speed. It might take a little longer to run safely, but it doesn’t crash halfway through. We also had to build real-time, row-by-row visual feedback in the Sheet to prevent “terminal anxiety”—so admins wouldn’t panic and kill the script while it was processing in the background.
My Questions for the Community:
Since we are always looking to optimise, I’m curious how other devs here are tackling this:
- Architecture: Are you using a similar trigger-based batching system to stay within Apps Script, or have you offloaded the heavy lifting entirely to Cloud Run/Cloud Functions?
- UX: How do you handle user UX when background tasks take 15+ minutes? How do you keep the user informed without exceeding quota limits on UI updates?
- Batching: Have you found a “sweet spot” for API batching sizes to maximise throughput before you hit that 6-minute mark?
Would love to hear your thoughts and strategies!
8
u/mylifestylepr May 09 '26
Don't have any suggestions, just intrigued in this achievement. I'm myself learning how to maximize Google apps script, still learning.
7
u/WillingnessOwn6446 May 09 '26
Yeah I did something like this. Make sure you're using the sheets API cuz it's going to copy way faster that way. Then you do it in batches of $5,000 or 10,000 rows of data. Cut it off well before the execution limit and use a trigger to fire it again.
Sucks though. Sometimes gas isn't the right tool for the job but I try to force it anyway
3
u/Expert_Dingo3194 May 09 '26
Have also done this. Saved where the cursor is. Also for sensitive data where there are big read writes I've used a staging sheet to help manage the process between runs.
I have one tool that scans back your email history and can run time heavy. So theres a modal that shows the process of the scan over all the data and it slowly completes over a few days of timed triggers. There's some ux tutorials on it as well and a help center doc to walk through it. Then it moves to maintenance mode once the major onboarding scans are complete.
Also one thing I've noticed is the loops within loops that are easily to introduce - really try to squash the complexity scaling because that will chomp your processing significantly as well
2
u/dimudesigns May 09 '26
At that scale (bulk updating 10k+ users), I'd definitely offload that work to Cloud Run/Cloud Run Functions.
1
u/microbitewebsites May 10 '26
There is another issue, on top of the the 6 minute cut off there are daily limits too https://developers.google.com/apps-script/guides/services/quotas If you can't do everything in 6 minutes set a future schedule that will continue to run. Alternatively look at making the script more efficient if possible
Different limits for different accounts too
1
u/marcnotmark925 May 10 '26
I would think of a completely different way to solve whatever the problem is.
1
u/cdemmings May 10 '26
The execution time for GAS is so inconsistent, I thought that sheets was free for home users and nobody in their right might would ever build a serious enterprise application with it. Most of my script use is in custom functions with only a 30 second timeout - which is extremely painful when their servers decide that "Loading...." is all I will ever see. Good luck with your project.
1
u/Richard_Musk May 10 '26
State management is the best way to do this. I mimic a week with heartbeats and pollers and I do everything in the background. Cache data as often as possible and utilize the sidebar.
1
u/broduding May 10 '26
I moved heavy stuff to GitHub actions.
1
u/everythingabili May 10 '26
Yep all of that is what I did/do ... and I'm on an a longer runtime. Very wise to go for slow and correct, rather than, "Oh that nearly finished, now what?"
I sometimes run a script for 3 or 4 days. A person below also makes a good point about other quotas being reached. It's quotas all the way down.
Here's my solution (sorry just copied and pasted into one file - hope it's all there) https://ctxt.io/2/AAD4PznKEw
The way I handle the UI is to tell the user they will get an email when the task is finished - which provides a mini report ... 14,345 rows processed, 3 errors, took 1.7 days etc... and a link back to the sheet.
I don't think a user necessarily needs to know "where they're up to"... and it more important that the user knows when and that it's DONE (correctly).
1
u/ThePatagonican May 10 '26
I faced this issue for our addon. But addon does opens the sidebar with html and js( that runs in the browser), so what we do is orchestrate from the js side the requests to gas. And we do only use gas for interacting with google apis, other stuff is done from js, even calling external apis (you could avoid the 1 min timeout from urlfetch)
Let me know if you would like me to explain deeper
1
u/Univium May 12 '26
I think if you have like the business/professional Google workspace you can go up to like 30 minutes.
Also, for scripts that must run an excessively long amount of time, I have like a script property that I can set to a value so that the next time the script runs it picks up where it left off
4
u/[deleted] May 10 '26
[removed] — view removed comment