Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
There will be 4 APIs we need to support:
Upload of pasted text:
User_id is a unique identifier of a user, used as a path parameter.
POST v1/upload_text/{user_id}
{
post_id: UUID,
text: String,
createdAt: Timestamp,
textType: Enum, (code or text),
ttl: String
}
Generation of unique sharable URLs:
POST v1/generate_url/{user_id}
{
post_id: UUID
}
Retrieval of text blob using the URL:
GET v1/retrieve_text/{user_id}
{
url: String
}
Deletion of a post:
DELETE v1/delete_post/{user_id}
{
post_id: UUID
}
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
First, we need to define the data model for storing the pasted text metadata:
table pasted_text_metadata {
post_id: UUID,
user_id: UUID,
created_at: Timestamp,
ttl: string,
text_type: string (whether the stored text is a text or code snippet)
}
For this table, we build an index on post_id.
table pasted_text_url {
sharable_url: string,
post_id: UUID,
user_id: UUID,
}
For this table, we have 2 indexes, one is on sharable_url, and the other is on post_id.
The above 2 tables store the metadata for the pastebin text. For metadata data storage, we will use postgres, which is a highly available distributed SQL database with ACID properties.
For the object storage, we will have post_id as keys, while the text blob as the stored object.
For all the requests, we first go through a load balancer, which routes traffic to different servers using consistent hashing. The request then goes to an API gateway, which does authentication, and rate_limiting by user_id, IP address etc.
Now let me walk through the 4 flows:
For removing stale pasted text after TTLs, we will rely on the inherent TTL features on both redis and postgres.
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
For the high level design, I will cover several questions, with focus on how does the system handle heavy read and write traffic, with high availability and relatively low latency.
Assuming the service supports up to 1 billion MAU, the peak read QPS will be around 1500, and write QPS will be 1/3 of that.