KatInterview

Design a Multi-Tenant Namespace File Storage Service

System DesignModel answer
HardModel answerSystem Designdistributed-systemsstorageconcurrency

Last updated

Design a production file storage system with hierarchical namespaces, per-directory capacity limits, atomic duplicate renaming, and petabyte-scale content storage.

Scenario

You are the founding engineer at a legal document platform that needs to store files on behalf of thousands of enterprise customers. The product team has locked in two core API operations and a set of behavioral guarantees. Your job is to design the full system — from the API surface down to the bytes on disk.

API Semantics

addFile(path: String) → finalPath: String The path looks like "contracts/2024/acme/nda.pdf". The call must:

  • Create any missing intermediate directories in a single atomic operation.
  • Store the file at the leaf position.
  • Return the path that was actually used, which may differ from the input due to renaming.

list(path: String) → Entry[] Returns only the immediate children of the given directory, not a recursive listing.

Constraints and Behavioral Rules

  • Each directory may hold at most 5 entries, counting both files and subdirectories toward the limit.
  • An addFile that would breach the limit at any point along the path — including intermediate directories that need to be created — must be rejected entirely. No partial writes are acceptable.
  • If the leaf directory already contains a file or folder with the requested name, auto-rename the incoming file using OS-style numeric suffixes: report.pdf → report (1).pdf → report (2).pdf. Renaming does not exempt a file from the capacity check.
  • If the incoming name itself already carries a suffix like report (1).pdf and that name is also taken, find the next available number rather than nesting suffixes like report (1) (1).pdf.

What to Cover

Walk through your design in each of the following areas. Be concrete about trade-offs — where you have a choice, say which option you would pick and why.

  1. Overall architecture — identify the major components and how they interact.
  2. Metadata schema and store choice — relational vs. NoSQL, schema layout, indexing strategy.
  3. Concurrency control — how you enforce the 5-entry cap and the rename logic atomically when multiple clients write to the same directory simultaneously.
  4. Transaction boundaries and idempotency — where the commit point is, what happens on retry, and how bytes and metadata stay in sync.
  5. Content storage — content-addressed vs. location-addressed keys, how large files are uploaded (streaming, resumable), and how the object storage layer relates to the metadata layer.
  6. Consistency and failure modes — what can go wrong at each step and how the system recovers.
  7. Scalability — partitioning strategy, sharding keys, caching approach.
  8. Observability and rate limiting — key metrics, SLIs/SLOs, per-tenant quota enforcement.
  9. Data lifecycle — versioning, soft deletion, garbage collection of orphaned blobs.
  10. Security — authentication, authorization, path traversal prevention, encryption.

Assumed Scale

Design for roughly 10,000 tenants, 5 billion file nodes, 2,000 writes/second average with 20,000 reads/second at peak, files between 1 KB and 5 GB with a ~1 MB median, and total stored data in the petabyte range.

Hints

Hint 1

Start with the hardest correctness requirement: the 5-entry cap must hold even when two clients try to add a file to the same directory at the same millisecond. Which consistency primitive does your store need to provide, and what does that rule out?

Hint 2

The rename logic and the capacity check are not independent. Sketch out the exact sequence of operations inside one transaction — what rows you lock, in what order, and why that order prevents deadlocks across concurrent writers.

Hint 3

Metadata and bytes live in separate systems. Identify the exact commit point that makes a file visible to readers, then reason about what happens to the uploaded bytes if that commit never arrives.