Question: Consider a distributed document editing system where multiple users can collaborate on a document. The document is stored in a distributed database, and each user
Consider a distributed document editing system where multiple users can collaborate on a document. The document is stored in a distributed database, and each user has their own local copy of the document.
The system uses Lamport's Logical Clock to timestamp events. Each user's document editor sends messages to the central server to update the document. The server assigns a Lamport timestamp to each incoming message to maintain a consistent order of events.
Now, imagine the following sequence of events involving two users, User A and User B:
User A opens their local document editor and starts editing the document. The editor sends a message to the server with Lamport timestamp
User B opens their local document editor and begins editing simultaneously with User A User Bs editor sends a message to the server with Lamport timestamp
The server receives both messages. However, due to network delays, the message from User B arrives at the server after the message from User A
User As editor sends another message to the server with Lamport timestamp to save the next set of edits
User Bs editor sends another message to the server with Lamport timestamp to save their next set of edits.
Now, write a code to ensure that the central server can correctly order and apply these edits to the shared document using Lamport's Logical Clock
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
