Linux File System, Distributed Cache (LLD part)
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-05-17
Problem Statement
Designing the core components of a Linux-like File System. The system must model files, directories, and support common file system operations with hierarchical directory structure.
Functional Requirements
•Support Files and Directories (tree hierarchy).
•File Operations: createFile(path), readFile(path), writeFile(path, content), deleteFile(path).
•Directory Operations: createDirectory(path), listDirectory(path), deleteDirectory(path).
•Support permissions (read, write, execute).
•Validate hierarchy (cannot add file to a non-existent directory).
Non-Functional Requirements
•Efficient lookup (O(depth) for path traversal).
•Extensible to support symbolic links or mount points in the future.
•Thread-safe operations for concurrent file access.
Design Hints
•Use a Composite Pattern for file/directory hierarchy (FileSystemNode as abstract base).
•File and Directory inherit from FileSystemNode.
•Use a FileSystem manager class to handle operations and path parsing.
•Optional: Use Command Pattern for undo/redo file operations.
Distributed Cache (LLD Part)
Design a Distributed Cache system (like Redis/Memcached) at the low-level design layer, focusing on cache internals and eviction policies.
Functional Requirements
•Support basic cache operations: put(key, value), get(key), delete(key).
•Handle cache capacity constraints with configurable eviction policies:
•LRU (Least Recently Used)
•LFU (Least Frequently Used)
•FIFO (First In First Out)
•Support time-to-live (TTL) expiration per key.
•Thread-safe access (multiple clients can read/write concurrently).
Non-Functional Requirements
•O(1) complexity for get() and put() operations.
•Clean, modular design for plugging in new eviction strategies.
•Extensible for a distributed setup (multiple nodes, replication, sharding).
Design Hints
•Core classes:
•Cache (interface for cache operations).
•InMemoryCache (implements Cache, stores data in hashmap + eviction policy).
•EvictionPolicy (strategy pattern).
•LRU, LFU, FIFO implementations.
•CacheEntry (holds key, value, TTL metadata).
•Use Strategy Pattern for eviction policies.
•Use Decorator Pattern for TTL handling.
•Optional: Use Observer Pattern for cache miss tracking/metrics.
✅ Both problem statements test class design, clean APIs, design patterns, and concurrency handling.