Design a folder hierarchy for workspace files
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in Figma's system design round, last asked Jan 2021. It tests data modeling, transactions and trees.
A team workspace keeps file metadata in nested folders. Members list a folder, create files and folders, rename them, and move a file or a whole folder to another parent. Design the data model, the APIs and the consistency rules for this hierarchy. File contents, editing, full-text search, sharing rules and moves between workspaces are out of scope; an upstream service tells you the workspace and what the caller may do.
Requirements
- Functional: list a folder's direct children with stable pagination and enough metadata to draw a file browser; create a file or folder under a parent; rename a node; move a file or an entire folder subtree to a new parent.
- Every node has a stable ID that never changes on rename or move.
- Names are unique among one parent's direct children, compared case-insensitively.
- A move is atomic and must never create a cycle, leave a node without a parent, or make it appear under two parents.
- A create, rename or move that timed out can be retried without being applied twice.
- Non-functional: large workspaces with deep trees and folders holding many children; listing is far more frequent than moving.
Clarifying questions
- How large can a workspace get, in nodes and depth? Do we need to list a folder with a million children?
- Is a move of a big folder expected to be instant, or can it take a while?
- Should the listing show a consistent snapshot while others are moving things around?
- What does the client show for a name conflict: an error, or an automatic "name (2)"?
- Do we need the full path of a node often (breadcrumbs), and how fresh must it be?
What a strong answer covers
- A node table with
id,workspace_id,parent_id,name, a case-foldedname_key, type and timestamps, plus a unique index on(parent_id, name_key). - Listing ordered by a stable key such as
(name_key, id)with a cursor, so pages do not skip or repeat items when nodes are added. - Moves as a single change of
parent_id(O(1) for a whole subtree), with a cycle check that walks from the new parent up to the root inside the same transaction, and the locking or serialization that stops two concurrent moves from making a cycle together. - Idempotent mutations: a client request ID stored with the result, so a retry returns the first outcome.
- Breadcrumbs and paths: walking parent pointers versus storing materialized paths or a closure table, and the cost each puts on moves.
- Sharding by workspace, so every hierarchy operation stays on one database.
Follow-ups
- Two members move folder A into B and B into A at the same moment. Walk through what happens.
- Add "delete folder" with a trash and restore. What happens to name uniqueness?
- Clients keep a local copy of the tree. How do they get changes since their last sync?
Where it's asked
- Figma · System design · Last asked Jan 2021Design discussion; one or two rounds
What it tests
data modeling · transactions · trees
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
