Skip to content

Commit 8eb8fd8

Browse files
committed
add data-structure and sync proposal
1 parent f86bc76 commit 8eb8fd8

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

docs/data-structure-and-sync.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Data structure & Sync
2+
3+
## Data per Space
4+
5+
Each space has multiple `Nodes`. Each `Node` can either be an `Entity` or a `Triple` in indicating a relationship between two `Entities`.
6+
7+
## Proposal
8+
9+
Each `Node` is a small CRDT document by itself and the content of the node is derived from the Yjs document.
10+
11+
This would allow to setup an event log per space. There can be 3 kinds of operations:
12+
13+
- set
14+
- delete
15+
16+
### Operations
17+
18+
#### Set
19+
20+
```json
21+
{
22+
"spaceId": "abc",
23+
"nodeId": "xyz",
24+
"type": "set",
25+
"content": "base64 encoded yjs update"
26+
}
27+
```
28+
29+
#### Delete
30+
31+
```json
32+
{
33+
"spaceId": "abc",
34+
"nodeId": "xyz",
35+
"type": "delete"
36+
}
37+
```
38+
39+
### Rules
40+
41+
- `delete` always wins over `set`
42+
- `set` updates must contain a commutative operation (CRDT update)
43+
44+
Therefor no conflicts can occur.
45+
46+
### Syncing
47+
48+
With a single sync server we could rely on an ordered event log per space managed by the server.
49+
50+
To make sure we can sync even when switching sync server we should create a structure that allows to sync in a decentralized fashion. Merkel-search-trees seem to be a good fit for this.
51+
52+
#### Merkel-search-trees
53+
54+
- https://inria.hal.science/hal-02303490/document
55+
- https://github.com/domodwyer/merkle-search-tree
56+
57+
#### End-to-End Encryption
58+
59+
The actual content should be encrypted. Therefor we want a structure like this:
60+
61+
```json
62+
{
63+
"spaceId": "abc",
64+
"nodeId": "xyz",
65+
"ciphertext": "base64", // contains the type and content in case it's a `set`
66+
"nonce": "base64",
67+
"commitment": "base64", // needed?
68+
"signature": "base64"
69+
}
70+
```
71+
72+
For the Merke-search-tree we probably would use the hash of the whole structure above.
73+
74+
### Downsides
75+
76+
- Currently doesn't support any kind of access control inside a space
77+
- Doesn't allow to sync only a part of a space

0 commit comments

Comments
 (0)