1 · Create a paste
The client sends a create request through the web layer. Write API creates a unique URL, saves the record, stores the paste, and returns the URL.
Interactive diagram · architecture
The client sends a create request through the web layer. Write API creates a unique URL, saves the record, stores the paste, and returns the URL.
Read API checks the generated URL and fetches the paste contents. Cache and read replicas help scale the read-heavy path.
Web server logs feed analytics. MapReduce can turn those logs into hit counts without requiring realtime processing.
The service scans for rows older than their expiration timestamp, then deletes them or marks them expired.
The anonymous person using Pastebin.
It sends a create or get request. DNS gives it an address, then the request reaches the Load Balancer.
Following a short link should be fast.
Interview approach › Step 1: Outline use cases, constraints, and assumptions →
DNS points the Pastebin name to an address.
It receives the client lookup. The client then reaches the CDN or Load Balancer.
DNS is a separate part of the request path.
A CDN can serve content close to the client.
It receives requests after DNS. It can serve popular content before a request reaches the Load Balancer.
CDN caching is one of several places to cache.
A load balancer distributes requests across servers.
It receives client traffic and sends it to a Web Server. Multiple Web Servers improve availability.
A load balancer adds another component to operate.
A reverse proxy handles the public request.
It receives traffic from the Load Balancer. It forwards create requests to Write API and get requests to Read API.
Horizontal scaling adds more servers to manage.
The application endpoint that creates a paste.
It receives a create request from Web Server. It checks SQL Write Master–Slave for a duplicate URL, saves the record, and saves contents to Object Store.
SQL or NoSQL is a design trade-off for this lookup.
The application endpoint that retrieves a paste.
It receives a get request from Web Server. It checks Memory Cache, then SQL Read Replicas for the URL and Object Store for contents.
Cache misses still depend on the database.
A process that turns web server logs into hit counts.
It receives Web Server logs. It hands monthly page data to SQL Analytics.
Page view analytics do not need to be realtime.
An in-memory store for popular content.
Read API checks it before the database. A cache miss goes to SQL Read Replicas.
The cache helps with uneven traffic and traffic spikes.
The SQL database for paste records and unique shortlinks.
Write API checks it for a duplicate and saves the pastes record. It replicates changes to SQL Read Replicas.
More write scaling may need federation, sharding, denormalization, or SQL tuning.
Replicated SQL databases that serve reads.
They receive replicated writes from SQL Write Master–Slave. Read API uses them after a cache miss.
Replicas must not be bogged down with replicating writes.
A database for analytics results.
Analytics writes page hit counts here. It stores the results of processing Web Server logs.
Realtime analytics are not a requirement.
Managed storage for paste contents.
Write API saves paste data here. Read API fetches contents from it after it finds the generated URL.
Pastebin stores paste contents instead of an original unshortened URL.
Detail · follows playback, or click any box or step to pin it
Close · follow playbackClick any box for an explanation, or use Next or Play to walk through the four steps.
Write API creates the generated URL and saves the record and paste contents.
The request moves from Client to Web Server to Write API, SQL Write Master–Slave, and Object Store.
Read API finds the generated URL and fetches paste contents.
The read path checks Memory Cache first, then SQL Read Replicas and Object Store.
MapReduce turns Web Server logs into page hit counts.
Analytics writes the resulting counts to SQL Analytics.
Expired records are found by their expiration timestamp.
The service deletes the entries or marks them expired.