Key takeaways
- ✓A single PUT of a 2 GiB file, with the connection cut at 20 random points, sent 21.14 GiB in 21 requests: each cut threw away everything sent so far, so 19.14 GiB was sent again, 9.6 times the file.
- ✓Split into 32 parts of 64 MiB, the same file with the same 20 cuts sent 2.64 GiB and resent only 0.64 GiB, because a cut loses only what was sent of the one part in flight. It finished in 19 s, against 144 s for the single PUT, in one run on a busy laptop.
- ✓A presigned URL is signed with the server's secret key for one method, one file name and an expiry time. The store accepted the PUT of the signed file name (200) and refused the same signature for another file name, for a GET, and after it expired (each 403).
- ✓The database keeps a small metadata row per file, not the bytes: the lab's files table got one row per upload, and both stored objects downloaded back with the exact SHA-256 checksum of the original.
- ✓The store checks signatures only when it is configured to. Without an identity in its settings, SeaweedFS accepts any request, so the presigned-URL checks mean something only with that file set up.
A 2 GiB file went over a connection cut 20 times, on purpose, and one upload of the whole file sent 21.14 GiB. The same file in 64 MiB parts, with the same 20 cuts, resent 0.64 GiB. This chapter takes apart the difference, then the other half of big uploads: a presigned URL, which lets a browser upload straight to storage without ever holding the storage keys.
The examples come from Lab 11 (Search, Geo and Object Storage) of the system design labs, its upload script 04_uploads.py, Exercises 1 and 2 (the lab numbers its exercises inside each script), and its recorded results in data/results/04_uploads.json. The store is SeaweedFS, an open-source object store that speaks Amazon's S3 API (the standard HTTP interface for object stores) and runs in Docker on one laptop, not in the cloud. The setup is the same Apple M4 Max with Docker Desktop (16 virtual CPUs) as the earlier chapters. Sizes are binary: 1 GiB is 1,024 × 1,024 × 1,024 bytes, a little more than a gigabyte, and 1 MiB is 1,024 × 1,024 bytes. The lab's run took place on a busy machine (its load average was 19.9 at the end), so read the shapes, not the last digit.
Why blobs don't go through the app server
Big files belong in an object store: a place that keeps each file, called an object, under a name, its key, and reads and writes it over HTTP. Two HTTP verbs matter here: PUT writes an object, and GET reads one. The database keeps only a small row about each object: its key, its size, a SHA-256 checksum (a fingerprint of the bytes, so you can tell whether a copy is the same file), its number of parts, and how it was uploaded. The lab's files table holds exactly that.
The reason is cost. A database that stores the bytes gets bloated backups and replication, and every download ties up a database connection and memory. An object store is built for large blobs and scales on its own. The app server stays out of the data path: it decides who may upload and what the file is called, and the bytes flow to the store.
One PUT of the whole file
The lab makes the connection cuts itself. The upload code stops sending at a chosen byte and the request fails, so the cut is simulated by the client, not a real bad network. The 20 cut points are random byte offsets into the file, drawn from a fixed seed (a starting value for the random numbers, so the run repeats): numpy's default_rng(1). Both ways of uploading meet the same 20 offsets.
A single PUT has no way to resume. Each cut ends the request, and the next try starts again from byte zero. So 20 cuts mean 20 failed tries and one that gets through: 21 requests in all.
| Upload | Requests | GiB sent | GiB resent | Resent ÷ file | Time |
|---|---|---|---|---|---|
| single PUT | 21 | 21.14 | 19.14 | 957% | 144 s |
The arithmetic is simple. A cut at byte x resends the x bytes sent before it. The 20 cut points average 0.96 GiB into the file, not the half-file, 1 GiB, a random cut would average. Their sum is 19.14 GiB, which the run measured exactly. The lab's README predicts "20 × 1 GiB = 20 GiB" and measures 19.14, the same thing rounded.
In parts
A multipart upload splits the file into numbered parts. The lab uses 32 parts of 64 MiB, each about 67 million bytes. Each part gets its own presigned URL (below) and its own PUT. A request at the start creates the upload, and a request at the end asks the store to join the parts into one object.
If a part is cut, only that part is sent again. The lab's results:
| Upload | Requests | GiB sent | GiB resent | Resent ÷ file | Time |
|---|---|---|---|---|---|
| single PUT | 21 | 21.14 | 19.14 | 957% | 144 s |
| multipart, 64 MiB parts | 52 | 2.64 | 0.64 | 32% | 19 s |
The 52 requests are 32 parts plus the 20 resends; the create and join requests are not counted. A cut costs what was sent of the part in flight, which on average is half a part, 32 MiB. Twenty cuts make 640 MiB, which is 0.625 GiB. The cuts landed a bit past the middle of their parts (51% on average), so the measured 0.64 GiB is close to that prediction. The 20 cuts hit 16 different parts; four of them were cut twice and sent three times.
The run took 19 s against 144 s, about 7.5 times faster. The likely cause is that the multipart run sent eight times fewer bytes (2.64 GiB against 21.14), but the lab didn't separate that from other effects. It is one run on a busy laptop, and the parts went up one at a time, not in parallel.
Both stored objects were downloaded back and matched the original's SHA-256, and each upload got its row in the files table.
Cuts so far
20 of 20Cut 20 lands 0.06 GiB into the file. A single PUT loses the 0.06 GiB sent so far. In parts, it lands 0.055 GiB into part 1, which is the only part resent.
Resent as a share of the file: single 957%, multipart 32%. Recorded after 20 cuts: single 21.14 GiB sent (19.14 resent) in 144 s; multipart 2.64 GiB sent (0.64 resent) in 19 s.
Part size is the trade-off. Smaller parts waste less per cut but mean more requests. S3 allows parts of at least 5 MiB (except the last one) and at most 10,000 parts per upload, so a 2 GiB file could use parts from 5 MiB up. The lab tried one size, 64 MiB.
Presigned URLs
A browser should not hold your storage keys, and two gigabytes should not pass through your servers. So the server signs a URL with its secret key: this method, this file name, until this time. The signature is a code only that secret key can produce, and the client uses the URL as is. A presigned URL like that is how each part above was uploaded.
The lab's second exercise tests what the signature allows. It signed a PUT for a file named avatar.png, valid for 60 seconds, then tried four requests:
| Request | HTTP status |
|---|---|
| PUT to the signed file name | 200 (OK) |
| PUT to another file name with the same signature | 403 (forbidden) |
| GET (download) with the PUT signature | 403 |
| PUT after the URL expired (a separate URL, valid 1 s, sent 2 s later) | 403 |
The signature covers the method, the file name and the expiry. So you can hand the URL to a browser, and it can upload that one object, for a short time, and nothing else. The lab's README adds the other half: a presigned URL means nothing if the store doesn't check signatures. SeaweedFS without a configured identity accepts any request. The lab's s3/s3.json, the store's settings file, adds one, and only then do these 403s appear.
A PUT URL can't limit the size of the upload or the kind of content, since the user chooses the bytes. The lab's README suggests a presigned POST (a form-style upload that the server signs with a policy, such as a size range and a content type) for that, and checking the content after the upload.
The workflow the lab ran
- Make a 2 GiB file with a known SHA-256 (a fixed-seed random file, so the run repeats).
- Upload it as one PUT, cut 20 times, then once through. Record the bytes sent and the time.
- Upload it as 32 parts of 64 MiB, each cut resent as its part, then join the parts. Record the same numbers.
- Download both objects, compare their SHA-256 with the original, and insert one
filesrow for each. - Run the presigned checks in the table above.
Caveats
- One run, on a busy laptop. The 144 s and 19 s are single runs, and the 7.5× is one ratio of two of them. The bytes sent are the likely reason for the gap, but that was not isolated.
- The cuts are simulated. The client stops sending on purpose. Real drops come with timeouts and half-finished packets, which this test does not produce.
- Parts went up one at a time. The lab's README asks what 8 parallel parts would do to the bytes resent when a cut hits 8 in flight. That wasn't measured.
- A cut resends the whole part. Resuming in the middle of a part would resend less. The lab didn't test that.
- Not tested: the presigned POST policy, abandoned multipart uploads (their parts cost storage until the upload is completed or aborted, so a lifecycle rule should clean them up), and the real expiry of a presigned URL for a large upload. The big uploads used a one-hour URL; the checks used 60 seconds and 1 second.
- SeaweedFS is not AWS S3. It speaks the same API, which is what the code relies on, but a managed store adds its own limits and behavior.
Check your understanding
Try each question before opening its answer.
Why did a single PUT of 2 GiB, cut 20 times, send 21.14 GiB?
A single PUT can't resume. Each cut threw away everything sent so far, and the next try started from byte zero. So each cut resent the bytes before it: the 20 cut points, averaging 0.96 GiB into the file, sum to 19.14 GiB resent, on top of the one full upload that got through.
What does a multipart upload lose to a cut, and why is that much less?
Only what was sent of the one part in flight. Each part is its own request, so a cut loses the bytes of that part sent before the cut, on average half a part, 32 MiB. Twenty cuts cost 0.64 GiB, or 32% of the file, against 957% for the single PUT.
What can the holder of a presigned PUT URL do with it, and what can't they do?
They can PUT the one file name the server signed, within the expiry, which the lab's store accepted (200). The same signature for another file name, a GET, and a PUT after expiry were each refused (403). The signature covers the method, the file name and the expiry, so the URL can't do anything else.
Why is the database holding only a row per file, and what does the row prove?
The bytes stay in the object store, which is built for large blobs, so the database isn't bloated or tied up by downloads. The row keeps the metadata: key, size, the SHA-256 checksum, parts and method. The lab's check downloaded both stored objects and compared their SHA-256 with the original; both matched.
Quiz
1.A single PUT of the 2 GiB file was cut 20 times and sent 21.14 GiB. Why was 19.14 GiB of it sent again?
2.The same 20 cuts hit a multipart upload of 64 MiB parts. Why did it resend only 0.64 GiB?
3.A presigned URL was made for a PUT of avatar.png, valid 60 seconds. Which request does the store accept?
Next up: Chapter 23, a URL shortener: built, loaded to its target, and checked against the design written before measuring. It puts the earlier chapters' IDs, caching, replicas and load balancing into one service.