What happens when you upload a file to Amazon S3?ย
Before we dive into the design, letโs define some terms.
๐๐ฎ๐๐ค๐๐ญ. A logical container for objects. The bucket name is globally unique. To upload data to S3, we must first create a bucket.ย
๐๐๐ฃ๐๐๐ญ. An object is an individual piece of data we store in a bucket. It contains object data (also called payload) and metadata. Object data can be any sequence of bytes we want to store. The metadata is a set of name-value pairs that describe the object.
An S3 object consists of (Figure 1):
๐น Metadata. It is mutable and contains attributes such as ID, bucket name, object name, etc.
๐น Object data. It is immutable and contains the actual data.
In S3, an object resides in a bucket. The path looks like this: /bucket-to-share/script.txt. The bucket only has metadata. The object has metadata and the actual data.
The diagram below (Figure 2) illustrates how file uploading works. In this example, we first create a bucket named โbucket-to-shareโ and then upload a file named โscript.txtโ to the bucket.
1. The client sends an HTTP PUT request to create a bucket named โbucket-to-share.โ The request is forwarded to the API service.
2. The API service calls Identity and Access Management (IAM) to ensure the user is authorized and has WRITE permission.
3. The API service calls the metadata store to create an entry with the bucket info in the metadata database. Once the entry is created, a success message is returned to the client.
4. After the bucket is created, the client sends an HTTP PUT request to create an object named โscript.txtโ.ย
5. The API service verifies the userโs identity and ensures the user has WRITE permission on the bucket.
6. Once validation succeeds, the API service sends the object data in the HTTP PUT payload to the data store. The data store persists the payload as an object and returns the UUID of the object.
7. The API service calls the metadata store to create a new entry in the metadata database. It contains important metadata such as the object_id (UUID), bucket_id (which bucket the object belongs to), object_name, etc.
If you enjoyed this post, you might like our system design interview books as well.
SDI-vol1: https://amzn.to/3tK0qQn
SDI-vol2: https://amzn.to/37ZisW9
Thanks Alex for this article ! A question - how does API service know which instance of data service to connect to ? S3 is a widely used B2B system and operates at a large scale , I am sure there must be more complexity involved while handing the request to store/reterive the data.