LESSON 13.4
Deduplication, deletion and cost
Storing identical bytes once with content hashes and chunking, deleting safely when blobs are shared, and estimating what storage and egress really cost.
6 min read
Object storage makes keeping bytes easy. At scale, three questions decide the bill and the risk: are you storing the same bytes many times, can you delete safely, and what does moving data cost?
Content-addressed blobs
If the blob's key is a hash of its content (say SHA-256), identical files map to the same key. On upload, the client sends the hash first; if the server already has it, the upload is skipped entirely and only a metadata row is added. This is how Dropbox, Git and container registries avoid storing the same data repeatedly.
Chunking
Whole-file hashes help with exact copies. Editing a big file still re-uploads all of it. Splitting files into chunks of a few megabytes, each stored and hashed separately, means only changed chunks move.
- Fixed-size chunks are simple, but inserting a byte near the start shifts every boundary and changes every chunk.
- Content-defined chunking picks boundaries where a rolling hash of the last few bytes matches a pattern. Boundaries move with the content, so an insert changes only the nearby chunks.
A file is then a list of chunk hashes, and two versions of the file share most of their chunks.
Deleting shared data
Sharing makes deletion a garbage-collection problem. A user's delete removes their metadata; the bytes can go only when nothing references them.
Reference counting
- Frees space promptly
- Counts drift on bugs or partial failures
Pick it when: Moderate scale with careful transactional updates.
Mark and sweep
- Self-correcting; recomputes the truth
- Scans all metadata periodically
Pick it when: Large stores; often run alongside reference counts as a safety net.
Always add a grace period (days) before deleting bytes, so an upload whose metadata isn't written yet, or a restore from trash, still finds its blob. Legal holds and retention rules may also forbid deletion for a time.
What it costs
Storage is cheap; moving it is not. Rough public-cloud list prices:
- Standard object storage
- about $23 per TB stored
- Infrequent-access class
- about $12.50 per TB, plus a per-GB retrieval fee
- Archive class
- about $1-4 per TB, hours to retrieve
- Internet egress
- about $50-90 per TB served
- CDN egress at volume
- often well under internet egress
For a media app, serving each stored byte a few times a month costs more than storing it. That's why CDNs, caching, efficient formats and lifecycle rules (move old data to cheaper classes) matter more than squeezing storage itself.
Try it
Multi-device File Sync HLD
Design chunked uploads and dedupe for a sync service.