List the key functional requirements for the system (Ask the AI for hints if stuck)...
Clients should upload and download the files
Clients should be notified upon file uploads
Clients should be able to list the uploaded files.
When clients is back online it's updates should be pushed to server.
Per user access control should be supported.
Encryption in transition and at rest.
Not in the scope:
List the key non-functional requirements (performance, scalability, reliability, etc.)...
Durability: 11 nines
Availability: 4 nines
Consistency: strong, ACID support
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
DAU: 10 mln
Read/write ratio 20:1
File size distribution:
20% - files from 0 to 1 mb
60% - files from 1 to 100 mb
20% files from 100 mb up to 10 GB (max allowed file size)
In order to calculate the total data volume of upload we need to get media of each file size range
1 mln uploads daily: 200k*500KB + 200k*5GB+50mb*600k = 100GB + 1PB + 30 TB => 1.1 PB daily
5 year data size projection approx 2 Exabyte
Read requests:
requests daily = 20* 1000 000 = 20 mln
read QPS = 20 000 000 / 100 000 = 200
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
/api/v1/files POST -> performs the actual upload process:
/api/v1/files/
/api/v1/files/
POST /api/v1/files/init -> {file_id, upload_session_id} (row created visible=false)
POST /api/v1/files/{file_id}/complete -> verifies all block hashes, then flips visible=true
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
Metadata DB: SOT of states of all the files stored in the block storage
Block service: responsible for upload/download of actual files and putting them to object storage.
Metadata service: responsible for registering upload in metadata DB and selecting primary block storage server upon upload.
Object storage: responsible for storing the files.
Notification service: responsible for communicating with the clients upon upcoming file updates to sync local and remote versions.
Load balancer: placement, block, notification services will be behind LB. Load balancer will be used for authentication as well. LB will perform per user rate limiting, and respond with 429 when too many requests happens.
Message queue (MQ): will be used for even streaming of file upload to trigger notifications and ensure durability of notifications.
Chunk validation:
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
SQL for Metadata DB
Block Table:
File Table:
User management is out of scope here.
No folder support
Transactions:
File record is created in the beginning of ifle upload with visible = False. keep visible = False through all blocks, and flip it once, in a single transaction with the final block insert, only after every block hash verifies.
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Orphan, incomplete session cleanup -> bckground worker that will do the GC.
Bit rot -> bckground scrub shouldb e handled by object storage provider.