Functional Requirements:
Non-Functional Requirements:
Our services will be read-heavy, with significantly more read requests compared to new paste creations, following a 5:1 read-to-write ratio.
Traffic Estimates:
New Pastes per Second:
1M / (24 hours * 3600 seconds) ≈ 12 pastes/sec
Paste Reads per Second:
5M / (24 hours * 3600 seconds) ≈ 58 reads/sec
Storage Estimates:
1M * 10KB = 10GB/day
Total storage for 10 years:
10GB/day * 365 days/year * 10 years = 36TB
Total number of pastes in 10 years: 3.6 billion.
Key storage requirement using base64 encoding (64^6 ≈ 68.7 billion unique strings):
3.6B keys * 6 bytes/key = 22GB
Bandwidth Estimates:
12 pastes/sec * 10KB = 120KB/sec
58 reads/sec * 10KB = 0.6MB/sec
Memory Estimates:
0.2 * 5M * 10KB ≈ 10GB
We can use SOAP or REST APIs to provide the functionality of our service. Here are the definitions for the APIs to create, retrieve, and delete pastes:
API: addPaste
Parameters:
Returns: (string)
API: getPaste
Parameters:
Returns:
API: deletePaste
Parameters:
Returns:
We need two tables: one for storing information about the pastes and another for storing user data.
In this schema:
URLHash is the unique identifier for the shortened URL.ContentKey is a reference to an external object storing the paste contents. We'll discuss the external storage of paste contents later in the chapter.At a high level, our system needs an application layer to handle all read and write requests. This application layer will interact with a storage layer to store and retrieve data. We can segregate our storage layer into two parts: one for storing metadata related to each paste and user information, and another for storing the actual paste contents in object storage (such as Amazon S3). This separation allows us to scale these components individually.
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
a. Application Layer:
Our application layer will handle all incoming and outgoing requests. The application servers will communicate with the backend data store components to serve these requests.
Handling a Write Request:
Key Generation Service (KGS):
Single Point of Failure:
Key Caching:
Handling a Read Request:
b. Data Store Layer:
The datastore layer is divided into two components:
Metadata Database:
Object Storage:
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?