Sanity import transaction size limits?
Based on the documentation I've reviewed, here's what you need to know about transaction size limits for @sanity/import:
Transaction Size Limits for @sanity/import
While the @sanity/import package doesn't have explicitly documented transaction size limits in its own documentation, there are important API-level limits you need to be aware of:
Key Limits:
Maximum mutation request body size: 4 MB - This is the critical limit for transactions. When importing data, the
@sanity/importtool batches mutations into transactions, and each transaction request cannot exceed 4 MB.Maximum request body size: 100 MB - This applies to the overall HTTP request, but mutation requests specifically are limited to 4 MB.
Maximum mutation rate: 25 requests/second - Rate limiting per IP address.
Maximum concurrent mutations: 100 - Per dataset concurrency limit.
How @sanity/import Handles This:
According to the importing data documentation, when using client libraries (which @sanity/import uses under the hood):
- Multiple mutations per transaction: It's recommended to batch multiple mutations within a single transaction, but you must ensure the request size stays within the 4 MB limit.
- Automatic batching: The CLI import tool has built-in abstractions that automatically batch mutations into transactions to avoid rate limits.
- Visibility mode: Using
deferredvisibility (instead ofsync) makes imports faster, as it doesn't wait for documents to be searchable before returning.
Best Practices:
- Keep individual transaction payloads well under 4 MB
- Use the official CLI tool (
sanity dataset import) which handles batching automatically - If writing custom import scripts, implement proper batching and concurrency control (the docs recommend using libraries like
p-queuewith a concurrency of 1 request per 40ms, or 25 req/s) - Monitor your request sizes, especially when importing documents with large content or many references
The 4 MB mutation request limit is the main constraint you'll encounter with @sanity/import transactions. The tool handles this automatically by batching your imports appropriately, but if you're building custom import logic, you'll need to manage this yourself.
Show original thread2 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.