Theme

Interactive diagram · architecture

Design Pastebin.com (or Bit.ly)

Design Pastebin.com (or Bit.ly) A client resolves Pastebin through DNS and can use a CDN. Requests pass through a load balancer and web servers to write and read APIs, an analytics service, a memory cache, SQL databases, and object storage. Design Pastebin.com (or Bit.ly) Diagram after donnemartin/system-design-primer · CC BY 4.0 Client DNS CDN Load Balancer Web Server Write API SQL WriteMaster–Slave ObjectStore 1 · Create a paste Read API Memory Cache SQL ReadReplicas 2 · View a paste Analytics SQLAnalytics 3 · Track analytics 4 · Delete expired pastes
✕

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.

✕

2 · View a paste

Read API checks the generated URL and fetches the paste contents. Cache and read replicas help scale the read-heavy path.

✕

3 · Track analytics

Web server logs feed analytics. MapReduce can turn those logs into hit counts without requiring realtime processing.

✕

4 · Delete expired pastes

The service scans for rows older than their expiration timestamp, then deletes them or marks them expired.

✕

Memory Cache

Step 2 · View a paste

What it is

An in-memory store for popular content.

Its job here

Read API checks it before the database. A cache miss goes to SQL Read Replicas.

Trade-off

The cache helps with uneven traffic and traffic spikes.

In the primer

Cache › Cache-aside →

✕

SQL Write Master–Slave

Step 1 · Create a paste

What it is

The SQL database for paste records and unique shortlinks.

Its job here

Write API checks it for a duplicate and saves the pastes record. It replicates changes to SQL Read Replicas.

Trade-off

More write scaling may need federation, sharding, denormalization, or SQL tuning.

In the primer

Database › Master-slave replication →

✕

Object Store

Step 1 · Create a paste

What it is

Managed storage for paste contents.

Its job here

Write API saves paste data here. Read API fetches contents from it after it finds the generated URL.

Examples

  • Amazon S3

Trade-off

Pastebin stores paste contents instead of an original unshortened URL.

In the primer

Database › Document store →

←/→ step · Space play/pause · R replay · Home/End jump

Detail · follows playback, or click any box or step to pin it

Click any box for an explanation, or use Next or Play to walk through the four steps.

1 · Create a paste

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.

2 · View a paste

Read API finds the generated URL and fetches paste contents.

The read path checks Memory Cache first, then SQL Read Replicas and Object Store.

3 · Track analytics

MapReduce turns Web Server logs into page hit counts.

Analytics writes the resulting counts to SQL Analytics.

4 · Delete expired pastes

Expired records are found by their expiration timestamp.

The service deletes the entries or marks them expired.