Design system for generating random UUIDs for files in a directory
Problem Statement
π― Objective
Design a class-based system that scans a given directory, identifies all files, and assigns a unique, random UUID to each file.
The system should maintain a mapping between the file path and its UUID, ensuring no duplicates and allowing lookup or regeneration when required.
πΉ Context
In many systems (e.g., cloud storage, backup tools, or version control), files are assigned unique identifiers (UUIDs) for tracking, deduplication, or indexing.
You are required to design an in-memory or persistent UUID assignment module that can efficiently:
β Functional Requirements
βοΈ Non-Functional Requirements
Aspect with Description
Performance
Should efficiently traverse directories with thousands of files.
Scalability
Should be extendable to handle large file systems.
Extensibility
Should allow support for different ID generation strategies (e.g., UUIDv4, hash-based).
Reliability
Each file must have a consistent and retrievable identifier.
Maintainability
Classes should be modular and follow SOLID principles.
π§± Core Components / Classes
Class and Responsibility
FileScanner
Recursively scans directories and lists all files.
UUIDGenerator
Generates unique random UUIDs.
FileUUIDMapper
Maintains mapping between file paths and UUIDs.
UUIDPersistenceManager (optional)
Handles saving/loading mappings from a file or database.
Main / Client
Orchestrates the overall flow β scan, generate, map, persist.
π§Ύ Class Diagram (Text Representation)
1
2ββββββββββββββββββββββββββ
3β FileScanner β
4ββββββββββββββββββββββββββ
5β + scanDirectory(path): List<File> β
6βββββββββββββ¬βββββββββββββ
7 β
8 βΌ
9ββββββββββββββββββββββββββ
10β UUIDGenerator β
11ββββββββββββββββββββββββββ
12β + generateUUID(): str β
13βββββββββββββ¬βββββββββββββ
14 β
15 βΌ
16ββββββββββββββββββββββββββ
17β FileUUIDMapper β
18ββββββββββββββββββββββββββ
19β - fileToUUID: Map β
20ββββββββββββββββββββββββββ
21β + assignUUID(file): void β
22β + getUUID(file): str β
23β + regenerateUUID(file): void β
24β + getAllMappings(): Map β
25βββββββββββββ¬βββββββββββββ
26 β
27 βΌ
28ββββββββββββββββββββββββββ
29β UUIDPersistenceManager β
30ββββββββββββββββββββββββββ
31β + save(map): void β
32β + load(): Map β
33ββββββββββββββββββββββββββπ Workflow Example
βοΈ Example Flow
1
2Input Directory: /user/photos
3Files Found:
4 - photo1.jpg
5 - photo2.jpg
6 - holiday/photo3.jpg
7
8Generated UUIDs:
9 - photo1.jpg β 1a79a4d6-87e
10 - photo2.jpg β e4da3b7f-bb6
11 - holiday/photo3.jpg β 1679091c-5a8
12
13Mapping saved to: uuid_mapping.jsonπ§ Key Design Considerations
π§© Design Patterns Used
Pattern Role
Factory Method
To create UUID generators with different strategies.
Singleton
UUIDGenerator or FileUUIDMapper can be global instances.
Strategy Pattern
Different UUID generation strategies (UUIDv4, hash-based).
Repository Pattern
For persisting fileβUUID mappings.
π¬ Example Interview Prompt Summary
Design a system that scans a directory and assigns unique random UUIDs to each file.
The system should maintain mappings, support queries and regeneration, and handle large directories efficiently.
Discuss class design, extensibility, and error handling.
π Bonus Extension Ideas