Design cloud storage system evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
##### Question
Design and implement an in-memory cloud storage system that maps files to their metadata and supports:
add_file(name, size) / get_file_size(name) / delete_file(name)
get_n_largest(prefix, n) to return the n largest files with a given name prefix
multi-user support with add_user(user_id, capacity) and add_file_by(user_id, name, size) enforcing per-user capacity limits
merge_user(user_id1, user_id
2) combining users and their files
backup_user(user_id) and restore_user(user_id) for versioned backups that do not affect other users’ files or capacities
Quick Answer: Design cloud storage system evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
You are asked to design and implement an in-memory cloud storage system that maintains a mapping from file names to their metadata (size) and supports both single-user and multi-user operations.
Assumptions to make explicit:
File names are unique per user. The early single-user functions operate in a special default user namespace.
Sizes are non-negative integers (bytes). Capacity is the maximum total size (sum of file sizes) allowed per user.
For get_n_largest(prefix, n), return the n largest files across all users whose names start with prefix. Each result should identify the user.
merge_user(u1, u2) combines user2 into user1; user1 remains, user2 is deleted. Capacity becomes the sum of both users' capacities.
If file name collisions occur during merge, rename the incoming conflicting file(s) from user2 by appending a suffix to ensure uniqueness (e.g., "name (merged 2)").
backup_user and restore_user operate per user and do not affect other users' files or capacities.
Required API
Single-user (default namespace):
add_file(name, size)
get_file_size(name) → size or None
delete_file(name)
get_n_largest(prefix, n) → list of (user_id, name, size)