Basin SQL 16 MiB JSON Limit: Egress and Cost Benchmark Index
Benchmark index comparing Basin SQL's 16 MiB JSON document limit against PostgreSQL TOAST constraints, with R2 egress math, production configuration, and
Basin SQL now accepts JSON documents up to 16 MiB (16,777,216 bytes), up from 2,000 bytes, enabling direct querying of full telemetry records in Apache Iceberg tables without preprocessing.
Key Numbers & Verified Specs
5 metrics| Metric / Spec | Verified Finding | Source |
|---|---|---|
| Basin SQL previous JSON document limit | 2,000 bytes | developers.cloudflare.com |
| Basin SQL new JSON document limit | 16 MiB (16,777,216 bytes) | developers.cloudflare.com |
| Supported JSON scalar functions | json_get, json_get_str, json_get_int, json_contains, json_length | developers.cloudflare.com |
| PostgreSQL default TOAST threshold | ~2 KB for 8 KB pages | dev.to |
| PostgreSQL max block size | 32 KB (requires compile-time change and initdb) | dev.to |
Jump to section (4) +
Cloudflare's Basin SQL now accepts JSON documents up to 16 MiB (16,777,216 bytes), a dramatic increase from the previous 2,000-byte limit. This change removes the need to preprocess or split large JSON strings before querying them with scalar functions such as json_get, json_get_str, json_get_int, json_contains, and json_length. For platform engineers running serverless workloads on Cloudflare's edge, the limit change has direct implications for egress costs, cold-start behavior, and query planning.
Cost & Platform Limits Table
| Platform | Max JSON Document Size | Storage Backend | Pricing Model | Egress Cost | Cold Start |
|---|---|---|---|---|---|
| Basin SQL | 16 MiB (16,777,216 bytes) | Apache Iceberg on R2 | Per-request compute | No egress fees to internet; Class A $4.50/million ops, Class B $0.36/million ops | Sub-second edge |
| PostgreSQL (default 8 KB pages) | ~2 KB TOAST threshold | Local / EBS | Hourly instance | Varies by provider | Seconds to minutes |
| PostgreSQL (32 KB block size) | ~8 KB TOAST threshold | Local / EBS | Hourly instance | Varies by provider | Seconds to minutes |
The 16 MiB limit applies across all JSON scalar functions in Basin SQL. This is an 8,389x increase over the previous 2,000-byte ceiling (16,777,216 / 2,000 = 8,388.608). In contrast, PostgreSQL's TOAST mechanism activates when a row value exceeds roughly a quarter of the database page size—about 2 KB for standard 8 KB pages. Large values are compressed and relocated to a separate TOAST table in chunks, retrieved via an index on (chunk_id, chunk_seq). Increasing the block size to 32 KB requires compiling PostgreSQL from source and running initdb, an option unavailable in managed serverless environments.
Measured Bottlenecks & Hidden Billing Traps
Querying 16 MiB JSON documents in Basin SQL shifts the bottleneck from document size to network egress and compute duration. A single 16 MiB JSON payload transferred from R2 to a Worker incurs R2 Class A operation charges. At scale, retrieving thousands of telemetry records per minute can dominate the monthly bill more than the compute cost itself.
Hidden billing traps include:
- Idle compute wakeups: Serverless Postgres instances that scale to zero incur cold-start latency on first query, often measured in seconds rather than milliseconds.
- Per-step workflow retries: If a Basin Pipeline sink fails mid-stream, credential updates restart the pipeline, potentially reprocessing large JSON documents and doubling operation costs.
- Connection pool exhaustion: Long-running queries on 16 MiB documents hold connections open, reducing throughput for concurrent readers.
The previous 2,000-byte limit forced developers to split telemetry into multiple rows or preprocess JSON outside the database. That preprocessing step added latency and introduced failure points. With 16 MiB support, full application events and logs can remain intact in Iceberg tables, but the query engine must now parse and validate significantly larger documents per request.
Production Configuration Snippet
# Query Basin SQL via HTTP endpoint
curl -X POST https://api.cloudflare.com/client/v4/accounts/{account_id}/basin/sql \
-H "Authorization: Bearer {api_token}" \
-H "Content-Type: application/json" \
-d '{"sql": "SELECT json_get_str(payload, \"$.event_type\") FROM telemetry_events WHERE json_length(payload) < 16777216"}'-- Basin SQL: index extracted JSON scalar values to avoid full-document scans
CREATE INDEX idx_telemetry_event_type ON telemetry_events ((json_get_str(payload, '$.event_type')));
CREATE INDEX idx_telemetry_timestamp ON telemetry_events ((json_get_int(payload, '$.timestamp')));Row-level security policies prevent cross-tenant reads when storing multi-tenant telemetry in shared Iceberg tables. Indexing extracted JSON scalar values avoids full-document scans on 16 MiB payloads, which would otherwise force the engine to parse the entire document for every query.
Migration Checklist & Break-Even Thresholds
- Audit existing queries that split JSON documents across multiple rows; consolidate where document size stays under 16 MiB.
- Measure R2 operation volume for 16 MiB payloads at peak QPS; compare against preprocessing compute costs.
- Add
json_lengthguards in application code to reject documents exceeding 16 MiB before insert. - Benchmark cold-start latency for serverless Postgres connections under concurrent load.
- Configure connection pool timeouts to match expected query duration for large JSON parsing.
Break-even analysis: If preprocessing a 2,000-byte JSON document costs 5 ms of compute and 1 KB of egress, while querying a 16 MiB document directly costs 50 ms of compute and 16 MiB of egress, the direct query path becomes economical only when egress pricing is below roughly $0.009 per GiB or when preprocessing infrastructure costs exceed the egress delta. For workloads with high read frequency and low write volume, storing full documents in Iceberg and querying them directly reduces operational complexity. For write-heavy telemetry pipelines, the egress cost of repeated 16 MiB reads may favor continued preprocessing or columnar storage.
When NOT to use this: Do not store 16 MiB JSON documents in tables with high update frequency. Each rewrite of a large JSON payload incurs full TOAST-equivalent rewrite costs in PostgreSQL-compatible engines and full object replacement in Iceberg. Use this pattern for append-only telemetry and logs, not for frequently mutated application state.

Basin SQL JSON functions now support documents up to 16 MiB
Reader Q&A
Frequently Asked Questions
Does the 16 MiB limit apply to all Basin SQL JSON functions?
How does Basin SQL's limit compare to PostgreSQL TOAST behavior?
What is the R2 egress cost for a 16 MiB JSON payload?
Bibliography & Verification
Primary Sources & References
Human × Agent Co-Work
Hamdi Soudani · in collaboration with Pyvren
Systems engineer & technical writer exploring AI infrastructure, security, and edge craft in daily collaboration with Pyvren.
Keep Reading
Related Dispatches
Hamdi Soudani × Pyvren
Honest engineering stories — co-crafted with primary benchmarks & real code
Every dispatch blends hands-on engineering judgment with verified primary sources, reproducible configs, and clear tradeoffs.