By Raj
Part of our Google Apps Script Consulting guides. Need this built for your team? Hire a Google Apps Script developer.
Estimated reading time: 10 minutes
Google Apps Script Best Practices: 12 Rules for Production Scripts
Production Apps Script is maintained code: triggers fire when you are not watching, and failures surface as silent stale tabs unless you design observability from day one.
The twelve rules below come from client audits—LockService for concurrency, Script Properties for secrets, batch I/O, and never storing API keys in Sheet cells visible to all editors.
Pair this guide with /blog/google-apps-script-debugging-guide for transcripts and with /blog/google-apps-script-quotas-and-limits when scaling volume.
Project structure and naming
Split config (sheet IDs, column maps) into a Config sheet or JSON in Script Properties. Name functions after business actions—syncStripePayouts—not after technologies.
Keep a single entry point per trigger type (onEditHandler calls processRow). Avoid top-level side effects that run on every save in the editor.
Batch reads and writes
Never call getValue/setValue inside loops over thousands of rows. Read once with getValues(), transform in memory, write once with setValues().
For formatted output, apply number formats to entire columns after the data write, not cell by cell.
Concurrency with LockService
Overlapping time-driven triggers can interleave writes and duplicate rows. Use LockService.getScriptLock().tryLock(30000) around critical sections.
If tryLock fails, exit early and let the next run pick up work—better than corrupting a ledger tab.
Secrets and authorization
Store tokens in Script Properties via PropertiesService.getScriptProperties().setProperty. Document re-auth steps when adding OAuth scopes.
Version control with clasp is excellent, but never commit .clasprc.json or live API keys. See /blog/apps-script-clasp-guide for Git hygiene.
Example code
function withScriptLock(fn) {
const lock = LockService.getScriptLock();
if (!lock.tryLock(30000)) {
Logger.log('Skipped run — lock held');
return;
}
try {
fn();
} finally {
lock.releaseLock();
}
}| Approach | Best for | Tradeoff |
|---|---|---|
| Apps Script native | Google Workspace-centric workflows | 6-min limit, quotas |
| Zapier / Make | No-code, many connectors | Per-task cost, vendor lock-in |
| Python + Cloud | Heavy data / ML | Hosting cost, separate auth |
| Google Apps Script consulting | Production custom logic | Build cost, you own code |
FAQ
Should I use V8 runtime for new projects?
Yes. Enable the V8 runtime in Project Settings for modern JavaScript features and clearer stack traces. Test thoroughly because some legacy Rhino quirks differ.
Where should configuration live?
Use a hidden Config sheet for non-secret toggles editors might change, and Script Properties for API keys. Never hard-code spreadsheet IDs without a single CONFIG object.
How do I prevent duplicate trigger installs?
On install, list ScriptApp.getProjectTriggers(), delete matching handlers, then create one fresh trigger. Document the install function in your handoff README.
Is Logger.log enough for production?
Logger.log helps during development, but production systems should also append errors to a Log sheet or email an admin digest. See /blog/google-apps-script-debugging-guide.
When should I extract logic to a library?
When three or more projects share identical API clients or validation helpers, publish an Apps Script library. Keep business rules in the container-bound project for easier client handoff.
Need this done for you? I handle this as part of my consulting work — fixed-price quote within 24 hours.
Book a call with Raj →Get the full Google Apps Script Best Practices script template
I'll email you a production-ready, commented version you can deploy in 10 minutes.
Continue reading
Apps Script Core
How to Automate Google Sheets with Apps Script (Beginner Guide)
Apps Script Core
Master Google Apps Script: A Step-by-Step Roadmap for Non-Coders
Apps Script Core
Google Apps Script Trigger Not Working? Here's the Fix
From another topic
Google Sheets CRM Automation: Triggers, Pipelines, and Follow-Ups →Need help with this? I handle this as part of my Google Apps Script Consulting service.
Workflow automation, script audits, triggers, quotas, and production best practices.
See how it works →