Notion is a very powerful piece of software that seamlessly integrates note-taking, knowledge base and task management. Notion is very convenient to use. It breaks down the way traditional note-taking software combines content by breaking up the content of a document into blocks and being able to drag and combine those blocks in a Lego-like fashion, making it very flexible to use. In this article, we’ll talk about how Notion handles data collaboration.

The document structure

Before we get into python data collaboration, we need to understand the python document structure. Notion document structures are made up of blocks that can be nested to form a tree. Blocks come in various types, such as pages, text, images, code blocks, and so on. Blocks are also extremely simple to use, just drag and drop with the mouse and rearrange their positions at will.< span style = “box-sizing: border-box; color: RGB (74, 74, 74); display: Block; line-height: 22px; font-size: 14px! Important; white-space: inherit! Important;”

{
    "3c4b5dc4-2ced-4346-b7c7-d7bcabbfff34": {"value": {"role":"read_and_write"."value": {"id":"3c4b5dc4-2ced-4346-b7c7-d7bcabbfff34"."version":481."type":"page"."content": ["9b6281c8-e546-4929-9242-0be3e8b61908"."29e945d6-3e2c-4c7a-bd1f-9d6dbdd0059b"."369797d8-8bf6-4794-9502-4ff1d4b9523d"]."format": {"page_icon":"🎀"
                },
                "permissions":[
                    {
                        "role":"editor"."type":"user_permission"."user_id":"115ca767-ba0d-48f7-a5ae-af1f91bcf44f"
                    },
                    {
                        "role":"read_and_write"."type":"public_permission"."added_timestamp":1644578023971}]."created_time":1639709100000."last_edited_time":1646054580000."parent_id":"83fcf30c-43b6-40b3-b0a5-964380955b82"."parent_table":"space"."alive":true."created_by_table":"notion_user"."created_by_id":"115ca767-ba0d-48f7-a5ae-af1f91bcf44f"."last_edited_by_table":"notion_user"."last_edited_by_id":"070b853c-1e8d-4a4d-95f2-7f130d94e5f0"."space_id":"83fcf30c-43b6-40b3-b0a5-964380955b82"}}},"9b6281c8-e546-4929-9242-0be3e8b61908": {"value": {"role":"read_and_write"."value": {"id":"9b6281c8-e546-4929-9242-0be3e8b61908"."version":125."type":"text"."properties": {"title":[
                        [
                            "1"]]},"created_time":1644822360000."last_edited_time":1646054520000."parent_id":"3c4b5dc4-2ced-4346-b7c7-d7bcabbfff34"."parent_table":"block"."alive":true."created_by_table":"notion_user"."created_by_id":"070b853c-1e8d-4a4d-95f2-7f130d94e5f0"."last_edited_by_table":"notion_user"."last_edited_by_id":"070b853c-1e8d-4a4d-95f2-7f130d94e5f0"."space_id":"83fcf30c-43b6-40b3-b0a5-964380955b82"}}},"29e945d6-3e2c-4c7a-bd1f-9d6dbdd0059b": {"value": {"role":"read_and_write"."value": {"id":"29e945d6-3e2c-4c7a-bd1f-9d6dbdd0059b"."version":8."type":"text"."properties": {"title":[
                        [
                            "2"]]},"created_time":1644924840000."last_edited_time":1646054580000."parent_id":"3c4b5dc4-2ced-4346-b7c7-d7bcabbfff34"."parent_table":"block"."alive":true."created_by_table":"notion_user"."created_by_id":"070b853c-1e8d-4a4d-95f2-7f130d94e5f0"."last_edited_by_table":"notion_user"."last_edited_by_id":"070b853c-1e8d-4a4d-95f2-7f130d94e5f0"."space_id":"83fcf30c-43b6-40b3-b0a5-964380955b82"}}}}Copy the code

Data together

Notion data collaboration is block-level collaboration. If multiple users modify different blocks in the same document at the same time, no conflict handling is required. If multiple users modify the same Block at the same time, conflict handling is required. Block collaboration is full update at the Block level, that is, the data written later directly overwrites the previous data. Therefore, compared with OT collaboration, Block collaboration does not require continuous version numbers. As long as the version number is larger, the Block state is newer, and the service layer only needs to obtain the latest Block data.

The role of the version number

In Block collaboration, the version number plays a weaker role than that in OT collaboration. The increment of the version number is completely controlled by the background. After the background receives a Block modification operation from the front-end and applies the operation, the version number of the Block is increased by 1. The role of version number in Block collaboration is mainly as follows:

  1. For the server to write data in optimistic lock mode;
  2. The front-end determines whether a Block is of the latest version. If not, the front-end immediately pulls the latest data from the server.

Data manipulation

< span style = “box-sizing: border-box; color: RGB (74, 74, 74); display: Block; line-height: 22px; font-size: 14px! Important; white-space: inherit! Important; word-break: inherit! Important;”

  • Set: Sets a set of properties for a Block and creates it if the Block or property does not exist. Usually used to create or overwrite a Block and update it.
  • Update: Updates some attributes of a Block. Update Block creation time, version, style, etc.
  • ListRemove: Removes a piece of data from an array property. It is usually used to remove a Block from the list of child nodes of its parent Block. It is also used to remove and then insert the child nodes when changing the order of the child nodes.
  • ListAfter: Inserts an item of data after an element in an array property value. Insert operation usually used to remove and then insert elements while dragging them.
  • ListBefore: Inserts a piece of data before an element in an array property value. < span style = “box-sizing: border-box; color: RGB (74, 74, 74); display: block; line-height: 22px; font-size: 14px! Important; white-space: inherit! Important;”

Anything a user edits is a combination of these atomic operations. The front-end doesn’t send atomic operations directly to the background, but rather a combination of these atomic operations. For example, dragging and dropping child elements of a Block is a combination of listRemove and listAfter.

Full synergy mode of operation

Notion: python creates a Notion that a user can modify a Block by changing its attributes, or changing the order of its children. When the contents of a Block are changed, the old value is replaced by the new value. Therefore, when multiple people edit the same Block at the same time, the overwrite update occurs, and the content written by the next person overwrites the content written by the previous person. Changing the order of the Block child nodes is to delete and insert the block. content array based on the Block ID of the specified child node. This operation is different from inserting and deleting the index array in OT collaboration. Therefore, when different people move children of the same Block, they can write directly without conflict. Because when you move a Block, you usually insert it in front of or behind an existing Block. When multiple people edit at the same time, the specified Block or blocks that need to be moved may be deleted. If the specified Block is removed, the Block to be moved is moved to the bottom of the parent element’s child node list. If the Block to be moved is removed, the move is invalid. In the background, all operations are processed in parallel. Operations between different blocks do not affect each other. Operations of the same Block use optimistic locks to prevent data loss. > < span style = “box-sizing: border-box! Important; color: RGB (74, 74, 74);

Data synergy sequence diagram

When receiving a collaborative message, the front end checks whether the version number of the Block in the collaborative message is greater than that of the corresponding local Block. If so, the server pulls the latest data of the Block. Below is a sequence diagram of collaborative data processed by the front end under several different editing operations.

When only user A edits A Block:When user A and user B edit A Block at the same time:User A deletes A Block and user B moves the Block:When user B moves Block1 to the back of Block2, the background will return a failure. When receiving an edit failure, the front end will directly pull the latest data to cover local data.

conclusion

Python/python/python/python/python/python/python/python/python/python/python/python/python/python/python/python But this simple collaborative processing of data can have an impact on the user experience.