File and Object Storage: Block vs File vs Object, Direct Multipart Uploads, Metadata Consistency, and Upload Security
System Design series · Part 3 Storage basics (5 of 8)
- SQL vs NoSQL: Choose a Database by Access Pattern, Not by Buzzword
- Indexes and B+Trees: From Disk Pages to Composite Indexes, Index-Defeating Queries, and Keyset Pagination
- B-Tree vs LSM-Tree: In-Place Updates vs Append-Only, and the Write, Read, and Space Amplification Trade-offs
- Transactions and Isolation Levels: MVCC, Lost Updates, Write Skew, and Spring Transaction Boundaries
- File and Object Storage: Block vs File vs Object, Direct Multipart Uploads, Metadata Consistency, and Upload Security
- Bloom Filters and HyperLogLog: Trading a Little Error for a Lot of Memory, and What to Do When Someone Games the Estimate
- Full-Text Search and Inverted Indexes: Chinese Tokenization, BM25 Ranking, Index Sync, and the Authorization Boundary of Search
- Geohash and Geospatial Indexes: Cell Boundaries in Nearby Search, Redis GEO, and How Distance Leaks Location
System Design series Part 3-5 | Previous: Transactions and Isolation Levels | Next: Bloom Filters and HyperLogLog | Series map
Read first: Part 2-1 Vertical Scaling, Horizontal Scaling, and Stateless Services, Part 3-4 Transactions and Isolation Levels.
Scenario and problem
Now that the talk is over, the platform opens three kinds of uploads: speakers upload their recordings (1–5 GB each) and handout PDFs, and members upload profile pictures. The first version has Spring Boot receive the file as a MultipartFile, save it to /data/uploads on the application server, and write the path to the database. Problems show up quickly:
- Once the service scales out to three machines, a file that machine A received cannot be read on machine B
- A speaker uploads a 5 GB recording over a 50 Mbps uplink: 5 × 10⁹ × 8 ÷ (50 × 10⁶) ≈ 800 seconds, so one Tomcat thread is tied up for 13 minutes. Tomcat allows at most 200 threads by default; with a few dozen speakers uploading at once, regular API calls start to queue
- The Wi-Fi drops at 90%, and the only option is to upload the whole file again from the start
- Someone treats the database as a file cabinet and switches to BLOBs: large files crowd the buffer pool, backups grow from 20 minutes to 3 hours, and replica lag spikes
- A security scan finds that someone uploaded a “profile picture” with a
.pngextension whose content is actually HTML
- A has the file, B cannot read itSpring Boot receives the file and saves it to /data/uploads. Once the service scales out to several machines, a request that lands on B finds no such file on B's disk.
- One recording ties up one threadA speaker uploads a 5 GB recording over a 50 Mbps uplink. It takes 800 seconds, and one Tomcat thread is tied up for 13 minutes. Tomcat allows at most 200 by default; with a few dozen speakers uploading at once, regular API calls start to queue.
- Disconnected at 90%The Wi-Fi drops at 90%. Everything uploaded so far is wasted, and the only option is to start over.
- The database as a file cabinetSomeone switches to storing files as BLOBs. Large files fill the buffer pool, backups grow from 20 minutes to 3 hours, and replica lag spikes too.
- HTML with a .png extensionA security scan finds a "profile picture" with a .png extension whose content is actually HTML. If you accept a file by its extension alone, then when the browser opens it under the site's domain, the JavaScript inside can read the site's cookies.
The simplest approach and its limits
The stateless services post already gave the first step: put files in object storage (S3), have the server issue only a presigned URL, and let the browser PUT the file there directly, so the file’s bytes never pass through the application server. That solves problems 1, 2, and 4.
But a single PUT has its limits:
- A single
PUTis capped at 5 GiB: right at the upper limit of the recordings - No resume: if the connection drops, you start over
- No parallelism: one connection carries the whole file, so it cannot use all the bandwidth
The bigger headache is consistency: the file is in S3, the record is in the database, and the two share no transaction (the transactions in the transactions post only cover what happens inside the database). If the frontend finishes the upload but never reports back, S3 holds an object nobody knows about; if the database writes the record first and the upload fails, you are left with a row pointing at a file that does not exist.
Core mechanism
Three kinds of storage
| Block | File | Object | |
|---|---|---|---|
| Examples | Cloud disks (EBS), local SSDs | NFS, EFS | S3, GCS, MinIO |
| Access | The OS sees a disk and puts its own file system on it | A directory mounted over the network, POSIX operations | HTTP API, whole objects accessed by key |
| Modification | Read and write at any offset | Read and write at any offset, append, locks | Only overwrite the whole object |
| Shared by many machines | Usually attached to one machine at a time | Yes | Yes |
| Latency | Lowest | Medium | Highest (every access is an HTTP request) |
| Scalability | A single volume has a capacity limit | Medium | Practically unlimited |
| Good for | Databases, programs that need low-latency random reads and writes | Existing programs that need a shared directory | Images, video, documents, backups, log archives |
Why object storage can scale almost without limit
Object storage deliberately gives up many file system capabilities in exchange for scalability:
- A flat namespace: there are only buckets and keys, no real directories. The
/inmedia/2026/talk.mp4is just a character; the console uses prefixes to make it look like folders - Objects cannot be partially modified: you can only write or overwrite a whole object; there is no append and no file lock. This makes it easy to keep multiple copies of the same object consistent
- No rename: “moving a folder” actually copies every object one by one and then deletes it. It is not atomic, and with many objects it is slow and expensive
- Data is spread out redundantly: the most intuitive way is to keep several copies; large systems more often use erasure coding, which splits the data into k pieces and computes m parity pieces, so any m lost pieces can be rebuilt:
| Method | Storage cost | Pieces it can lose at once | Pieces read to repair one |
|---|---|---|---|
| 3 replicas | 3.0x | 2 | 1 |
| Reed–Solomon (6, 3) | 1.5x | 3 | 6 |
| Reed–Solomon (10, 4) | 1.4x | 4 | 10 |
Erasure coding gets higher fault tolerance in half the space, at the cost of reading more data and doing more computation during a repair. Ceph, MinIO, and HDFS 3 all support it; S3 does not disclose the scheme it uses internally and only commits to a durability level.
Consistency: S3 now provides strong read-after-write consistency for PUT and DELETE: once a write succeeds, an immediate read returns the new content. The claim you find online that “S3 is eventually consistent” describes how things were before December 2020. When two writes hit the same key at the same time, by default the later one overwrites the earlier one; if you need “create only if it does not exist”, add the If-None-Match: * condition, and the second write gets 412 Precondition Failed.
Request rate: S3 supports at least 3,500 writes (PUT/COPY/POST/DELETE) and 5,500 reads (GET/HEAD) per second per prefix, and there is no limit on the number of prefixes in a bucket, so when you need more throughput you spread keys across more prefixes. Scaling happens gradually: when traffic jumps suddenly you first get 503 Slow Down, so pair it with retries and backoff.
Multipart upload
A large file is split into parts that are uploaded separately, then combined into one object once they are all in:
sequenceDiagram
participant B as Browser
participant A as API
participant S as S3
participant D as Database
B->>A: 1. I want to upload a 4.2 GB mp4
A->>S: CreateMultipartUpload
A->>D: Record PENDING
A-->>B: uploadId + a presigned URL for each part
par Parallel upload
B->>S: PUT part 1
B->>S: PUT part 2
B->>S: PUT part N
end
B->>A: 2. Done uploading
A->>S: ListParts (go by the parts actually on S3)
A->>S: CompleteMultipartUpload
A->>D: Record UPLOADED
- Parts can be uploaded in parallel, and a failure means re-uploading only that one part
- Uploads can resume after a disconnect: the
uploadIdis still there, so finished parts do not need to be uploaded again - Limits: each part is 5 MiB to 5 GiB (the last part has no minimum), at most 10,000 parts, and a single object can be up to 48.8 TiB (the 5 TB often quoted in older material is out of date)
Part size is a trade-off: larger parts mean fewer requests; smaller parts mean less to re-upload after a single failure and more parallelism. Compute the part size from the object size:
package media;
/** Picks the part size within S3 multipart limits: each part 5 MiB to 5 GiB, at most 10,000 parts. */
public final class PartSizes {
static final long MIB = 1024L * 1024;
static final long MAX_PART = 5L * 1024 * MIB;
static final int MAX_PARTS = 10_000;
static final long DEFAULT_PART = 64 * MIB;
private PartSizes() {
}
public static long partSize(long objectBytes) {
long needed = (objectBytes + MAX_PARTS - 1) / MAX_PARTS; // at least this big, so there are no more than 10,000 parts
long size = Math.max(DEFAULT_PART, needed);
size = (size + MIB - 1) / MIB * MIB; // round up to a whole MiB
if (size > MAX_PART) {
throw new IllegalArgumentException("exceeds the single-object limit");
}
return size;
}
public static int partCount(long objectBytes, long partSize) {
return (int) ((objectBytes + partSize - 1) / partSize);
}
public static void main(String[] args) {
long gib = 1024 * MIB;
long[] sizes = {200 * MIB, 5 * gib, 1024 * gib, 10 * 1024 * gib, 10_000 * 5 * gib, 49 * 1024 * gib};
String[] labels = {"200 MiB", "5 GiB", "1 TiB", "10 TiB", "48.8 TiB", "49 TiB"};
for (int i = 0; i < sizes.length; i++) {
try {
long part = partSize(sizes[i]);
System.out.printf("%-9s part %,6d MiB × %,6d parts%n", labels[i], part / MIB, partCount(sizes[i], part));
} catch (IllegalArgumentException e) {
System.out.printf("%-9s %s%n", labels[i], e.getMessage());
}
}
}
}200 MiB part 64 MiB × 4 parts
5 GiB part 64 MiB × 80 parts
1 TiB part 105 MiB × 9,987 parts
10 TiB part 1,049 MiB × 9,996 parts
48.8 TiB part 5,120 MiB × 10,000 parts
49 TiB exceeds the single-object limit64 MiB is enough for ordinary files; only objects larger than about 625 GiB need bigger parts to stay within 10,000.
Unfinished multipart uploads keep taking up space: uploaded parts are kept and billed until you complete or abort the upload, and they do not show up when you list objects. Always set a lifecycle rule that cleans them up automatically.
Consistency between the database and the files
The file and the record live in two systems and cannot be wrapped in one transaction, so use a state machine instead, which gives every kind of failure a clear way to clean up:
stateDiagram-v2
[*] --> PENDING: create multipart upload
PENDING --> UPLOADED: size check passes, complete succeeds
PENDING --> EXPIRED: not finished within 1 day
UPLOADED --> AVAILABLE: malware scan and format check pass
UPLOADED --> REJECTED: checks fail
AVAILABLE --> DELETED: user deletes it
- Only files in
AVAILABLEshow up in any query or download - The object exists but the record does not, or the record is stuck in
PENDING: the object is created with astate=pendingtag, which changes toavailableonly after it passes the checks; a lifecycle rule deletes objects still taggedpendingafter 1 day, and a scheduled job on the database side moves timed-outPENDINGrecords toEXPIRED - The record exists but the object does not: the record never reaches
AVAILABLE, so users never see it - Deletion: first change the record to
DELETEDso users stop seeing it immediately; then delete the object. If that fails it can be retried, and users are not affected
Comparing options
Where to put the files
| Local disk on the app server | Shared file system | Database BLOB | Object storage | |
|---|---|---|---|---|
| Horizontal scaling | No | Yes | Yes | Yes |
| Large files | Limited by one machine’s disk | Yes | Slow down the buffer pool, backups, and replication | Yes |
| Same transaction as business data | No | No | Yes | No, needs a state machine |
| Cost | Low | High | Highest (database storage is the most expensive) | Lowest |
| Good for | Temporary files | Existing programs that need POSIX operations | Small amounts of data, a few KB each, that must share a transaction with the data | Almost every file users upload |
Upload methods
| Through the app server | Presigned PUT |
Multipart + presigned | |
|---|---|---|---|
| Server load | Thread and bandwidth tied up the whole time | Only issuing URLs | Issuing URLs, complete |
| Max file size | Your choice | 5 GiB | 48.8 TiB |
| Resume, parallel | Build it yourself | No | Yes |
| Can the server inspect the content | During the upload | Only after the upload | Only after the upload |
| Good for | Small files that need immediate processing | Regular files under 100 MB | Large files, unstable networks |
In Java
1. The upload flow
Implement the flow above with AWS SDK for Java 2.x (2.59.7). The database records and the owner checks live in the service that calls this class; only the parts that talk to S3 are kept here:
package media;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.springframework.http.ContentDisposition;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.CompletedPart;
import software.amazon.awssdk.services.s3.model.Part;
import software.amazon.awssdk.services.s3.model.Tag;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
public class MediaUploadService {
static final long MAX_BYTES = 5L * 1024 * 1024 * 1024; // talk recordings: 5 GiB max
static final Duration UPLOAD_URL_TTL = Duration.ofMinutes(30);
static final Map<String, String> ALLOWED_TYPES = Map.of("video/mp4", "mp4", "application/pdf", "pdf");
private final S3Client s3;
private final S3Presigner presigner;
private final String bucket;
public MediaUploadService(S3Client s3, S3Presigner presigner, String bucket) {
this.s3 = s3;
this.presigner = presigner;
this.bucket = bucket;
}
public record StartedUpload(String key, String uploadId, long partSize, List<URL> partUrls) {}
/** Step 1: check the declared size and type, create the multipart upload, and issue an upload URL for each part. */
public StartedUpload start(long declaredBytes, String contentType) {
if (declaredBytes <= 0 || declaredBytes > MAX_BYTES) {
throw new IllegalArgumentException("file size out of range");
}
String extension = ALLOWED_TYPES.get(contentType);
if (extension == null) {
throw new IllegalArgumentException("unsupported file type");
}
String key = "media/" + UUID.randomUUID() + "." + extension; // the server generates the key
String uploadId = s3.createMultipartUpload(b -> b.bucket(bucket).key(key)
.contentType(contentType)
.tagging("state=pending")) // lifecycle cleans up objects that never finish the flow
.uploadId();
long partSize = PartSizes.partSize(declaredBytes);
List<URL> urls = new ArrayList<>();
for (int part = 1; part <= PartSizes.partCount(declaredBytes, partSize); part++) {
int partNumber = part;
urls.add(presigner.presignUploadPart(p -> p.signatureDuration(UPLOAD_URL_TTL)
.uploadPartRequest(u -> u.bucket(bucket).key(key).uploadId(uploadId).partNumber(partNumber)))
.url());
}
return new StartedUpload(key, uploadId, partSize, urls);
}
/** Step 2: do not trust the ETags and sizes the frontend reports; go by the parts that actually exist on S3. */
public void complete(String key, String uploadId, long declaredBytes) {
List<Part> parts = s3.listPartsPaginator(b -> b.bucket(bucket).key(key).uploadId(uploadId))
.parts().stream().toList();
long actualBytes = parts.stream().mapToLong(Part::size).sum();
if (actualBytes != declaredBytes) {
s3.abortMultipartUpload(b -> b.bucket(bucket).key(key).uploadId(uploadId));
throw new IllegalStateException("uploaded size does not match the declared size");
}
List<CompletedPart> completed = parts.stream()
.map(p -> CompletedPart.builder().partNumber(p.partNumber()).eTag(p.eTag()).build())
.toList();
s3.completeMultipartUpload(b -> b.bucket(bucket).key(key).uploadId(uploadId)
.multipartUpload(m -> m.parts(completed))
.ifNoneMatch("*")); // fail if an object with this key exists; never overwrite
}
/** Step 3: mark the object available only after the malware scan and format check pass. */
public void markAvailable(String key) {
s3.putObjectTagging(b -> b.bucket(bucket).key(key)
.tagging(t -> t.tagSet(Tag.builder().key("state").value("available").build())));
}
/** Downloads are always served as attachments, so the browser never opens them under our domain. */
public URL downloadUrl(String key, String originalFilename) {
String disposition = ContentDisposition.attachment()
.filename(originalFilename, StandardCharsets.UTF_8)
.build()
.toString();
return presigner.presignGetObject(p -> p.signatureDuration(Duration.ofMinutes(5))
.getObjectRequest(g -> g.bucket(bucket).key(key).responseContentDisposition(disposition)))
.url();
}
}start: size and type are checked before any URL is issued; the server generates the key from a UUID; each part gets one presigned URL, which can upload only to the givenuploadIdand part numbercomplete: a presigned URL cannot limit the actual size of each part, so before completing,ListPartsfetches the parts that really exist on S3, and their sum is compared with the declared size; on a mismatch the upload is aborted right away. The ETags also come fromListParts, so the frontend does not have to report them, and CORS does not need to expose theETagheaderifNoneMatch("*"): even if two flows accidentally end up with the same key, they cannot overwrite each other
2. Lifecycle rules
{
"Rules": [
{
"ID": "expire-unfinished-media",
"Status": "Enabled",
"Filter": { "Tag": { "Key": "state", "Value": "pending" } },
"Expiration": { "Days": 1 }
},
{
"ID": "abort-incomplete-multipart",
"Status": "Enabled",
"Filter": { "Prefix": "media/" },
"AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 1 }
}
]
}They have to be two separate rules: S3 does not allow AbortIncompleteMultipartUpload in a rule that filters by tag.
3. Downloads
downloadUrl has S3 respond with Content-Disposition: attachment, so the browser downloads the file instead of opening it. The original filename lives only in the database and goes into the header only at download time; Spring’s ContentDisposition handles the encoding of non-ASCII filenames:
attachment; filename="_3___.pdf"; filename*=UTF-8''%E7%AC%AC3%E5%A0%B4%E8%AC%9B%E7%BE%A9.pdffilename is an ASCII fallback for old browsers; filename* is the full UTF-8 filename. Public static assets (such as talk cover images) sit behind a CDN instead; see the CDN post for how.
Pitfalls and gotchas
- Assuming folders really exist: “renaming a folder” means a copy plus a delete for every object, so 100,000 objects take 200,000 requests, and a failure partway leaves the job half done
- Using object listing as a query:
ListObjectsV2returns at most 1,000 keys per call and cannot filter by metadata. A query like “all attachments for a given talk” needs the database - Traffic concentrated on one prefix: above a few thousand requests per second you get
503 Slow Down. Start keys with a UUID or another well-spread value, and retry 503s with backoff - No rule to clean up unfinished multipart uploads: the invisible parts keep getting billed
- Uploading large files with a single
PUT: anything over 5 GiB fails outright, and a disconnect near the limit costs the most - Relying on outdated material: “S3 is eventually consistent” and “a single object is at most 5 TB” are no longer true
- Concurrent writes to the same key: by default the later write overwrites the earlier one. If you need “create only once”, use
If-None-Match - Using object storage as a database: small data that changes often (counters, status) means rewriting the whole object every time, and every time is an HTTP request
Security
- Always generate keys on the server: if you use the user’s filename as the key, attackers can guess or overwrite other people’s files (for example by uploading a file named
avatars/1001.png), and special characters in filenames can also break later processing. The original filename lives only in the database and is used only inContent-Disposition - Do not trust the extension or
Content-Type: the client decides both, so look at the magic bytes at the start of the file to find the real format. For images, read the dimensions before deciding whether to decode: a PNG of a few hundred bytes can claim 50,000 × 50,000 pixels in its header and exhaust the server’s memory when decoded (a decompression bomb). The same goes for archives: limit the total size and the number of files when extracting:
package media;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Iterator;
import java.util.zip.CRC32;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
/** Basic checks on uploaded files: detect the real format from the header; for images, read the dimensions without decoding pixels. */
public final class UploadInspector {
enum Kind { PDF, PNG, JPEG, MP4, UNKNOWN }
static final long MAX_PIXELS = 25_000_000; // about 5000 × 5000
private UploadInspector() {
}
static Kind sniff(byte[] head) {
if (startsWith(head, 0, "%PDF-".getBytes(StandardCharsets.US_ASCII))) {
return Kind.PDF;
}
if (startsWith(head, 0, new byte[] {(byte) 0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n'})) {
return Kind.PNG;
}
if (startsWith(head, 0, new byte[] {(byte) 0xFF, (byte) 0xD8, (byte) 0xFF})) {
return Kind.JPEG;
}
if (startsWith(head, 4, "ftyp".getBytes(StandardCharsets.US_ASCII))) {
return Kind.MP4;
}
return Kind.UNKNOWN;
}
/** Reads only the width and height in the header, without allocating memory for pixels. */
static long[] dimensions(byte[] image) throws IOException {
try (ImageInputStream in = ImageIO.createImageInputStream(new ByteArrayInputStream(image))) {
Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
if (!readers.hasNext()) {
throw new IOException("unrecognized image format");
}
ImageReader reader = readers.next();
try {
reader.setInput(in, true, true);
return new long[] {reader.getWidth(0), reader.getHeight(0)};
} finally {
reader.dispose();
}
}
}
static String inspectAvatar(String filename, byte[] content) throws IOException {
Kind kind = sniff(Arrays.copyOf(content, Math.min(content.length, 16)));
if (kind != Kind.PNG && kind != Kind.JPEG) {
return filename + ": rejected, the extension says image but the content is " + kind;
}
long[] size = dimensions(content);
long pixels = size[0] * size[1];
if (pixels > MAX_PIXELS) {
return String.format("%s: rejected, claims %,d × %,d pixels, a full decode needs about %,.1f GiB of memory",
filename, size[0], size[1], pixels * 4 / 1024.0 / 1024 / 1024);
}
return String.format("%s: passed, %s %d × %d", filename, kind, size[0], size[1]);
}
public static void main(String[] args) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB), "png", out);
byte[] avatar = out.toByteArray();
byte[] disguised = "<html><script>alert(document.cookie)</script></html>".getBytes(StandardCharsets.UTF_8);
byte[] bomb = avatar.clone(); // change only the width and height in IHDR; the file is still a few hundred bytes
ByteBuffer.wrap(bomb, 16, 8).putInt(50_000).putInt(50_000);
CRC32 crc = new CRC32();
crc.update(bomb, 12, 4 + 13); // chunk type + IHDR data
ByteBuffer.wrap(bomb, 29, 4).putInt((int) crc.getValue());
System.out.println(inspectAvatar("avatar.png (" + avatar.length + " bytes)", avatar));
System.out.println(inspectAvatar("cute-cat.png", disguised));
System.out.println(inspectAvatar("huge.png (" + bomb.length + " bytes)", bomb));
}
private static boolean startsWith(byte[] data, int offset, byte[] prefix) {
return data.length >= offset + prefix.length
&& Arrays.equals(data, offset, offset + prefix.length, prefix, 0, prefix.length);
}
}avatar.png (91 bytes): passed, PNG 64 × 64
cute-cat.png: rejected, the extension says image but the content is UNKNOWN
huge.png (91 bytes): rejected, claims 50,000 × 50,000 pixels, a full decode needs about 9.3 GiB of memory- Serve user uploads from a separate domain: when a browser opens user-uploaded HTML or SVG under your domain, the JavaScript inside can read your site’s cookies and DOM (stored XSS). Serve user content from a different domain (not a subdomain that shares cookies), and add
Content-Disposition: attachmentandX-Content-Type-Options: nosniffto the responses - Open files up only after they pass the checks: a finished upload only means the file has arrived. It has to pass a malware scan (for example GuardDuty Malware Protection for S3 or ClamAV) and a format check before it moves to
AVAILABLE, which is also why the state machine needs theUPLOADEDstate - Keep buckets private and URLs short-lived: since April 2023, new buckets have Block Public Access turned on by default; do not turn it off for convenience. Serve public content through a CDN and allow only the CDN to read the bucket. Presigned URLs end up in browser history, logs, and the
Refererheader, so the shorter their lifetime, the better. Thecomplete,abort, and download APIs must also confirm that the upload record belongs to the current user; otherwise you have BOLA (Part 8)
When to use it, and when not to
- Object storage: images, video, documents, backups, log archives, data lakes; in other words, large unstructured data that is written once and read many times
- Shared file system: existing programs that must read and write through file paths, or that need partial modification or file locks
- Block storage: databases, and single-machine programs that need low-latency random reads and writes
- Database BLOB: only for very small data that must be in the same transaction as the business data
- Direct multipart upload: files of 100 MB or more, or unstable networks; for small files a single presigned
PUTis enough
References
- Irving Reed, Gustave Solomon, “Polynomial Codes over Certain Finite Fields”, Journal of SIAM, 1960
- Sage Weil et al., “Ceph: A Scalable, High-Performance Distributed File System”, OSDI 2006
- Amazon S3 User Guide — Amazon S3 multipart upload limits: https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html
- Amazon S3 User Guide — Best practices design patterns: optimizing Amazon S3 performance: https://docs.aws.amazon.com/AmazonS3/latest/userguide/optimizing-performance.html
- Amazon S3 User Guide — How to prevent object overwrites with conditional writes: https://docs.aws.amazon.com/AmazonS3/latest/userguide/conditional-writes.html
- Amazon S3 User Guide — Configuring a bucket lifecycle configuration to delete incomplete multipart uploads: https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpu-abort-incomplete-mpu-lifecycle-config.html
- Amazon S3 User Guide — Blocking public access to your Amazon S3 storage: https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html
- AWS SDK for Java 2.x — Work with Amazon S3 pre-signed URLs: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples-s3-presign.html
- RFC 6266 — Use of the Content-Disposition Header Field in HTTP; RFC 8187 — Indicating Character Encoding and Language for HTTP Header Field Parameters
- OWASP — File Upload Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html
- Further interactive diagrams: Dilum Sanjaya, System Design — an interactive course: https://designed-to-scale.vercel.app/
Comments