Why this exists
NetSuite gives every script call a fixed budget of governance units and a time limit. If a call runs out of either, NetSuite stops it and the caller gets no response. Any records the script already marked as sent are lost with it.
Integrations are often built with batch sizes picked by hand and a polling schedule that the other system chose on its own. No one works out what a call can afford or how often the caller has to call to keep up with the volume. The usual result is a call whose cost grows with the backlog and uses more than half its time limit, inbound calls with no size limit, and polling around the clock that mostly returns nothing while the same records are re-sent on every call.
This standard makes both numbers, batch size and call frequency, a required, calculated part of every integration design.
Batch size comes from the unit and time budgets. Call frequency comes from volume and batch size. Both are written into the RFD before any code is written, and both are measured in UAT.
The limits
Per call or per invocation. These are the values in NetSuite Help at the time of writing. Confirm them against the current Help topics "SuiteScript Governance and Limits" and "Script Execution Time Limits" before a design is signed off.
| Script type | Units per call | Time limit | Notes |
|---|---|---|---|
| RESTlet | 5,000 | 5 minutes | The usual entry point for an external system. The caller waits for the whole call. |
| Suitelet | 1,000 | 5 minutes | Rarely right for system-to-system traffic. |
| User event | 1,000 | 5 minutes | Runs inside the user's save. Never do integration calls here. |
| Scheduled | 10,000 | 60 minutes | One queue slot per run. |
| Map/reduce | getInputData 10,000 · map 1,000 · reduce 5,000 · summarize 10,000 | 60 · 5 · 15 · 60 minutes | Limits apply per invocation and the framework yields for you. The right tool for large volumes. |
| Other limit | Value | Why it matters |
|---|---|---|
| Rows per search page | 1,000 (getRange or one page) | A batch can never be bigger than one page unless the script pages through results. |
| RESTlet payload | 10 MB request or response | Bounds batch size for wide records with long text. |
| Concurrent web service calls | Account limit, shared by RESTlets, SOAP and REST web services | Read it at Setup › Integration › Integration Management › Integration Governance. Calls over the limit are rejected. |
Unit costs
SuiteScript 2.x costs for the calls integrations use most. Treat them as planning estimates. The only reliable number is the one you measure (chapter 4, step 3, or chapter 5).
| Call | Transaction | Custom record | Other records (customer, contact, employee, item) |
|---|---|---|---|
| record.load / create / copy / transform | 10 | 2 | 5 |
| Record.save | 20 | 4 | 10 |
| record.submitFields | 10 | 2 | 5 |
| record.delete | 20 | 4 | 10 |
| Call | Units | Note |
|---|---|---|
| search.lookupFields | 1 | Cheapest way to read a few fields from one record. |
| search.load | 5 | |
| Search.runPaged / PagedData.fetch | 5 | Per call, not per row. |
| ResultSet.getRange / each | 10 | Per call, not per row. A search run inside a loop is the most common hidden cost. |
| query.runSuiteQL | 10 | Per call. |
| https.request | 10 | Plus the remote system's response time against the time limit. |
| email.send | 20 | |
| file.load / File.save | 10 / 20 | |
| task.submit | 20 | Hand-off to a scheduled or map/reduce script. |
| log.*, format.*, runtime.getRemainingUsage | 0 | Logging is free, so log the usage every time. |
- A search inside a loop. 10 units per pass, so cost grows with the number of records, or worse, with the size of the backlog.
- User events on the records you write.
submitFieldsandsavefire the target record's user events in the same call, and their usage and time count against it. - Load and save when you only need to set fields.
load + saveon a transaction costs 30;submitFieldscosts 10.
Sizing method
Pick the script type
It sets the unit budget and time limit (chapter 2). An external system calling in means a RESTlet. If a single run needs more than one RESTlet call can afford, accept the request in the RESTlet and hand the work to a map/reduce script with
task.submit.Write down the cost model
Split the call into a fixed part that runs once (searches, lookups, loading config) and a part that runs once per record. List each SuiteScript call with its cost from chapter 3.
units(call) = fixed + per_record × recordsMeasure it
If the script, or one like it, already runs in production, read the cost from its execution log (chapter 5). The log has real records, real volumes and the real calling pattern. For a new script, log
runtime.getCurrentScript().getRemainingUsage()at the end of the call and run it in sandbox once with 10 records and once with 50, using the largest realistic records. Time both runs too.per_record = (used_50 − used_10) / 40 fixed = used_10 − 10 × per_recordSet the batch size
Take the smallest of four ceilings. Keep a reserve of 10% of the unit budget (500 for a RESTlet) and use only half the time limit, because record size varies and the target record's user events add cost.
B_units = floor((budget − fixed − reserve) / per_record) B_time = floor((time_limit × 0.5 − fixed_seconds) / seconds_per_record) B_rows = 1,000 per search page (more only if the script pages) B_payload = floor(5 MB / bytes_per_record) batch = min(B_units, B_time, B_rows, B_payload)Set the call frequency
Size for the busiest hour, not the daily average. The interval has to clear peak volume and still meet the freshness the business needs.
calls_per_peak_hour = ceil(peak_hour_volume / batch) max_interval = min(60 min / calls_per_peak_hour, latency_target) calls_per_day ≈ 24 h / intervalCheck the backlog
After an outage, a bulk load or a mass update, the queue fills. Work out how long it takes to clear at the chosen batch and interval. If records arrive faster than one batch per interval, the backlog never clears.
drain_capacity_per_call = batch − arrivals_per_interval drain_time = ceil(backlog / drain_capacity_per_call) × intervalCheck concurrency
Calls in flight at once must stay under the account limit, together with every other integration. A queue that marks records as sent is only safe with one caller at a time. Say so in the contract.
Write it into the RFD and enforce it in code
Record every number in the RFD's capacity section (chapter 8). The script checks remaining units as it goes (chapter 7), and inbound messages carry a maximum batch size that NetSuite enforces.
Production history
A script that already runs in production has measured itself. If it logs what it handled and how many units it had left, a SuiteQL query against the execution log (scriptnote) gives the cost model, the call interval and the real batch sizes without a sandbox run.
What the script must log
One AUDIT line per call, written last. Scripts built to this standard already do this (chapter 7).
log.audit('usage', JSON.stringify({ records: records.length, unitsUsed: 5000 - script.getRemainingUsage(), ms: Date.now() - started }));
Query: scripts that log the summary line
SELECT TO_CHAR(date, 'YYYY-MM-DD HH24:MI:SS') AS ended, detail
FROM scriptnote
WHERE scripttype = 12345 -- the script's internal ID
AND title = 'usage'
ORDER BY date
Query: older scripts with a per-record line and a remaining-units line
Pair each remaining-units entry with the per-record lines written in the 90 seconds before it. Group by time, not by log row ID, because row IDs are not in strict time order.
SELECT TO_CHAR(r.date, 'HH24:MI:SS') AS ended,
TO_NUMBER(r.detail) AS remaining,
(SELECT COUNT(*) FROM scriptnote h
WHERE h.scripttype = r.scripttype
AND h.title LIKE 'Record sent%' -- the per-record line
AND h.date BETWEEN r.date - (90/86400) AND r.date) AS records
FROM scriptnote r
WHERE r.scripttype = 12345
AND r.title LIKE 'Remaining governance%'
ORDER BY r.date
Query: real demand, not log lines
SELECT COUNT(*) AS sends, COUNT(DISTINCT SUBSTR(title, 13)) AS distinct_records
FROM scriptnote
WHERE scripttype = 12345 AND title LIKE 'Record sent%'
Reading the result
- Fixed cost = units used by a call that handled 0 records.
- Per-record cost = (units used − fixed) ÷ records, from a full call. Check it holds across several call sizes.
- Seconds per record = (call duration − empty-call duration) ÷ records.
- Interval = the gap between call start times. Volume = distinct record IDs per hour, so re-sends do not count as demand.
- History is short. NetSuite purges execution logs. Scripts that log every step at DEBUG level fill the space and can leave only a few hours of history. Keep production deployments at AUDIT and log one summary line per call so history lasts.
- A script that never logs remaining units gives time and record counts only.
- Overlapping calls blur the time windows. Check start times before trusting a window.
- The MCP SuiteQL connection reads production, so these queries run against real history.
Calculator
Two steps. First describe what the script does for each record, including every lookup on a related record, and the calculator adds up the units and seconds from the chapter 3 costs. Then it sizes the batch and call interval from your volumes. The unit costs are NetSuite's; the seconds are planning estimates you can overtype. Replace any of the results with measured values when you have them.
Step 1 · Build the cost per record
| Step | Runs | Units | Seconds | Share of per-record units |
|---|
The totals below fill the three cost fields in step 2. Overtype them with measured values from the production log or a sandbox run when you have them (chapter 5).
Step 2 · Size the batch and interval
Build patterns
Outbound pull: stop on budget, not on a fixed count
The batch size from chapter 4 is a maximum. The script also checks its remaining units and time before each record, and tells the caller when more is waiting.
/** @NApiVersion 2.1 @NScriptType Restlet */
define(['N/runtime', 'N/search'], (runtime, search) => {
const MAX_BATCH = 200; // from the RFD capacity table
const RESERVE = 500; // 10% of 5,000
const PER_RECORD = 20; // measured in sandbox
const TIME_BUDGET_MS = 150000; // half of the 5-minute limit
const get = () => {
const script = runtime.getCurrentScript();
const started = Date.now();
const records = [];
const paged = search.load({ id: 'customsearch_outbound_queue' }).runPaged({ pageSize: 1000 });
let stopped = false;
for (const range of paged.pageRanges) {
for (const result of paged.fetch({ index: range.index }).data) {
const outOfUnits = script.getRemainingUsage() < RESERVE + PER_RECORD;
const outOfTime = Date.now() - started > TIME_BUDGET_MS;
if (records.length >= MAX_BATCH || outOfUnits || outOfTime) { stopped = true; break; }
records.push(buildRecord(result));
}
if (stopped) break;
}
log.audit('usage', { sent: records.length, remaining: script.getRemainingUsage(), ms: Date.now() - started });
return { TotalResults: paged.count, CurrentResults: records.length, HasMore: paged.count > records.length, Records: records };
};
return { get };
});
Inbound push: publish a maximum and enforce it
const MAX_INBOUND = 50; // from the RFD capacity table; the contract states it
const post = (body) => {
if (body.Records.length > MAX_INBOUND) {
return { Status: 'Rejected', MaxBatch: MAX_INBOUND, Received: body.Records.length };
}
// ...process, checking getRemainingUsage() as above
};
- Run every search once per call and look results up in memory.
- Prefer
submitFieldsandlookupFieldsover load and save. - Count records, not search rows. A record with lines is one record.
- Return
HasMoreso the caller can call again at once while a backlog exists. - Log units used and elapsed time on every call, success or failure, in one AUDIT line.
- Keep production deployments at AUDIT so the log keeps more than a few hours.
- Move volumes that a RESTlet cannot carry to map/reduce.
- Pick a batch size without the cost model behind it.
- Put a search,
lookupFieldsorloadinside a loop over the queue. - Let the cost of one call grow with the size of the backlog.
- Accept an inbound batch of any size.
- Let the other system choose the polling interval without the volume numbers.
- Mark a record as sent before the other system confirms it received it.
What every RFD states
Add a Capacity and frequency section to the RFD (in Processing rules, or as its own chapter) with one row per message and these columns:
| Msg | Script type · budget | Fixed units | Units per record | Seconds per record | Batch size and binding ceiling | Peak records / hour | Interval | Backlog drain time |
|---|---|---|---|---|---|---|---|---|
| 1b | RESTlet · 5,000 | 15 | 20 | 0.2 | 224 · units | 120 | 15 min | 1,000 in 1 h 30 m |
The example row is illustrative.
Sign-off checklist
- Every message has a script type, budget, cost model and batch size.
- Costs were measured from production history, or from a sandbox run with the largest realistic records. Not only estimated.
- The batch size is the smallest of the unit, time, page and payload ceilings, with the reserve kept.
- The interval clears peak-hour volume and meets the freshness target.
- Backlog drain time is stated for a realistic worst case (a day's outage or a bulk load).
- No call's cost grows with the size of the backlog.
- Inbound messages state a maximum batch size, and NetSuite enforces it.
- Concurrent calls stay under the account limit together with other integrations, and the caller knows whether parallel calls are allowed.
- Every call logs units used and elapsed time.
- The interval is agreed with the other system's team and written into the contract.
Worked example
An outbound pull of changed customer records (RESTlet), sized from its production log. The figures are illustrative.
| Step | Value | Source |
|---|---|---|
| Budget, reserve, time budget | 5,000 units, 500, 150 s | RESTlet limits, 10% reserve, half the time limit |
| Fixed cost | 10 units, ≈ 5 s | Empty calls left 4,990 and took ≈ 5 s |
| Per record | 5 units, ≈ 0.55 s | A call with 150 records left 4,240 and took ≈ 85 s; a call with 79 left 4,595 and took ≈ 45 s |
| Unit ceiling | 898 | (5,000 − 10 − 500) ÷ 5 |
| Time ceiling | ≈ 260 | (150 − 5) ÷ 0.55 |
| Batch size | ≈ 260 | Time binds, not units. The code in production uses 150. |
| Interval | 10 min | Gap between call start times in the log |
| Capacity at 150 every 10 min | 21,600 a day | 150 × 144 calls |
| Real demand | ≈ 1,000 customers in 9 h | About 3,900 sends but only 1,000 distinct customers |
Capacity is not the problem here; waste is. A group of about 80 customers was sent on most calls, roughly 2,700 of the 3,900 sends. Only the integration writes their sync date, yet their last-modified time keeps moving without a system note, so they look changed on every call. Counting distinct records instead of log lines exposed it. Without the production history it would have read as high demand.