Design a Recursive File-Search API
Last updated: August 11, 2026
Quick Overview
Design a recursive API for searching files within a directory and its subdirectories, handling various edge cases.
Amazon
August 11, 202612
0
112 solved
Design a recursive API for searching files within a directory and its subdirectories, handling various edge cases.
This question is typically asked during the technical interview round to evaluate a candidate's understanding of recursive algorithms and their ability to handle edge cases in software design. The interviewer is looking for a structured approach to problem-solving, as well as the candidate's ability to think critically about input validation and error handling.
What the Interviewer Expects
- Clearly define the API's input parameters and output format.
- Handle edge cases such as null inputs, empty directories, and non-existent files.
- Implement a recursive search mechanism effectively.
- Discuss potential performance implications and optimizations.
- Provide a clean and maintainable code structure.
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you optimize this search for large file systems?
- What would you change if the search needed to be case-insensitive?
- Can you explain how you would implement this in a multi-threaded environment?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
To design a recursive file-search API, we need to define the input parameters and expected outputs. The API should accept a directory path and a filename to search for. The expected outputs include er...
High-Level Design
The API will use a recursive function to traverse the directory tree. It will check each file and subdirectory in the given directory. If a file matches the search criteria, it will return the file pa...