Answer
Requirements: users upload a block of text and receive a unique link; pastes may be public or unlisted, can expire, and are read far more often than written. A paste can be up to a few megabytes.
- Write path: generate a unique key as in a URL shortener, store the content in object storage, and store metadata (key, owner, size, expiry time, storage location) in a database.
- Read path: look up the metadata, then serve the content from object storage through a CDN or cache, since popular pastes are read heavily.
- Expiry: a background job deletes expired pastes in batches, and every read checks the expiry time so that expired links never serve content.
- Trade-off: keeping content in object storage rather than the database costs an extra lookup, but keeps the database small and cheap to scale.
More in Web Services
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Design a URL shortener | Concept | Medium | Read the answer to Design a URL shortener | |||
| 2 | Design a pastebin service | Concept | Medium | Read the answer to Design a pastebin service | |||
| 3 | Design a rate limiter | Concept | Medium | Read the answer to Design a rate limiter | |||
| 4 | Design a notification system | Concept | Hard | Read the answer to Design a notification system |