Provider-based data persistence design #225
doodlewind
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A provider-based design is proposed here to synchronize workspace content via different data persistence backends.
The basic idea is to introduce
DocProvider
for syncing YDoc, andBlobProvider
for syncing binary contents (e.g., images, files, videos).YDoc and
DocProvider
A
DocProvider
is a regular YDoc provider. It doesn't have APIs to be explicitly called during the YDoc lifecycle. DocProviders may include:DebugDocProvider
- for playgroundIndexedDBDocProvider
- for webWebSocketDocProvider
- for web and clientFileSystemDocProvider
- for clientSQLiteDocProvider
- for clientMulti DocProviders with the same type (e.g., multi
WebSocketDocProvider
) can be attached to one YDoc, syncing the doc to different hosts.BlobStorage
andBlobProvider
A space (or page) may add multiple images to its content. These binary contents are defined as blobs and should be stored in a collaborative KV store. This store is called
BlobStorage
and has similar APIs aslocalStorage
. Generally, we should only work on theseBlobStorage
APIs for performing CRUD operations for blobs. ABlobStorage
can connect to multiBlobProvider
s, where the actual persistence operation happens.APIs for
BlobStorage
:storage.addProvider()
storage.removeProvider()
storage.providers
storage.blobs
storage.synced
storage.onChange(event)
storage.get(id): Promise<BlobURL>
storage.set(file): Promise<BlobId>
storage.delete(id): Promise<void>
storage.clear(id): Promise<void>
APIs for underlying
BlobProvider
:Different types of providers may include:
DebugBlobProvider
- for playgroundIndexedDBBlobProvider
- for webBucketBlobProvider
- for web and clientFileSystemBlobProvider
- for clientSQLiteBlobProvider
- for clientAs an example, after a user opens his workspace in the Web version from Affine Cloud, if the workspace hasn't been opened locally before, these are what's going to happen:
IndexedDBDocProvider
andWebSocketDocProvider
are initialized for syncing YDoc.IndexedDBBlobProvider
andBucketBlobProvider
are initialized (and connected toBlobStorage
) for syncing images.During this process, the
onChange
callback on the BlobStorage instance will be called once a new image is loaded.Other providers
We may have
AwarenessProvider
andNotificationProvider
in the future, but they don't have top priorities.Beta Was this translation helpful? Give feedback.
All reactions