Quick revision
The short answer
Each slow upload holds a Tomcat thread for the whole time the client takes to send its body, so a few hundred slow phones occupy all 200 threads while the CPU has almost nothing to do. A reverse proxy with request buffering, which NGINX does by default, receives the whole body from the slow client first and then hands it to Tomcat at local network speed, and response buffering does the same for downloads. The proxy should also enforce body size, timeouts and per-client connection limits, and for large files, direct uploads to object storage with presigned URLs keep them out of the service entirely.
What to remember
In this answer, we saw that with one thread per request, each slow upload blocks a Tomcat thread for its entire duration, so about 190 slow photos exhaust 200 threads at 15 percent CPU. A reverse proxy with request buffering receives the whole body first and hands it to Tomcat in milliseconds, response buffering does the same for downloads, the proxy enforces size, timeout and connection limits, and presigned URLs let large files go straight to object storage.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Each slow upload holds a Tomcat thread for the whole time the client takes to send its body, so a few hundred slow phones occupy all 200 threads while the CPU has almost nothing to do. A reverse proxy with request buffering, which NGINX does by default, receives the whole body from the slow client first and then hands it to Tomcat at local network speed, and response buffering does the same for downloads. The proxy should also enforce body size, timeouts and per-client connection limits, and for large files, direct uploads to object storage with presigned URLs keep them out of the service entirely.
Why this question is asked
A service that stops responding at 15 percent CPU is a classic puzzle: nothing is busy, yet nothing gets served. The thread dump gives it away, and the fix is one of the oldest reasons reverse proxies exist. Interviewers ask this because it tests whether we understand the thread-per-request model and what a proxy buffers. In this answer, we will recap how Tomcat assigns threads, do the arithmetic of slow uploads, see how proxy buffering fixes it, add protective limits, and look at uploading straight to object storage.
1A Quick Recap: One Thread per Request
Spring MVC on Tomcat uses a thread per request. When a request arrives, Tomcat takes a thread from its pool, 200 by default, and that thread runs the whole request: reading the body, running our controller, writing the response. While the thread waits for bytes from the network, it is blocked, doing nothing but unavailable for anyone else. When all 200 threads are busy, new connections wait in a queue, and eventually clients time out.
This model works well when requests arrive quickly and spend their time computing or waiting on fast local services. It works badly when the slowest part of a request is the client itself.
2Doing the Arithmetic of Slow Uploads
A phone uploads a 4 MB photo over a weak evening connection at about 500 kilobits per second, which is about 62 kilobytes per second. Sending the body takes about 64 seconds. For all that time, a Tomcat thread sits inside the request body read, blocked. If three such uploads start every second, then by Little's law the number in progress at once is the arrival rate times the duration: 3 times 64 is about 190 threads busy just waiting for photos.
Add a handful of normal requests and the pool is exhausted. Every thread is blocked reading a request body, exactly what the thread dump showed, and the CPU sits at 15 percent because receiving bytes slowly costs almost nothing. The service is not overloaded with work; it is overloaded with waiting.
Notice the numbers in that thread: 58 seconds elapsed, 21 milliseconds of CPU. The thread is almost entirely idle, yet it is not available.
3How Request Buffering Fixes It
Put NGINX in front of Tomcat. With request buffering, which NGINX does by default through proxy_request_buffering on, NGINX reads the entire request body from the client before it opens a request to the backend. The slow 64-second upload now happens between the phone and NGINX, which is built on an event loop and holds thousands of slow connections with a few worker processes and a little memory each. Only when the whole photo has arrived, in memory or in a temporary file, does NGINX send it to Tomcat over the local network, which takes milliseconds.
So a Tomcat thread is busy for the real work, perhaps 50 milliseconds to read the body locally, resize and store the photo, instead of 64 seconds. The same 200 threads now serve hundreds of requests per second.
6 messages in order. Play them, or step through them one at a time.
The slow part happens at the proxy; the Java thread is busy only for the real work.
Response buffering, controlled by proxy_buffering and also on by default, does the same in the other direction. Tomcat writes the response to NGINX at full speed and the thread is released, while NGINX trickles the response to a slow client.
4Limits That Belong at the Proxy
The proxy is also the right place to protect the service. A maximum body size rejects a 2 GB upload with 413 before it consumes anything. Timeouts on reading the client's body and headers close connections that stall, which also defends against slow-request attacks, where an attacker deliberately sends a byte every few seconds to hold resources. Connection and request rate limits per client address stop one client from opening thousands of connections.
Note that client_body_timeout limits the time between two successive reads, not the whole upload, so a slow but steady phone still succeeds while a stalled one is cut off.
5For Large Files: Skip the Service Entirely
For photos and larger files, there is a better design: the file never passes through our service at all. The app asks the service for permission to upload; the service checks the user and returns a presigned URL, a time-limited URL for a specific object in object storage such as Amazon S3, signed with our credentials. The app uploads directly to S3, which is built to absorb slow uploads at any scale, and then tells the service the upload is done, or S3 sends an event. The service handles two tiny JSON requests instead of a 4 MB body.
This also removes the proxy's temporary files and bandwidth from the picture, and it lets uploads resume across network drops with multipart uploads.
6Follow-up questions
Would virtual threads remove the need for buffering?
They would remove the thread exhaustion. With spring.threads.virtual.enabled=true on Spring Boot 3.2 or later and Java 21 or newer, each request runs on a cheap virtual thread, and a virtual thread blocked reading a socket does not hold an operating system thread, so thousands of slow uploads no longer starve the service. But each slow request still holds a connection, buffers and memory in Tomcat, and Tomcat's maximum connection count still applies. The proxy's limits, timeouts and protection against slow-request attacks are still valuable, and presigned uploads are still better for large files. So virtual threads remove the most painful symptom, not the reasons to have a proxy.
Why not just raise Tomcat's thread pool to 2,000?
It would postpone the problem rather than solve it. Two thousand platform threads cost memory for their stacks and scheduling overhead, the number of slow clients can still exceed any fixed pool on a bad evening, and an attacker can fill it on purpose. Buffering removes the dependency between client speed and threads.
7Conclusion
In this answer, we saw that with one thread per request, each slow upload blocks a Tomcat thread for its entire duration, so about 190 slow photos exhaust 200 threads at 15 percent CPU. A reverse proxy with request buffering receives the whole body first and hands it to Tomcat in milliseconds, response buffering does the same for downloads, the proxy enforces size, timeout and connection limits, and presigned URLs let large files go straight to object storage.
Open with
Tomcat uses a thread per request, 200 by default, and a thread is held for the whole request, including the time spent reading the body. An evening photo upload at about 500 kilobits per second takes around a minute for a 4 MB photo, so at three uploads a second about 190 threads are just sitting there waiting for bytes.
Then, if they want more
That is why the thread dump shows threads blocked reading request bodies while the CPU is at 15 percent: the service is full of waiting, not work. The fix is a reverse proxy with request buffering in front.
NGINX does this by default with proxy_request_buffering on: it receives the whole body from the slow phone on its event loop, which handles thousands of slow connections cheaply, and only then sends it to Tomcat at local network speed, so the thread is busy for milliseconds. Response buffering does the same for slow downloads.
I would also set limits at the proxy: client_max_body_size, body and header timeouts, and connection limits per client, which also protect against slow-request attacks. For photos specifically, I would go further and use presigned S3 URLs so the app uploads directly to object storage and the service only handles two small JSON calls.
Virtual threads would remove the thread exhaustion, but I would still keep the proxy's limits.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Java 21, Spring Boot 3.2
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is happening, and how can a reverse proxy in front of the service fix it?": https://scrivio-interview-library.netlify.app/architecture/load-balancing-networking/6f7e25a8ad/