All resources
Cloud Infrastructure10 min read

Build resumable uploads that survive bad networks

A protocol for chunked uploads, checksums, expiration, and safe assembly across browsers and unreliable connections.

A practical PingFlow guide for developers working at the boundary between systems.

At a glance

Key takeaways

  • Start with the boundary
  • Model the system before choosing a tool
  • Design for failure, misuse, and change
In this guide

Start with the boundary

Build resumable uploads that survive bad networks is easiest to get right when the boundary is named before the implementation begins. Decide which system owns the decision, which inputs are trusted, what the caller can observe, and what must remain private. That framing prevents a local optimization from quietly becoming an undocumented protocol.

Large uploads fail for reasons unrelated to the file: a laptop sleeps, a mobile network changes, a proxy closes an idle connection, or a user refreshes the page. A resumable protocol turns one fragile request into a series of bounded operations with a durable upload session. The server must still know when a file is complete and trustworthy.

Model the system before choosing a tool

Create an upload session with an owner, expected size, checksum or part manifest, expiration, and maximum part size. Store parts under an opaque session prefix and keep completion metadata separate from the bytes. Decide whether the client uploads directly to object storage or through your API, and make the final assembly an explicit state transition.

Write the model down as a small state diagram or table before selecting a library. Identify the durable state, the derived state, and the transitions that may be retried. This makes it easier to compare a managed service with an in-process implementation and to explain why a particular trade-off is acceptable for this workload.

Design for failure, misuse, and change

Part numbers can be repeated with different bytes, a client can claim completion before all parts arrive, and an abandoned session can consume storage forever. Parallel parts may arrive out of order. A checksum of concatenated bytes is not the same as a provider's multipart checksum, so document which value is authoritative.

A resilient design assumes that inputs are incomplete, dependencies are slow, operators make mistakes, and requirements will change. Put limits at the boundary, return errors that a caller can act on, and preserve enough context to distinguish a bad request from an unavailable dependency. Avoid broad fallbacks that make an unsafe state look successful.

Implementation example

Issue short-lived part URLs or an authenticated upload endpoint, validate part number and size, and record a checksum for every accepted part. Make retries with the same part and checksum idempotent; reject a conflicting replacement. Assemble only after the manifest matches the expected parts, then write a final object record and mark the session complete in one controlled workflow.

Keep the first implementation narrow enough to review line by line. Make inputs, outputs, authorization context, and failure behavior explicit instead of hiding them behind a convenience helper. The example should be safe to run with synthetic data, emit a correlation identifier, and leave a durable artifact that another engineer can inspect after the request has finished.

text
upload = create_session(size, checksum, expires_at)
part = put_part(upload.id, number, bytes, checksum)
complete(upload.id, manifest)

Verify and troubleshoot

Test dropped connections, reordered parts, duplicate retries, conflicting parts, expired sessions, missing final parts, oversized chunks, checksum mismatch, and a canceled upload. Resume after a browser restart and compare the final checksum with a trusted local calculation. Confirm incomplete bytes are never downloadable through the normal object path.

Use a small test matrix that covers the ordinary path, an empty or missing input, a duplicate request, a timeout, a permission failure, and a version mismatch. Assert both the response and the side effects. When a test fails, compare the observed transition with the model rather than adding a retry or widening a timeout without evidence.

Operations and recovery

Monitor active sessions, abandoned bytes, assembly duration, checksum failures, and part retry rates. Keep a bounded cleanup job and a user-visible resume window. During an incident, pause assembly while preserving accepted parts and provide a safe cancel path. Reconcile storage inventory with upload-session metadata to catch leaks.

Give the operator a bounded recovery action: replay a safe event, rebuild a derived view, rotate a credential, drain a queue, or roll back a compatible revision. Record the owner, retention period, alert threshold, and rollback condition next to the implementation. A runbook is useful only when it can be followed without reconstructing the design from production logs.

A practical decision guide

For a small service, prefer the design with the fewest hidden states that still meets the cloud infrastructure requirement. Add a managed dependency when it removes a failure mode you can measure, not simply because it is popular. Keep the interface replaceable by isolating provider-specific code behind a narrow adapter and by testing the behavior your users depend on.

Revisit the decision when traffic shape, data sensitivity, team ownership, or recovery objectives change. A design that is excellent for a single tenant or a low-volume internal tool can be the wrong design for a public multi-tenant path. Record the assumptions so the next change starts with evidence rather than folklore.

An implementation checklist

Before publishing a change related to build resumable uploads that survive bad networks, write down the input contract, authorization context, state transitions, limits, and user-visible errors. Identify the smallest synthetic dataset that demonstrates the normal path and the smallest dataset that demonstrates the dangerous path. Add a correlation ID to the example, make retries deliberate, and decide which artifacts can be retained for support without copying secrets or unnecessary personal data. This checklist is deliberately boring: repeatable release evidence is more valuable than a clever demo.

Use a disposable environment to exercise the implementation with realistic concurrency and a dependency failure. Compare the observed result with the contract, then record the measured latency, resource use, and recovery action. If a managed service or library is involved, pin its version and capture the relevant configuration. Ship behind a reversible change when the behavior is new, and schedule a follow-up review after real traffic reveals assumptions that a test fixture could not.

References and further reading

Use the object-storage provider's multipart-upload documentation, HTTP range and checksum guidance, and browser connection lifecycle APIs. Document maximum size, part size, expiration, checksum algorithm, and recovery behavior in the client contract.

Prefer primary protocol specifications, vendor security documentation, and measured behavior from a disposable environment. Read the failure and deprecation sections, not only the happy-path quick start. A short reference list attached to the code gives future maintainers a way to distinguish an intentional constraint from an accidental implementation detail.

Keep exploring