
Web Dev Limits
In February 2025, someone posted to the MongoDB community forums that their MongoDB service had gone down. The log said BSONObjectTooLarge: an object of 17,041,110 bytes, against a limit of 16,793,600.
The twist came in the replies. Someone pointed out that the oversized document wasn't the poster's data at all. It was FTDC, the diagnostic data the server collects about itself. The advice was to upgrade from 6.0.15, or to switch diagnostic collection off.
I like that story because nobody did anything obviously wrong. A limit every MongoDB user has heard of, 16MB per document, still took a service down, and the document that crossed it was one the database wrote on its own.
Every layer of a web stack has ceilings like that. API Gateway rejects anything over 10MB. A synchronous Lambda call stops at 6MB. localStorage gives an origin 5MiB. nginx refuses a 2MB upload out of the box. Most of them stay invisible until something crosses them, usually in production and usually at a bad time.
Some of the numbers developers repeat to each other are also out of date. I've checked each one below against its source, and the references are at the end.
Numbers that get repeated wrong
| What people say | What's actually true |
|---|---|
| URLs max out at 2,048 characters | Internet Explorer's limit was 2,083. Chrome allows 2MB. Today the server usually breaks first: nginx rejects a request line over 8KB. |
| Node's heap defaults to about 1.4GB | Since Node 12.7 the heap follows the container's memory limit. On Node 20 it's about half the container, levelling off near 2GB for containers of 4GiB up. |
| Browsers allow 6 connections per host | That's HTTP/1.1. HTTP/2 sends many requests over one connection, though servers still cap streams per connection (nginx defaults to 128). |
5MB of localStorage is plenty |
5MiB is the ceiling per origin, and every read and write is synchronous. IndexedDB can use a large share of the disk. |
| File uploads just work | nginx's default client_max_body_size is 1MB, which is smaller than most photos straight off a phone. |
1. API payload size
AWS API Gateway rejects request payloads over 10MB, for REST and HTTP APIs alike, and that quota can't be raised. If a Lambda function sits behind it, Lambda's own limit is tighter: 6MB for a synchronous request and 6MB for the response. That's usually the one people hit first. Response streaming lifts the response side to 200MB, but the request side stays at 6MB.
So keep big things out of the request. Paginate large datasets across several calls, compress what you can with gzip or Brotli, and batch lots of small operations into fewer requests. For files, skip the API entirely: hand the client a presigned S3 URL, let it upload straight to storage, and let a Lambda pick the file up from there. API Gateway never has to touch it.
2. MongoDB document size
A MongoDB document can be at most 16MiB of BSON. Nobody sets out to design a document that big. They get there slowly: an array that gains an element on every event, a nested object that keeps sprouting fields, or base64 images stored inline because it was convenient at the time.
Split data that grows without bound into its own collection and reference it. Put files in GridFS, which stores them in chunks. Watch document sizes in production with the $bsonSize aggregation operator, so the biggest documents show up on a dashboard long before one of them hits the ceiling. And keep the server itself patched, since in the forum case the problem document was MongoDB's own.
3. Browser storage
localStorage and sessionStorage get 5MiB each per origin, 10MiB combined at most. The API is synchronous, so large reads and writes block the main thread, and there's no indexing or querying at all.
You've probably heard that 5MB of localStorage is plenty for caching on the client. It's a ceiling, not a comfortable budget, and anything past a handful of preferences belongs somewhere else.
That somewhere is IndexedDB, which shares a much bigger per-origin budget with the Cache API and the origin private file system. Chromium-based browsers let an origin use up to 60% of the disk. Safari allows around 60% for browser apps. Firefox, in its default best-effort mode, allows the smaller of 10% of the disk or 10GiB per site, and up to 50% once the site has been granted persistent storage.
Cookies sit at the other extreme. RFC 6265 only asks browsers to support at least 4,096 bytes per cookie and 50 cookies per domain. Chrome allows 180 per domain.
Use IndexedDB for real client-side data. It's more work than localStorage, but it was built for this. Add cleanup routines so stale data doesn't pile up forever, call navigator.storage.persist() if losing the data would actually hurt, and keep anything that matters on a server.
4. URL length
The 2,048-character rule gets repeated everywhere. Internet Explorer's real limit was 2,083 characters, defined in its networking library, and IE has been retired for years. Chrome accepts URLs up to 2MB, and Firefox and Safari also go far beyond IE's old limit.
The server is where long URLs break now. nginx needs the whole request line to fit into one 8KB buffer, or it returns 414 Request-URI Too Large. Apache's LimitRequestLine defaults to 8,190 bytes. API Gateway caps a Regional REST API's URL at 10,240 characters, and edge-optimized and private APIs at 8,192.
Stop putting whole application state into query strings. Send complex queries as POST bodies, keep state in the client, and if a long URL is genuinely needed, check the web server's configuration first, because that's almost certainly where the limit lives.
5. Memory and timeouts
You may have heard that V8 gives Node about 1.4GB of heap on 64-bit systems. That was the old default. Since Node 12.7, released in 2019, Node sets the heap limit from the container's cgroup memory limit. Red Hat measured Node 20 images at about half the container's memory, levelling off near 2GB once the container has 4GiB or more. You can still override it with --max-old-space-size (in MiB), or with the newer --max-old-space-size-percentage.
One catch: under cgroup v2, older Node versions didn't see the container limit at all. The libuv function Node uses only read cgroup v1, so in one reported case a pod limited to 600MiB got a heap limit of 1.96GiB. libuv 1.45 fixed it in 2023. To check what your process actually got, compare v8.getHeapStatistics().heap_size_limit with the container's limit.
Timeouts are the other quiet failure. A REST API in API Gateway allows an integration up to 29 seconds by default. Since June 2024 you can raise that for Regional and private REST APIs, though it may cost you some of your account's throttle quota. HTTP APIs stop at 30 seconds, and that can't be raised. Lambda itself can run for 15 minutes, which doesn't help when the gateway in front gives up after 29 seconds.
Release objects you're done with, stream large data instead of loading whole files into memory, and break long work into smaller async steps. Anything that takes more than a few seconds belongs in a background job, with a webhook or a polling endpoint for the client.
6. Browser connections
Over HTTP/1.1, browsers open about six connections per host. Fire off 20 requests at once and 14 of them wait in a queue.
HTTP/2 sends many requests over a single connection, which mostly retires that problem. It doesn't remove limits entirely, because servers cap the number of concurrent streams on each connection. nginx's default is 128.
Make sure the server and CDN speak HTTP/2, which most do by now. If you're stuck on HTTP/1.1, batch requests and lazy-load anything that isn't critical.
7. Cache storage
The Cache API that service workers use draws from the same per-origin budget as IndexedDB, so the numbers in section 3 apply here too. The budget isn't guaranteed, either. Data stored in best-effort mode can be evicted when the device runs low on space, and phones get there much sooner than laptops.
Cache what matters and let the rest go. A stale-while-revalidate strategy keeps the app fast without hoarding old assets. Write service workers that handle a cache miss gracefully, because on a budget Android phone the cache you were counting on may simply be gone.
8. File upload size
This one catches people because the defaults are so much lower than they'd guess. nginx's client_max_body_size defaults to 1MB and returns 413 Request Entity Too Large above it.
Apache is the opposite. Its LimitRequestBody was unlimited until 2.4.54, which changed the default to 1GiB. The "2MB" figure people associate with Apache is usually PHP, whose defaults allow 2MB per file (upload_max_filesize) and 8MB per request (post_max_size). Platforms and frameworks add their own caps on top.
Set the limit explicitly at every layer: the proxy, the app server and the framework. For large files, use chunked, resumable uploads so a dropped connection doesn't mean starting again. tus and Uppy make that much less painful than it sounds.
9. Database connections
Every database has a ceiling on concurrent connections, and hosted ones make it very concrete. MongoDB Atlas Free and Flex clusters allow 500 connections. Paid tiers allow more per node: on AWS, an M10 allows 1,500 and an M20 3,000. Managed PostgreSQL varies by plan and instance size.
This limit bites when things are going well. Traffic spikes, every request fights for a connection, and the resulting errors look random and intermittent. Serverless makes it easier to hit, because every new function instance opens connections of its own.
Pool connections and reuse them instead of opening one per request. Send read-heavy traffic to replicas, and watch the connection count in production so pool exhaustion shows up as a graph instead of a mystery.
10. TCP ephemeral ports
This is the most invisible limit on the list. When your app opens a TCP connection, the OS picks a local port for your side of it. On Linux those come from a default range of 32768 to 60999, which is 28,232 ports. After a connection closes, its port sits in TIME_WAIT for about 60 seconds before it can be reused.
On Monday, 6 April 2026, Bluesky was intermittently down for about eight hours because of exactly this. A new internal service started calling the AppView data plane's GetPostRecord with batches of 15,000 to 20,000 URIs, while normal callers sent 1 to 50. The endpoint started one goroutine per URI, each dialing memcached, and unlike the other endpoints it never called errgroup's SetLimit. The pool kept only 1,000 idle connections.
The arithmetic is brutal. One 15,000-URI call needs about 14,000 new connections, and each of those ports then sits in TIME_WAIT for a minute. Two such calls inside a minute and the whole range is gone. The caller was making fewer than three requests a second. Volume had nothing to do with it; batch size did.
The logs said bind: address already in use. Bluesky's temporary fix was a dialer that picked a random loopback IP for each connection, which widened the space of usable address and port pairs. Their post-mortem calls group.SetLimit(50) "the critical missing line."
Cap concurrency wherever you fan out, with errgroup's SetLimit in Go or a semaphore anywhere else. Use pools that bound the total number of connections, not just the idle ones. net.ipv4.tcp_tw_reuse lets new connections reuse TIME_WAIT sockets when it's safe. Its default only does that for loopback traffic, and setting it to 1 turns it on everywhere. net.ipv4.ip_local_port_range can be widened too. Watch TIME_WAIT counts with ss -s, because the usual symptom is connect: cannot assign requested address, and by then you're already in an outage.
11. WebAssembly memory
WebAssembly memory comes in 64KiB pages. A standard 32-bit module can address at most 65,536 of them, which is 4GiB. Memory64 lifts that: it shipped in Chrome 133 and Firefox 134 in early 2025 and is part of WebAssembly 3.0. Browsers still cap a single memory at 16GB through the JavaScript API. It isn't free, though. SpiderMonkey's measurements put the slowdown anywhere from 10% to over 100% depending on the workload, so it's worth it only when you really need more than 4GiB. Mobile devices run out of physical memory long before either limit.
Be deliberate about allocating and freeing memory in Wasm modules, use streaming compilation so the module isn't loaded all at once, and profile early. If you're pushing Wasm this hard you're probably building something interesting, which is all the more reason to measure.
12. LLM token limits
These numbers change faster than anything else in this post, so treat them as a snapshot from October 2026.
Every current Claude model (Fable 5.1, Opus 5.5, Sonnet 5.5 and Haiku 5.5) has a 1M-token context window and can write up to 128K tokens in one response. OpenAI's GPT-4.1 family reached 1M tokens in April 2025, where GPT-4o had stopped at 128K. Embedding models are much smaller: OpenAI's text-embedding-3 models take up to 8,192 tokens per input.
Chunk long text sensibly, overlap the chunks when continuity matters, and summarize long documents before sending them. Count tokens before you send a request (tiktoken for OpenAI models, the token counting endpoint for Claude), and keep the model behind an interface you can swap, because these limits will have moved again by the time you read this. Check the provider's docs for current values.
13. HTTP header size
Most of us never think about header sizes until we're staring at a 431 Request Header Fields Too Large at four on a Friday.
nginx needs each header field to fit into one 8KB buffer, or it returns 400. Apache allows 8,190 bytes per field and 100 fields. Node's HTTP server accepts 16KiB of headers in total by default, raised from 8KiB in v13.13.0. API Gateway caps all header values on a REST API at 20,480 bytes combined (8,000 on a private API), and on an HTTP API the request line and headers together at 10,240 bytes.
The usual culprits are bloated cookies, long JWTs and piles of custom headers, often all three. Keep cookies lean and don't store whole session objects in them. Audit what's in your JWT claims, because they tend to collect data nobody uses. If a request needs to carry a lot of metadata, put it in the body.
Quick reference
| Limit | Default or cap | What helps |
|---|---|---|
| API payload | 10MB (API Gateway), 6MB (Lambda synchronous) | Pagination, compression, presigned uploads |
| MongoDB document | 16MiB of BSON | Separate collections, GridFS, $bsonSize checks |
| Browser storage | 5MiB localStorage, up to 60% of disk for IndexedDB in Chromium |
IndexedDB, cleanup, navigator.storage.persist() |
| URL length | 2MB in Chrome, 8KB request line in nginx, 8,190 bytes in Apache | POST bodies, client state, server config |
| Memory and timeouts | About half the container for Node's heap, 29s REST API integration | Streaming, background jobs |
| Browser connections | About 6 per host on HTTP/1.1, 128 streams per connection in nginx | HTTP/2, batching, lazy loading |
| Cache storage | Shares the origin's quota, evictable under pressure | Cache less, handle misses |
| File uploads | 1MB in nginx, 1GiB in Apache 2.4.54+, 2MB per file in PHP | Explicit limits at every layer, resumable uploads |
| Database connections | 500 on Atlas Free and Flex | Pooling, read replicas, monitoring |
| Ephemeral ports | 28,232 on Linux, about 60s in TIME_WAIT |
Concurrency caps, bounded pools, tcp_tw_reuse |
| WebAssembly memory | 4GiB for 32-bit modules, more with Memory64 | Careful allocation, profiling |
| LLM tokens | 1M context on current Claude models and GPT-4.1 | Chunking, summarizing, counting tokens first |
| HTTP headers | 8KB per field in nginx, 16KiB total in Node, 20,480 bytes in API GW | Lean cookies, smaller tokens, data in the body |
The pattern
Almost every one of these follows the same arc. Something works in development, works in staging and works in production for months. Then the data gets a bit bigger, or a new caller shows up with an unusual batch size, and it falls over.
Bluesky's outage didn't need high traffic, just a batch nobody had capped. The MongoDB poster didn't need a bad schema, because the document that broke was the database's own. The limits apply whether or not anyone is watching them.
What helps is knowing where the walls are, measuring how close you are in production, and deciding ahead of time what you'll do when a number starts creeping up. If you've hit a limit that isn't on this list, tell me about it in the comments.
References
- MongoDB forum: service down with BSONObjectTooLarge (February 2025)
- MongoDB limits: BSON document size
- MongoDB: $bsonSize
- API Gateway quotas for REST APIs
- API Gateway quotas for HTTP APIs
- API Gateway integration timeout increase (June 2024)
- Lambda quotas
- MDN: storage quotas and eviction criteria
- RFC 6265: HTTP state management (cookies)
- Chromium: cookies per domain (kDomainMaxCookies)
- Chromium: connections per host
- Chromium URL display guidelines (2MB URL limit)
- IEInternals: URL length limits
- nginx core module: client_max_body_size and header buffers
- nginx HTTP/2 module: http2_max_concurrent_streams
- Apache core directives: LimitRequestBody, LimitRequestLine, LimitRequestFieldSize
- PHP core settings: upload_max_filesize and post_max_size
- Node.js 20+ memory management in containers (Red Hat)
- Node.js: heap limit from cgroup memory (PR #27508)
- Node.js: wrong memory ceiling under cgroup v2 (#47259)
- Node.js command-line options
- MongoDB Atlas: Free and Flex cluster limits
- MongoDB Atlas: Flex cluster limits
- MongoDB Atlas: service limits (connections per node)
- Linux kernel: ip-sysctl (ip_local_port_range, tcp_tw_reuse)
- Linux kernel: TCP_TIMEWAIT_LEN in tcp.h
- Linux man page: connect(2), EADDRNOTAVAIL
- Bluesky: April 2026 outage post-mortem
- Surfing Complexity: thoughts on the Bluesky incident write-up
- MDN: WebAssembly.Memory
- SpiderMonkey: is Memory64 actually worth using?
- WebAssembly 3.0 announcement
- Claude models overview
- Claude token counting
- OpenAI: introducing GPT-4.1
- OpenAI API reference: embeddings
Enjoyed this post?
Get the next one by email. No spam.
By subscribing, you agree to our Privacy Policy. You can unsubscribe at any time.
Discussion
Loading comments...
This website is still under development. If you encounter any issues, please contact me.