retrystorm · Learn · Interview practice · Glossary · Components

Home › Interview practice › Pictures Everywhere

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.

Inkwell's pictures are everywhere now: profile pictures, attachments, cover images, about 1 MB each, and readers view a thousand of them a second. They're served by the app servers out of the database, whose network card has been full since the morning. Notes fail along with them. The database team won't buy bigger machines just to serve pictures.

What it does

  • Notes: users read and save notes, 2 KB each, through the app servers and the database.
  • Pictures: readers view pictures, about 1 MB each, and writers sometimes upload a new one. There are 50 000 of them, a few far more popular than the rest.

Workload

3 500 rps for 15 seconds: notes are 70% of requests, pictures 30%.

How to build it

The app servers and the database are fixed. Notes have to go through them. Pictures can go anywhere that stores them: the database, object storage, and a CDN in front of either.

Object storage
Reads$0.40 per million
Writes$5 per million
Bandwidthno limit

Every byte sent to a reader is billed as egress: $0.09 per GB from storage or the servers, $0.085 per GB from a CDN's edge, which also bills $1 per million requests.

  1. Connect notes to the load balancer, then the app servers, then the database.
  2. Run it with pictures going the same way, and look at the database's network.
  3. Give the pictures a home of their own. Uploads need a presigned URL from the app servers: connect pictures to the load balancer as well.

Part of Chapter 22: Object Storage.

About · Contact · Privacy · Terms of use