GOAT EngineerPreparing your learning space…

System Design · Practice problem · Easy

Accept Large Uploads Without Melting Your Servers

Send large files straight to object storage with a short-lived presigned URL, not through your servers, because every byte through a server uses its network line. Build both here and run them under traffic.

Easy means one bottleneck to find. You solve it on a canvas that runs your design. The canvas needs JavaScript; everything on this page works without it.

What is the situation?

People upload videos to your app, and each file is 100 MB. An upload takes three calls. The app asks POST /uploads for permission, sends the file with PUT /files/:id, and then tells you with POST /uploads/:id/done so the file can appear in the customer's library. Two stores are already on your canvas: Files, an Object Store where every file must end up, and the Uploads table, a Database where every finished upload must be recorded. On a normal day 100 uploads a second arrive, each making its three calls in order. Design the path for those calls so that uploads stay quick and the bill stays under budget. Here is the fact that matters. The hardware table counts small requests, and a file is a different kind of load, because it holds a server's network line while its bytes cross that server. Each server has one line, shared by everything it is working on, and files cross it one after another. An App Server's line moves 10 Gbps, which is 12.5 of these files a second, and an API Gateway's or a Worker's moves the same. A Load Balancer's line moves 100 Gbps. An Object Store and a Database have no line limit here. A CDN here keeps copies for readers and does not pass an upload on to storage. The Object Store charges $0.40 per million requests on top of its monthly price. A small request gives up after 2 seconds, and a file gives up after 30. A connection carries every API unless you choose which ones it carries, so choose when the Client has more than one connection.

What must your design do?

  • A request to start an upload is answered within 200 ms at the 99th percentile, and at least 99.9% of them are served.
  • A file is stored within 2 seconds at the 99th percentile, counting only the time on your side.
  • Every file reaches Files.
  • Every finished upload is recorded in the Uploads table.
  • The system costs $1,100 a month or less.

What does Run test?

Run works without an account. It checks your design against 2 tests you can read before you start:

  • A normal day. 100 uploads a second for 40 seconds, each making its three calls in order.
  • A lunchtime rush. From second 10 to second 20, uploads rose by half, to 150 a second.

What does Submit add?

Submit needs an account. It runs 2 more tests you cannot read in advance, and stops at the first one your design fails, showing what happened and why. Passing every test, or giving up, unlocks the written solution.

Which parts can you use?

Already on your canvas: Files, Uploads table.

  • Load Balancer: about 50,003 a second, $18 a month each
  • API Gateway: about 20,000 a second, $35 a month each
  • App Server: about 2,000 a second, $45 a month each
  • Object Store: about 50,000 a second, $15 a month each
  • Database: about 5,000 a second, $120 a month each

Every connection takes 1 ms, and the budget is $1,100 a month.

What does this problem leave out?

  • The signed URL itself: who may have one, how long it lasts and what it allows. A Client connected straight to an Object Store stands in for it, and nothing checks the permission.
  • Who is allowed to call what. A real phone must never hold your database password, but nothing here stops you connecting a Client straight to a Database. That would pass here and be wrong in real life.
  • The size of a queue message. A real queue refuses a message of 100 MB, and nothing here does.
  • The customer's own connection. A file of 100 MB takes real time on a phone, and a slow customer holds any server in the path for all of that time. Every time here is the time on your side.
  • Uploads that break halfway, resuming, and sending a file in parts.
  • Paying to move data. Only machines and requests to the Object Store cost money here.
  • A network line on every other part. Only the servers have one here: a Load Balancer, an API Gateway, an App Server, a Worker, a Waiting Room and a Connection Server. A file sent through an Outbox Relay or a Queue moves as if that part had no line.

Where does this problem fit?

Its category is Files & media: Move, sync and stream big blobs. It practises data modeling and reliability & ops.

For the whole system, read the interview breakdown Design Cloud File Storage (Dropbox, Drive).

See every practice problem.

By GOAT Engineer. Explore System Design · Privacy Policy · Contact.