retrystorm · Learn · Interview practice · Glossary · Components

Home › Learn › Object Storage

Chapter 22 · Data · 20 min

Object Storage

Give large files a home of their own: object storage, links instead of proxies, and what every request and byte costs.

Inkwell's pictures are everywhere now: profile pictures, attachments, cover images. They all come out of the database, through the app servers, and the database's network has been full since morning. The database team won't buy bigger machines just to serve pictures.

Large files and small rows want different homes. A database is built for many small rows; files of a megabyte or more fill its network and its disks. Object storage is built for files, and moving them there takes the weight off every server they used to pass through.

Files don't belong in the database

Every picture served out of the database leaves through the database's network card, then through an app server's. At a megabyte a picture, a few hundred views a second fill a medium server's card, and everything else on those servers waits behind them. The files also bloat the database itself: its disks fill, its backups crawl, and its memory caches pictures instead of the rows that make pages fast.

DataWhere it belongs
Notes, users, prices: small rows read and changed oftena database
Pictures, attachments, exports: large files written once, read many timesobject storage

Object storage

Object storage keeps files, called objects, in buckets, each under its own name. There's nothing to size: no tiers, replicas or partitions, and it serves as many requests and as many bytes as you send it, up to a limit per key prefix (on S3, about 3 500 writes and 5 500 reads a second for each prefix). It's durable, too, so a stored file stays stored.

The price is speed. Each request takes tens of milliseconds, and the slowest few in a hundred 100 to 200 ms, slower than a typical indexed database lookup.

Off the servers

Instead of passing a file on, the app hands the client a link to fetch it from storage. The database keeps only a small row for each file: its key in the bucket and metadata such as its size and owner.

Paying per request and per byte

Object storage bills every request: about $0.40 per million reads and $5 per million writes. It also bills every byte it sends to readers, its egress, at about $0.09 per GB. A thousand views a second of 1 MB pictures is 3.6 million reads an hour, about $1.50, and 3 600 GB of egress, over $300. The egress is the bill. A CDN in front answers the popular files from its edges, so only its misses reach storage, but it bills every request it answers, about $1 per million, and every byte it sends, about $0.085 per GB.

Uploads

The client asks the app for a presigned URL, a short-lived signed link for one upload, then sends the file straight to the bucket. Private files are read the same way, through a signed link for one download. On the canvas, connect writers to both the app and the storage: the app issues the presigned URL, so without a connection to the servers, uploads are refused.

Big files fail midway. A multipart upload sends a file in parts, so a lost part can be sent again on its own. The lab sends one in three parts and loses the second. Compare starting over with sending only what is missing.

In the wild

The ideas in this chapter, and where you'll meet them in real systems and interviews:

IdeaWhere you'll meet it
Object storageAmazon S3, Google Cloud Storage, Azure Blob Storage
Presigned URLsS3 presigned URLs, Google Cloud Storage signed URLs
A CDN in frontAmazon CloudFront in front of S3

Your practice

Inkwell's pictures are everywhere now, about 1 MB each and a thousand views a second, and they're served out of the database, whose network has been full all morning. Notes fail along with them, and the database won't get bigger. Give the pictures a home of their own, so pages are fast and nothing fails.

Key takeaways

  • Large files belong in object storage, small rows read often in a database.
  • Object storage has nothing to size, but each request takes tens of milliseconds.
  • Give the client a link, so files never cross the app servers.
  • Every request and every byte sent is billed; at this size the bill is egress, and a CDN barely changes it.
  • Uploads ask the app for a presigned URL, then go straight to the bucket.

Read first

  • The Edge
  • Bandwidth

Practise it

  • Pictures Everywhere: A megabyte per picture, a thousand pictures a second, and a database that won't get bigger. Take the pictures off the servers.

Terms

  • Egress: The bytes a service sends out to readers, and what the cloud charges for them.
  • Multipart upload: Sending a big file in parts, so a lost part is sent again on its own instead of the whole file.
  • Object storage: Stores files (objects) in buckets, with no sizing, priced per request and per byte.
  • Presigned URL: A short-lived link that lets a client upload or download one object directly.
AI system design mock interview · About · Contact · Privacy · Terms of use