WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Coding Interview Essentials · Understanding System Design · question 92 of 120

How would you design a global File Storage Service like Google Drive?

📕 Buy this interview preparation book: 120 Coding Interview Essentials questions & answers — PDF + EPUB for $5

Designing a global File Storage Service like Google Drive involves several factors. Let’s consider the business requirements and system requirements separately.

**1. Business Requirements:**

- Massive storage: A system needs to store billions of files.

- Fast access: The system needs to be able to quickly store and retrieve these files.

- Sharing: The system needs the ability to share files and folders, giving either read-only or read/write access to specific users.

- Realtime synchronization: The system should mirror any changes made to the file over all the devices of the user.

- Data consistency: All replicas of the files should offer the same view of the data.

**2. System Requirements:**

- Horizontally scalable: The system should be capable of scaling as the amount of data increases.

- High availability: All files should be available for access at any point in time.

- Data durability: The system should be robust against data loss.

- Security and privacy: The data should be securely stored, with sensitive data being encrypted.

**3. Key Design Considerations**

To build such a File Storage Service, we need to consider the following:

- File Metadata management

- File data and its version management

- File sharing and collaboration

- Resilient against failures

Here is a high-level breakdown of the system design:

**1. File Metadata Management:**

To store metadata of all files, Google Drive possibly uses Bigtable, a distributed storage system for managing structured data. Each file could be represented by an object containing:


$$\begin{aligned} \text{FileID} &: \text{Unique identifier of the file} \\ \text{FileName} &: \text{Name of the file} \\ \text{CreatedTime} &: \text{Creation timestamp} \\ \text{UpdatedTime} &: \text{Timestamp of the last update} \\ \text{Owner} &: \text{User who uploaded the file} \\ \text{Size} &: \text{Size of the file} \\ \text{ShareInfo} &: \text{Info about the users file is shared with} \\ \text{Location} &: \text{Location of the file in the user's directory structure}\end{aligned}$$

We can use consistent hashing for distribution of files among servers.

**2. File Data and Its Version Management:**

Google Drive uses another distributed storage system, Google Cloud Storage, to store the actual file data. Each file is divided into several chunks, and each chunk is replicated over multiple data stores for durability and availability.

Whenever a file gets updated, the changed chunks are versioned and stored as a new copy (like Copy-on-Write), while the old versions are still kept for some time.

**3. File Sharing and Collaboration:**

For file sharing, we need to store the sharing list, which contains users/groups the file shared with and their access level (read/write).

When multiple users edit the same file, to avoid write-write conflicts, a good approach can be to use the Operational Transformation algorithm. In this algorithm, two operations O1 and O2 are transformed in such a way that both achieve the desired effect even when applied simultaneously.

**4. Resilient Against Failures:**

To prevent any data loss, we can replicate the file data into multiple copies across different data centers. Further, we can use Global Transaction Identifier to ensure Atomicity and Consistency across various Write operations.

**Conclusion** There is a lot that goes into designing a large-scale distributed system like Google Drive and many trade-offs to consider. This is just one such design with a few possible trade-offs.

Keep in mind that designs can differ based on the specific use-cases and assumptions being made, and this is a high level, simplified design.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Coding Interview Essentials interview — then scores it.
📞 Practice Coding Interview Essentials — free 15 min
📕 Buy this interview preparation book: 120 Coding Interview Essentials questions & answers — PDF + EPUB for $5

All 120 Coding Interview Essentials questions · All topics