hardSystem Design

How would you design a file storage service like Dropbox?

873 views
01

Understand the problem

Outline file storage.

file-storage
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

Content-hash chunk dedup
Run Playground
import hashlib

store = {}    # content-addressed blocks: hash -> bytes (S3 in production)

def put_file(data, chunk_size=4):
    manifest = []
    for i in range(0, len(data), chunk_size):
        c = data[i:i + chunk_size]
        h = hashlib.sha256(c).hexdigest()[:8]
        if h not in store:                 # only upload NEW blocks (dedupe)
            store[h] = c
            print("upload", h, repr(c))
        else:
            print("skip (already stored)", h)
        manifest.append(h)
    return manifest                        # file = ordered list of chunk hashes

v1 = put_file(b"hello world data")
print("--- edit the end, re-sync ---")
v2 = put_file(b"hello world DATA")          # leading chunks unchanged -> reused
print("v1:", v1)
print("v2:", v2)
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.