Design an in-memory cloud storage system
Company: Ramp
Role: Software Engineer
Category: System Design
Difficulty: hard
Interview Round: Take-home Project
Design and implement an in-memory cloud storage system that maps fully qualified file paths to file metadata (e.g., name and size). Do not use the real filesystem. Assume requests will not create collisions between file and directory names. Implement the following feature levels (passing earlier levels remains required at later levels):
Level 1 — Basic file ops
- bool AddFile(const std::string& name, int size): Add a new file path with size in bytes. Fail and return false if a file with the same path already exists.
- bool CopyFile(const std::string& name_from, const std::string& name_to): Copy the file at name_from to name_to. Fail if name_from does not exist or is not a file, or if name_to already exists. Return true on success, false otherwise.
- std::optional<int> GetFileSize(const std::string& name): Return the file size if the file exists; otherwise return std::nullopt.
Level 2 — File discovery
- Support finding files by matching path prefixes and by matching suffixes (e.g., extension). Define clear APIs and choose data structures to make these queries efficient. Describe the expected time and space complexity.
Level 3 — Users and capacity limits
- Add a user concept with per-user storage capacity limits (in bytes). Associate files with users and enforce limits on AddFile/CopyFile. Specify error handling and what each API returns when limits would be exceeded.
Level 4 — Compression support
- Support compressing and decompressing files. Define APIs to compress/decompress a file and update stored size accordingly. Clarify whether GetFileSize returns logical (uncompressed) size or physical (stored) size, and how capacity accounting works under compression.
General requirements
- Keep everything in-memory. Provide class and method interfaces, core data structures (e.g., maps/tries/indexes), and justify trade-offs. Concurrency handling is optional but discuss how you would make operations thread-safe if needed. Include a brief test strategy and example scenarios demonstrating the expected behavior.
Quick Answer: This interview question evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer for Design an in-memory cloud storage system states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.