Part 3 of 8 · 2 min read
Growing the design
One server, then three tiers.
The book grows the design in steps.
Step 1: one server. A web server, a MySQL database for metadata, and a directory for files. Under it each user has a namespace, a root folder of their own. A file is identified by its namespace and its path.
The APIs. Three main ones. Upload a file, either as a simple upload for small files or a resumable upload for large ones (ask for a resumable link, send data while watching the state, and resume if cut). Download a file by path. List a file's revisions, by path and a limit. All need sign-in and use HTTPS.
Step 2: the disk fills. First fix: shard the files across servers by user id. This stops the fire, but a failed storage server still loses data.
Step 3: object storage. Use a service such as Amazon S3. It replicates data within a region and across regions, which guards against loss. A bucket is a named container, like a folder.
Step 4: split the rest.
- A load balancer in front of the web servers, so servers can be added or removed.
- The metadata database moved off the server, with replication and sharding.
- File storage in S3, replicated in two regions.
Now the web servers, the metadata and the files can each grow on their own.
client -> load balancer -> web / API servers -> metadata DB (replicated, sharded) + cache
'--> block servers ------> cloud storage (S3, two regions)
A worked example (made up). Without replication, one failed disk holding 1 TB loses 1 TB of customer files. With each block stored in two regions, one failure loses nothing, and the system keeps working from the other copy.
Resumable upload
A resumable upload sends a large file in a way that, after a break, can continue from where it stopped and need not start again.
Example: a 5 GB upload drops at 3 GB. The client asks the server how much arrived and sends only the last 2 GB.
Check yourself: 1. What fixes a full disk, and what does it not fix? 2. What does replication across regions protect against? 3. Why move the metadata database off the web server?