Model an In-Memory File System With Instant Folder Size Queries

Last updated: November 29, 2026

Quick Overview

Design classes for an in-memory file system like a simplified OneDrive namespace: create directories, write files with sizes, delete files or folders, list a folder, and return the total size of any folder in constant time.

Microsoft
Software Engineering Fundamentals
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Design classes for an in-memory file system like a simplified OneDrive namespace: create directories, write files with sizes, delete files or folders, list a folder, and return the total size of any folder in constant time.

Microsoft onsites often include an object-oriented design question tied to a familiar product, and storage teams for OneDrive and SharePoint care about quotas and folder sizes. The interviewer checks class modeling (a common node type with file and directory subclasses), path handling, and the trade-off of maintaining aggregate sizes on write instead of recomputing on read.

What the Interviewer Expects
  • Models files and directories with a shared base type
  • Parses absolute paths and creates intermediate directories
  • Maintains subtree sizes incrementally so du is O(1)
  • Updates sizes correctly on overwrite and delete
  • Raises clear errors for invalid operations
Key Topics to Cover
object-oriented design
composite pattern
tree aggregation
path parsing
quota tracking
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you add a move or rename operation and keep sizes correct?
  • How would this change if the namespace were sharded across servers?
  • How would you support hard links that appear in two folders?
  • How would you make it thread-safe?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • mkdir(path) creates directories including missing parents.
  • write(path, size) creates or overwrites a file, creating parent directories.
  • delete(path) removes a file or a whole folder.
  • `ls...
High-Level Design

A composite tree: Node holds name, parent pointer, and size; File stores its own size; Directory adds a children dict and stores the total size of its subtree. Every write or delete ...


Submit Your Answer
Markdown supported