Google Docs is an online word processing tool that is part of Google's free, web-based Google Docs Editor package. It has many features and is a complex system. If you take a closer look at how it is built and how it works, you may realize that it is much more intricate than it appears at first glance. Without any much delay let’s see how Google Docs work :)
Google Docs is a large system with many features, including document storage, sharing, formatting, and editing. The system can be broken down into these main components:
It’s always convenient to have a high-level overview of the system we’re trying to build. One way to simplify a complex system is to divide it into smaller components. Let's take a look at these components:
Google Docs has a storage mechanism similar to an operating system, with concepts such as directories, files, and owners. A file object is a fundamental component of the system, and includes content, parent, owner, and additional metadata like creation date. The root directory has an empty parent, which represents the folder hierarchy.
Google Docs allows multiple users to collaborate on the same document, but how does it achieve this? There are two types of algorithms used for collaborative editing: Conflict-free Replicated Data Types (CRDTs) and Operational Transformation (OT).
Google Docs uses an event passing mechanism called operational transformation to maintain and synchronize a consistent state between users working on a shared document.
For example, if two users, Sam and Aditi, are working on the same document, which has an initial state "BC", and they both make changes to it. Their changes will be sent to the server along with their last revision. Specifically, if Aditi inserts the character "D" at position 2 and Sam inserts the character "A" at the beginning, the server will transform Aditi's change to be inserted at the 3rd index. The server keeps track of the complete revision history of each document, allowing each collaborator to edit the document.
The figure below shows how operational transformation works:
Google Docs allows you to invite collaborators and assign them various levels of permission, such as read-only or owner. However, for more precise access control, you can use Role-Based Access Control (RBAC). RBAC ensures that employees only have access to the information and resources needed to fulfill their specific job responsibilities, and cannot access information that is not relevant to their role. This helps to protect sensitive data and maintain network security.
In the RBAC model, access can be restricted to specific actions, such as reading, creating, or editing files, based on various variables including authorization, responsibility, and job expertise. This ensures that only those with the appropriate permissions can perform certain actions, which helps to protect sensitive data and critical applications. RBAC has several advantages, including:
Designing a collaborative document editing platform can be challenging due to several factors. One difficulty is in allowing multiple users to edit the same document without conflicting changes. Another challenge is ensuring that simultaneous edits are effectively merged without causing issues. Both of these issues require careful planning and design in order to provide a seamless and efficient collaboration experience for users.
Operational transformation is a technique used in Google Docs to solve the first problem of allowing multiple users to edit a document simultaneously. The second problem is solved by the collaborative protocol. When you open a Google document, code is running in two places: your web browser and the Google servers. The code that runs in your browser is called the client. The client processes all of your changes to the document before sending them to the server, and then processes changes made by other editors after receiving them from the server.
To effectively collaborate in Google Docs, each client must keep track of four pieces of information:
The server maintains three pieces of information:
By effectively using the information available to them, it is possible to design the client-server communication in a way that allows all editors to quickly process each other's updates in real-time. Let's examine how this is done in a document with a simple example.
Let’s look into actual flow by considering an example:
The above example concludes with Bob and John receiving and acknowledging John’s change, respectively. The server and both editors are staring at the same page at this point —Hello Google!
So this is how Google Docs work :)
To ensure the smooth functioning and high availability of our system, it is important to monitor and troubleshoot it by providing warnings when performance or availability decline. One way to do this is by integrating Google Cloud into our observability and alerting procedures.
Google Cloud services automatically provide observability data, such as metrics, logs, and trace data, which allows for a comprehensive view of the system. We can also use third-party monitoring, alerting, and notification solutions to transmit observability and event data for our Google Cloud services. This data can be extracted and integrated into our current reliability and alerting systems.
By combining these approaches, we can effectively monitor and troubleshoot our system to ensure it is running smoothly and efficiently.
In this blog post, we attempted to explain how Google Docs works. It can be challenging to design real-time products like Google Docs. We hope that by reading this article, you gained some insight into the inner workings of Google Docs and the considerations that must be made to ensure a seamless collaborative experience. If you have any thoughts or comments, please share them in the message section below.
Thanks to Suyash Namdeo for his contribution in creating the first version of this content. If you have any queries/doubts/feedback, please write us at email@example.com. Enjoy learning, Enjoy system design, Enjoy algorithms!
Subscribe to get well designed content on data structure and algorithms, machine learning, system design, object orientd programming and math.
©2023 Code Algorithms Pvt. Ltd.
All rights reserved.