VaultDrive
Self-hosted cloud drive in Python and Django/DRF with streaming SHA-256 content-addressed deduplication, immutable file versioning, atomic byte quotas, and subtree-scoped share links.

Overview
VaultDrive is an open-source, self-hosted file storage backend and workspace UI written in Python 3.12, Django 5.2, and Django REST Framework. It models cloud drive primitives—nested folders, multi-revision files, per-user byte quotas, and expiring share links—on top of content-addressed blob storage rather than mutable file paths.
Problem
Naive file-upload services commonly exhibit three failure modes as usage grows:
- Buffering entire uploads in memory causes heap spikes on large payloads, while quota checks executed outside database row locks leave orphaned files or allow concurrent requests to exceed limits.
- Storing revisions by filename duplicates identical bytes across repeated saves and makes rollbacks require full byte copies.
- Recursive serializer queries over nested folder hierarchies degrade into
O(N)SQL round-trips, and naive folder share tokens risk horizontal path traversal outside the shared directory subtree.
Approach and architecture
VaultDrive separates domain rules, transactional service orchestration, relational metadata (SQLite by default for local evaluation; PostgreSQL 16 in Docker), and a pluggable BlobStorage protocol implemented for both local atomic filesystem storage (LocalCASStorage) and Google Cloud Storage (GCSBlobStorage).
- Streaming content-addressed uploads:
HashingChunkStreamstreams incoming uploads in64 KiBchunks to temporary staging files while computing incremental SHA-256 digests, promoting verified blobs into shardedab/cd/<sha256>keys via atomicos.replaceor GCS object writes. - Immutable revisions and
O(1)rollback: EachDriveFiletracks ordered immutablev1..vNrevision records pointing to reference-counted CAS digests. Restoring an earlier revision updates the active pointer and creates an audit revision without copying underlying blob bytes; unreferenced blobs are reclaimed via reference-counted garbage collection. - Transactional quotas and cycle-safe trees: Upload mutations lock the owning
Userrow withselect_for_update()before committing quota deltas, rolling back unreferenced staged blobs on HTTP413. Folder moves acquire row locks to prevent directory cycles, andbuild_workspace_treeloads folder hierarchies in bulk and assembles trees in memory. - Subtree-scoped sharing: Public share links (
/s/<token>) support expiration timestamps and download caps, verifyingcollect_descendant_folder_idsso nested downloads cannot escape the shared folder boundary (403).
Engineering decisions and trade-offs
- Explicit service layer over ORM signals: All storage, quota, and garbage-collection side effects run inside explicit service transactions rather than Django signals, keeping failure rollback behavior deterministic and statically verifiable via AST import-layer checks.
- Reference-counted deduplication vs. lock contention: Serializing per-user quota updates with
select_for_update()trades maximum per-account parallel write throughput for strict byte-quota invariants without distributed coordination.
Evaluation and benchmarks
Local benchmark and evaluation scripts (make bench and make eval in the repository) measure three core invariants:
- Folder tree query complexity: Reduced a 121-folder workspace fetch from
242recursive SQL queries to2bulk queries (17.8xlower wall-clock latency in the local benchmark). - Upload memory footprint: Streaming
64 KiBchunks reduced peak Python heap allocation on a16 MiBupload from16,389 KiB(full-buffer read) to138 KiB. - CAS deduplication: Across a 36-upload multi-revision workload with repeated content, content-addressed storage achieved a
3.0xphysical storage reduction (66.7%fewer bytes stored).
Limitations
VaultDrive is an engineering prototype and reference implementation, not a multi-region production storage service. Single-request chunked streaming is implemented rather than resumable multipart uploads, and encryption-at-rest relies on the underlying disk or GCS bucket configuration rather than client-side envelope encryption.