A developer is processing a 50-image batch where each image is a photograph of a handwritten form. The images are sent as base64-encoded PNG in the API request. Average image size is 2MB. The team notices response latency is 45 seconds per API call for a batch of 10 images. What is the most effective optimization?
Select an answer to reveal the explanation.
Short Explanation
Here's the deal — convert those 2MB PNG photographs to JPEG at 85% quality before base64 encoding. JPEG cuts photographic file size by 70-80% while handwritten text stays legible, so your request payload and latency drop fast.
Full Explanation
The most effective optimization is converting images from PNG to JPEG with an 85% quality setting before encoding. A 2MB PNG image of a photograph is inefficiently encoded for transmission because photographs contain gradients, shadows, and varied tones. JPEG at 85% quality reduces photographic image size by 70-80%, bringing a 2MB image down to roughly 400KB, with minimal impact on handwriting legibility because handwritten text is high-contrast and survives JPEG compression well. This directly reduces the base64 payload and transmission time, which is the root cause of the observed latency.
Increasing image resolution before base64 encoding is wrong because the latency problem comes from transmission and processing overhead caused by large images, not from insufficient resolution. Raising resolution makes the images larger, which worsens payload size and latency.
Using URL image references instead of base64 encoding is wrong because it requires the images to be accessible at a public URL, which may not be available, and introduces a dependency on external hosting. That makes the architecture more complex than simply converting the image format before encoding.
Sending images individually in 10 separate API calls rather than batching 10 images per call is wrong because parallelizing API calls can improve throughput, but it does not reduce the per-image processing cost. It also multiplies the number of API connections and may hit rate limits, so it addresses throughput rather than the root cause of per-call latency.