How an Everyday Upload Limit Turned into an Algorithm Problem
1. The Problem I recently got a bug ticket about a file upload flow. The application is deployed on Vercel. When creating an order, users can attach multiple files, and the original implementation bundles all files into a single request. This caused us to hit Vercel's 4.5 MB request size limit . For example: File A: 2.0 MB File B: 1.5 MB File C: 1.2 MB Total: 4.7 MB Each individual file is…
The issue arose when creating orders with multiple files attached, causing a breach of Vercel's 4.5 MB request size limit. To resolve this, files could be uploaded individually, but this would lead to an increase in HTTP requests. The challenge then became to find the most efficient way to group the files, minimizing the number of requests.
This problem resembled the Bin Packing Problem, where the goal is to minimize the number of bins (in this case, requests) used to store items (files) each with a specific size, without exceeding a given size limit (the 4.5 MB request limit). The problem was akin to LeetCode 1986, which required finding the minimum number of work sessions needed to complete a set of tasks with a given session time, utilizing bit mask dynamic programming.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.