KatInterview

Multi-Tenant File Vault with Per-User Limits and Compression

System DesignModel answer
HardModel answerSystem Designsystem-designstoragequotas

Last updated

Design a multi-user file storage backend that handles uploads, downloads and copies, enforces per-user space limits, and transparently compresses data, with durability, security and testing covered.

Build a Multi-Tenant File Vault

You are asked to design the backend for a file storage product shared by many customers. Each customer has a storage allowance determined by their plan. Walk through your design as you would in a system design discussion.

What the service must do

  1. File operations. Users can upload new files, download them, and duplicate them. Define the API surface. Explain what "duplicate" means in your system (a server-side reference copy, a full physical copy, or copy-on-write), and say how metadata and sharing permissions behave on the new file.
  2. Users and allowances. Operators can create users and assign each a plan with a maximum amount of storage. Explain how usage is measured, how the limit is enforced when an upload starts or finishes, and how duplicates and compressed data are counted.
  3. Compression. Files are compressed when stored and restored when read. Choose algorithms, decide where in the data path compression happens, say where the compression details are recorded, and discuss the trade-off between CPU, latency and space saved.
  4. Reliability and scale. Address durability, availability, horizontal scaling and consistency. Describe the main components (blob storage, metadata service, indexes), how data is partitioned and replicated, which background jobs exist, and how the system recovers from failures.
  5. Security and operations. Cover authentication, authorization and access control lists, audit logging, file versioning, and monitoring. Propose the API methods for each feature and outline how you would test the system.

What is expected

  • State your assumptions about scale (users, file counts, sizes, request rates) before designing.
  • Provide an API sketch, a data model, and a component diagram or description.
  • Justify key decisions and call out trade-offs and failure modes.
  • Finish with a test strategy.

Hints

Hint 1

Split files into immutable chunks identified by a content hash. This makes copies cheap (just new references), enables integrity checks, and makes compression decisions per chunk.

Hint 2

Decide what you charge users for: logical (uncompressed) bytes give predictable numbers, while physical bytes leak information about other users' data. Then use an atomic conditional update on a per-user counter, with a reservation at upload start and a settle step at completion.

Hint 3

Keep file bytes out of the metadata tier. Use a transactional, sharded metadata store for namespaces, versions, quotas and reference counts, and an immutable, erasure-coded blob store underneath. Add background jobs for garbage collection, scrubbing, quota reconciliation and recompression of cold data.