Inside a blob store
hard 30 minHow a blob store is built: a gateway, a metadata service that knows where each piece is, data nodes that hold pieces, and background jobs that repair, move and delete.
See it run
Follow a blob from upload to deletion, lose some pieces, and get them back.
Operations
The life of a blob
Upload, store, replicate, serve and clean up.
Step 1 of 8
Upload request
Upload: request
The client asks the gateway, with size and type.
Step 1: Upload request
url = api.sign(user, key) # uploadfor part in split(file): put(url[part], part)pieces = encode(chunk) # storeplace(pieces, zones)metadata.commit(key, manifest)replicate_later(manifest) # replicatecdn.serve(key) # servecollect_garbage() # clean up- Protects
- Whole system
- Price
- Background jobs
- One server
- one disk failure from loss
Name the phase you are in: upload, store, replicate, serve, collect.
In the real world
The same inside a blob store doing real jobs. Pick one and step through it.
Detection, degraded reads, repair.
Step 1 of 4
Heartbeats stop
Wait for the grace time
Node 2 is silent.
Step 1: Heartbeats stop
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Name before bytes
criticalA reader follows the manifest to a chunk that is not there.
Wrongmetadata.commit(key, ids)store(chunks)Rightids = store(chunks)metadata.commit(key, ids)All pieces in one rack
criticalNine pieces behind one power supply are one failure.
Wrongplace(pieces, same_rack)Rightplace(pieces, spread="zone", max_per_zone=3)Deleting orphans at once
criticalA running upload looks like an orphan until its commit.
Wrongif not in_manifest(c): delete(c)Rightif orphan(c) and age(c) > GRACE: quarantine(c)Using the ETag as the id
majorTwo blobs with equal bytes can share an ETag. A copy would overwrite a record.
Wrongblob_id = response["ETag"]Rightblob_id = new_unique_id()
Interview tips
Memory trick: PUMP
- Presigned URL request
- Upload parts in parallel
- Monitor with tags
- Post the complete request
Memory trick: DICE
- Deduplication
- Intelligent tiering
- Compression
- Erasure coding
Draw it like this
- Gateway, then names above and bytes below.
- Background jobs dashed.
- Zones as boxes.
Expect these questions
- What if it crashes between the two writes?
- What does a rebuild read?
- Who deletes, and when?