Let's say I'm designing a REST service with Spring, and I need to have a method that accepts a file, and returns some kind of ResponseDto. The application server has its POST request size limited to 100MB. Here's the hypothetical spring controller method implementation:
public ResponseEntity<ResponseDto> uploadFile(@RequestBody MultipartFile file) {
return ResponseEntity.ok(someService.process(file));
}
Let's assume that my server has 64GB of RAM. How do I ensure that I don't get an out of memory error if in a short period (short enough for process()
method to still be running for every file uploaded), 1000 users decide to upload a 100MB file (or just 1 user concurrently uploads 1000 files)?
EDIT: To clarify, I want to make sure my application doesn't crash, but instead just stops accepting/delays new requests.