Bugpit

Lessons › From one user to millions

Move files off your servers

A photo app: 36,000 req/s, and 8 in 10 are photos. Each photo sits on the disk of whichever server took the upload. Move them somewhere every server can reach.

Play this level

Free with an account. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

A file on one server's disk is a trap. The other servers can't see it, and if that server dies the file dies with it. You can't add or replace servers freely while they hold your files.

Object storage, such as Amazon S3, keeps whole files in one shared place. You fetch a file by name, every server sees the same copy, and S3 is designed for 99.999999999% durability.

A CDN can fetch straight from storage, so photos stop passing through your app servers. Wire the CDN to storage, not the servers: if a server still fetches the file, it still does the work.

S3 serves at least 5,500 reads per second per prefix (the folder part of a file's name). Past that, spread files across more prefixes.

This level counts reads only. Uploads aren't simulated.

What you have to achieve

36,000 requests a second at the busiest hour, 2% of them writes and 80% static files.

What you learn

Photos now outlive any server. Look at the numbers though: p99 got slower, because S3 takes about 100 ms to start answering, and the whole bill barely moved. Teams don't choose object storage for speed. They choose it so servers can come and go without losing a file.

Check yourself

Why move photos from server disks to object storage?

Show the answer

Every server sees the same files, and they outlive any server. A file on one server's disk is lost with that server. Teams pick object storage for durability, not speed.

Where should the CDN fetch photos from?

Show the answer

Straight from object storage. If an app server still fetches the file, it still does the work. Wire the CDN to storage.

Try it yourself

More in From one user to millions

← CDN, queues and no single point of failure Survive a crash →