High-Concurrency Image Delivery: Architecture Design and Performance Optimization

    This article explains how to design and optimize a high-concurrency image delivery system. It covers the limitations of serving images from application servers, a layered architecture, upload and write pipelines, storage and derivative image strategies, caching and distribution design, security and cost control, observability and capacity estimation, and common pitfalls. Readers will learn how to keep bandwidth costs under control, protect the origin, reduce latency, and maintain a stable viewing experience at scale.

    1. Background: From Sharing a Batch of Images to Delivering Them at Scale

    The original requirement looks simple: publish a batch of high-quality images, let as many users as possible browse them smoothly, and hope those users come back. But when traffic grows from a few dozen users to hundreds of thousands, this seemingly simple requirement quickly turns into a classic engineering problem: runaway bandwidth costs, an overwhelmed origin, slow first-screen loading, difficult adaptation across devices, and frequent malicious crawling and hotlinking.

    Many teams initially store images on the local disk of the application server, and the application process reads and returns them. This works during validation, but it has three structural flaws:

    1. The application process is blocked on I/O, compute resources are coupled with storage resources, and scaling can only enlarge everything together, which wastes a lot.
    2. A single disk has limits on capacity and throughput and cannot scale horizontally.
    3. There is no edge-based distribution, so users across regions experience high latency.

    The core idea of image delivery is therefore to decouple compute from storage, push static assets down to the edge, and trigger dynamic processing on demand. The following sections go through the pipeline layer by layer.

    2. Layered Architecture

    A mature image delivery system typically has five layers:

    • Access layer: domain resolution, nearest access point, TLS termination, rate limiting, and security protection.
    • Distribution layer: edge cache nodes that handle the vast majority of read requests.
    • Storage layer: object storage that holds original images and derivative images.
    • Processing layer: image decoding, cropping, compression, format conversion, and watermark overlay.
    • Control layer: configuration distribution, cache purge, monitoring and alerting, and cost accounting.

    The key design principle is that read requests should terminate at the edge as much as possible, and only go back to the origin on a miss. Write requests (uploads) use a separate path so they do not affect the stability of the read pipeline.

    3. Upload and Write Pipeline

    The upload stage is not about “can the file be uploaded” but about “uploading reliably, quickly, and safely”.

    3.1 Client-Side Direct Upload and Credential Delegation

    The recommended approach is for the server to issue a time-limited temporary upload credential, and the client writes directly to object storage, so images do not flow through the application server and consume bandwidth twice. The credential must restrict the path prefix, size limit, and validity period:

    1. Credential constraints example (pseudocode)
    2. path_prefix = "images/2026/08/"
    3. max_size = 10 MB
    4. expire_in = 300 s
    5. content_type= image/*

    3.2 Resumable Upload and Integrity Verification

    Large image uploads should support chunking and resumable upload. After each chunk is uploaded, its index is recorded; once all chunks are done, a merge is triggered. After merging, the server should verify the object size and content digest to prevent truncated files from entering the delivery pipeline. Objects that fail verification go into an isolation prefix and wait for a cleanup job to reclaim them.

    3.3 Separating Metadata from Business Data

    Image binaries go to object storage, while business attributes (title, tags, visibility, collection membership) go to a database. The two are linked by a unique identifier. The benefits are: database rows stay short and indexing is efficient; the image read path does not depend on the database, so availability is higher.

    4. Storage and Derivative Image Strategy

    4.1 Original Images and Derivative Images

    Keep one original image as the “source of truth” and treat all other sizes as regenerable derivative data. Derivative image names should carry spec information to make troubleshooting and batch invalidation easier:

    1. Original: images/2026/08/a1b2c3.jpg
    2. Derivative: images/2026/08/a1b2c3_w800_h600_q80.webp

    4.2 Combining On-Demand and Pre-Generation

    Fully on-demand generation will overwhelm the processing layer during traffic spikes; fully pre-generated images waste storage and compute. In practice, a safer approach is to combine the two: pre-generate high-frequency placements such as the home page, rankings, and collection covers; use on-demand generation for long-tail sizes, and set a per-object processing lock to avoid the same image being computed repeatedly under concurrency.

    1. On-demand generation flow (pseudocode)
    2. key = normalized derivative key
    3. if exists(key): return key
    4. if not acquire_lock(key): wait and read again
    5. img = read original image(key)
    6. out = crop and compress(img, target spec)
    7. write to object storage(key)
    8. release lock(key)
    9. return key

    4.3 Format and Quality Adaptation

    The same content can be provided in multiple encoding formats, negotiated by the access layer based on request headers, so the client does not need to be aware of it. Quality parameters should not be hard-coded; it is better to set tiers by the main use of the image: avatar-type images can use low resolution with high quality, illustration-type images need to preserve detail, and photo-type images can use more aggressive compression in exchange for smaller size.

    5. Distribution and Cache Design

    5.1 Cache Key Normalization

    Cache keys must be normalized; otherwise the same image will produce multiple copies due to different parameter order, and the hit rate will drop sharply. It is recommended to keep only whitelisted parameters and concatenate them in a fixed order:

    1. canonical_key = /img/{id}?w={w}&h={h}&q={q}&f={f}
    2. Non-whitelisted parameters are discarded and do not participate in caching or origin fetch

    5.2 Tiered Caching and Warm-Up

    Edge node caches handle the main read traffic, and origin-fetch requests should be merged (only one concurrent origin fetch is allowed per key) to avoid a cache stampede. Content updates follow the order “write to storage first, then purge cache”; if the purge fails, a shorter fallback expiration time lets things converge automatically.

    Actively warming up before publishing new content, pushing hot keys to the edge in advance, can significantly reduce the origin-fetch peak at the moment of release.

    5.3 Degradation and Fallback

    A degradation path must be designed: when the processing layer is unavailable, return the nearest existing spec; when object storage is abnormal, return a placeholder image instead of an error page; under extreme rate limiting, prioritize logged-in users and core pages. The criteria for degradation should come from monitoring metrics, not manual guesses.

    6. Security and Cost Control

    On the security side, at least four things must be covered: hotlink protection (referer validation), private content (time-limited signed access), upload content compliance checks (asynchronous review, isolation on hit), and abnormal crawling detection (rate limiting by access pattern rather than a single IP).

    The key point on the cost side is that the bill for image delivery is mainly made up of egress traffic and storage capacity, and compute cost is often not the main part. So the optimization priority should be: improve cache hit rate > reduce per-image size > reduce the number of storage copies > optimize compute specs. Setting a lifecycle policy for derivative images, automatically moving specs that have not been accessed for a long time to infrequent access or deleting them, is the most cost-effective move.

    7. Observability and Capacity Estimation

    Core metrics to collect include: hit rate, origin-fetch rate, time to first byte, end-to-end load time, processing queue backlog, and failure rate broken down by error type. Averages alone are not enough; you should look at percentiles, because the long tail is the source of user experience.

    Capacity estimation can start with a simplified model for an upper-bound estimate:

    1. Peak egress bandwidth ≈ daily active users × images viewed per user × average bytes per image ÷ active duration × peak factor
    2. Every 10% increase in cache hit rate reduces origin-fetch bandwidth by roughly the same proportion

    This model is used to determine the scale of scaling and the budget range; real values need to be calibrated with load testing and production observation.

    8. Common Pitfalls

    1. Setting the cache expiration too long without a refresh mechanism, making content updates uncontrollable.
    2. Cache keys containing unconstrained user parameters, diluting the hit rate.
    3. Derivative images growing without limit, so storage cost inflates linearly over time.
    4. Only rate limiting at the application layer, lacking edge-side protection, so the origin is still punched through.
    5. Monitoring only successful volume and not failure composition, making fault localization very inefficient.

    9. Summary

    Image delivery is essentially a typical “read-heavy, write-light, size-sensitive, edge-friendly” scenario. Decoupling storage from compute, treating derivative data as a regenerable resource, normalizing cache keys, and designing degradation paths and monitoring metrics in advance will give you a stable viewing experience with controllable cost. On top of that, using general capabilities such as object storage, content delivery, and log monitoring from Baidu AI Cloud, teams can focus their energy on the business and content quality itself, rather than repeatedly patching infrastructure.