Amazon S3 (Simple Storage Service) is a distributed object storage system designed to store and retrieve large amounts of data reliably over a network.

Why Do We Need Object Storage?
Imagine you're building an application that generates millions of photos, videos, PDFs, emails, and sensor readings. You need a reliable way to store and retrieve all this data.
The first thought might be to use a database. However, traditional relational databases are primarily designed to manage structured data, relationships, and queries. Although they can store large files as binary data, using them to manage massive volumes of large files can increase storage costs, database load, backup times, and resource contention with business-critical queries.
Next, you consider a traditional file system. It can store files of any format, but your application must manage file paths, directories, naming conventions, and filesystem operations. As the number of files grows, managing their organization and access becomes increasingly complex.
This is where object storage comes in. Instead of organizing data around files and directories, object storage treats each piece of data as an independent object containing three components: the actual data, metadata describing it, and a unique identifier.
Applications interact with objects through a simple RESTful API using operations such as PUT to upload,
GET to retrieve, and DELETE to remove data. The storage system manages the underlying storage implementation.
By separating file storage from database operations and providing a consistent API for accessing data, object storage offers a practical way to manage massive volumes of diverse, unstructured data.
How Object Storage Works in a Distributed System?
In a single-machine object storage system, all objects are stored on one machine's disk. But what happens when the amount of data grows beyond its storage capacity, or the machine cannot handle the incoming requests?
Considering you're building a service like Amazon S3, millions of users upload photos, videos, documents, and backups every day. As the data grows, a single machine becomes a bottleneck in terms of storage capacity, request throughput, and reliability. If the machine fails, the stored data may also become unavailable or lost.
To overcome these limitations, we build a distributed object storage system that spreads data across multiple machines. Each machine contributes storage capacity and processing power, allowing the system to handle growing volumes of data and requests.
However, distributing data introduces new challenges: deciding which machine should store an object, locating it when requested, and ensuring it remains available when a machine fails.
The system handles these complexities internally while exposing a single, unified API to clients. Applications can
continue using operations such as PUT, GET, and DELETE without knowing which machine physically stores
their objects.
What is an object?
Every object has three fundamental components:
- Data: The actual content, such as an image, video, document, or binary file.
- Metadata: Information describing the data, such as its size, content type, and creation date.
- Unique identifier: A key used to identify and retrieve the object.
Object storage uses a flat logical namespace in which each object is identified by a unique key. The application retrieves an object using its identifier.
When an application stores an object:
- The application provides a key, data, and optional metadata.
- The object store writes the data to disk.
- It records the key and corresponding storage location in its metadata index.
- It returns a success response.
When the application retrieves the object, the system looks up the key, locates the data, and reads the bytes.
Object storage is an abstraction and access model; it doesn't require a fundamentally different physical storage medium.
On a single machine, object storage doesn't automatically outperform file storage. In fact, if our object store uses a filesystem underneath, it introduces an additional abstraction layer that may add overhead.
Its main advantages at this level are simplicity of the logical interface, flexible metadata, and independence from the internal data format.
Suppose you're building a backend service that stores profile pictures, PDFs, and videos. With a traditional filesystem, your application might look like this:
File file = new File("/data/users/123/profile.jpg");
Files.write(file.toPath(), imageBytes);
byte[] data = Files.readAllBytes(file.toPath());
Your application needs to deal with filesystem paths, directory creation, filename collisions, and file management. Now imagine introducing an object storage interface:
objectStore.put("user-123-profile", imageBytes);
byte[] data = objectStore.get("user-123-profile");
The application interacts with objects using identifiers. It doesn't need to know how the storage implementation organizes the underlying files. The difference becomes more valuable as the application grows in complexity.
Consider this interface:
interface ObjectStore {
void put(String key, byte[] data);
byte[] get(String key);
void delete(String key);
}
The interface itself doesn't make the system faster or more durable. It makes the application less dependent on storage implementation details.
An object store may even use a filesystem internally.
As a general rule, if an object is over 10 MB and does not need SQL querying, it should be stored in a blob storage.
While blob storage solved the storage problem, it didn't solve the data transfer problem.
Provide object storage through a RESTful API-based interface.
Terminologies
Bucket: a logical container for objects. To upload data to S3, we must first create a bucket.
Object: An object is an individual piece of data we store in a bucket.
Functional requirements
-
Bucket creation
-
Object uploading and downloading
-
Object versioning
-
Listing objects in a bucket. It is similar to the AWS S3
lscommand. -
Uploading an object
-
Downloading an object
-
Object versioning and listing objects in the bucket.
Non-Functional requirements
- 100 PB of data.
- Data durability of 6 nines. Making three full copies of data gives us roughly six nines of data durability.
- Service availability is 4 nines.
- Storage efficiency reduces storage cost while maintaining a high degree of reliability and performance.
Sequence flow
- The API service forwards the object data to the data store.
- The data routing service generates a UUID for this object and queries the placement service for the data node to store this object. The placement service checks the virtual cluster map and returns the primary data node.
- The data routing service sends data directly to the primary data node together with its UUID.
- The primary data node saves the data locally and replicates it to two secondary data nodes. The primary node responds to the data routing service when data is successfully replicated to all secondary nodes.
- The UUID of the object is returned to the API service.
Server As a Proxy
The standard approach routes file bytes through your application servers. A client uploads a 2GB video, the API server receives it, then forwards it to blob storage. Same for downloads - blob storage sends to the API server, which forwards to the client. This works for small files, but breaks down as files get bigger.
We're forcing application servers to be dumb pipes. They add no value to the transfer, just latency and cost.
Direct uploads
we switch from uploading through our servers to uploading directly from the client to blob storage.
That 25GB upload failing at 99% means starting over from scratch. You lose visibility into upload progress since it bypasses your servers entirely. Your database shows "pending" while S3 might already have the complete file - or maybe it doesn't, and you can't tell without checking.
The seemingly simple act of moving bytes around has become a distributed systems problem with eventual consistency, progress tracking, and state synchronization challenges that the proxy approach never faced.
What are presigned URLs?
When a client wants to upload a file, instead of receiving the entire file, your server just receives a request for upload permission. You validate the user, check quotas, then generate a temporary upload URL. This URL encodes permission to upload one specific file to one specific location for a limited time - typically 15 minutes to 1 hour. This is called a presigned URL.
https://mybucket.s3.amazonaws.com/uploads/user123/video.mp4
?X-Amz-Algorithm=AWS4-HMAC-SHA256
&X-Amz-Credential=AKIAIOSFODNN7EXAMPLE%2F20240115%2Fus-east-1%2Fs3%2Faws4_requ
&X-Amz-Date=20240115T000000Z
&X-Amz-Expires=900
&X-Amz-SignedHeaders=host
&X-Amz-Signature=b2754f5b1c9d7c4b8d4f6e9a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9
The signature is a cryptographic hash of the request details (HTTP method, resource path, expiry time) combined with your secret key. When the client uploads to this URL, the storage service recalculates the same hash using its copy of your credentials. If the signatures match and the URL hasn't expired, the upload proceeds.
Since anyone with the URL can use it, you need to encode restrictions when generating them. Storage services let you add conditions that get validated during upload:
-
content-length-range: Set min/max file sizes to prevent someone uploading 10GB when you expect 10MB -
content-type: Ensure that profile picture endpoint only accepts images, not videos
These restrictions are baked into the signature. A URL generated for a 5MB image upload will be rejected if someone tries to upload a 500MB video.
The client performs a simple HTTP PUT to this URL with the file in the request body. From their perspective, they're uploading directly to storage. Your infrastructure never touches the bytes. That Sydney user uploads to Sydney's blob storage region at full speed while your servers in Virginia handle other requests.
Resumable Uploads for Large Files
Consider what happens when uploading really large files. Say a 5 GB video. With a typical network connection of 100 Mbps, it would take 429 seconds to upload. That's 7 minutes and 9 seconds. If the connection drops at 99%, you have to start over from scratch.
Fortunately, all major cloud providers solve this with chunked upload APIs. AWS S3 uses multipart uploads where each 5MB+ part gets its own presigned URL. Google Cloud Storage and Azure use single session URLs where you upload chunks with range headers to the same endpoint.
The client uploads these parts, tracking completion checksums returned by the storage service. These are just hashes of the uploaded data, so they're cheap to compute and verify. If the connection drops after uploading 60 of 100 parts, the client doesn't start over. Instead, it queries the storage API to see which parts already uploaded successfully, then resumes from part 61. The storage service maintains this state using the session ID (upload ID in S3, resumable upload URL in GCS, etc.).
Finally, after all parts upload, the client must call a completion endpoint with the list of part numbers and their checksums. The storage service then assembles these parts into the final object. Until this completion succeeds, you have parts in storage but no accessible file. Incomplete multipart uploads cost money, so lifecycle rules should clean them up after 24-48 hours.
State Synchronization Challenges
Moving your servers out of the critical path solves the bottleneck, but introduces a new class of problems around distributed state management.
The common pattern is to store file metadata in your database while the actual file lives in blob storage. This gives you the best of both worlds - fast queries on metadata with unlimited storage for the files themselves.
But this creates several problems:
-
Race conditions: The database might show 'completed' before the file actually exists in storage
-
Orphaned files: The client might crash after uploading but before notifying you, leaving files in storage with no database record
-
Malicious clients: Users could mark uploads as complete without actually uploading anything
-
Network failures: The completion notification might fail to reach your servers
Most blob storage services solve this with event notifications. When S3 receives a file, it publishes events through messaging services (like SNS/SQS) with details about what was uploaded. The event includes the object key - the same storage_key you stored in your database when generating the presigned URL. This lets you find the exact row to update.
How do you prevent abuse?
Implement a processing pipeline where uploads go into a quarantine bucket first. Run virus scans, content validation, and any other checks before moving files to the public bucket. This prevents someone from uploading malicious content and immediately sharing the link.
Set up automatic content analysis - image recognition to detect inappropriate content, file type validation to ensure a "photo" isn't actually an executable, size checks to prevent storage bombs. Only after these checks pass do you move the file to its final location and update the database status to "available."
This approach is much more robust than trying to detect abuse patterns in real-time. Even if someone bypasses your rate limiting and uploads malicious content, they can't use it until your systems approve it.
The processing delay also naturally throttles abuse - attackers can't immediately see if their upload worked, making automation harder.
Always include file size limits in the presigned URL conditions. Without these, someone could upload terabytes of data on a URL meant for a small image, exploding your storage costs.