> ## Documentation Index
> Fetch the complete documentation index at: https://superdoc-caio-pizzol-sd-docs-snippet-typecheck-2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Storage

Storage depends on how your users edit.

For real-time collaboration, store the Yjs document state. That is the live
source of truth. A DOCX file can seed an empty room, and you can export DOCX
snapshots whenever you need Word interop, downloads, audit records, or pinned
versions.

For single-user or check-in/check-out flows, store DOCX versions directly.

## Storage approaches

| Collaboration level         | Approach     | Canonical store        | When changes are stored          |
| --------------------------- | ------------ | ---------------------- | -------------------------------- |
| [High](#high-collaboration) | Yjs/CRDT     | Yjs update or snapshot | Continuously on the backend      |
| [Low](#low-collaboration)   | Check in/out | DOCX binary            | When the user saves or checks in |

### High collaboration

For real-time, multi-user collaboration, each client connects to a
[real-time collaboration service](/editor/collaboration/overview). Only Yjs
updates move through that service. The collaboration server merges those
updates and stores the current Yjs state.

<Info>
  **Complexity: medium**: Requires a server-side [Yjs service](/guides/collaboration/self-hosted-overview)
</Info>

**How it works:**

* The first DOCX can seed an empty room.
* After that, the Yjs document is canonical.
* Each edit is sent as a Yjs update over WebSocket.
* The server stores Yjs updates or periodic Yjs snapshots.
* SuperDoc exports a fresh DOCX from the current Yjs-backed editor state when you need a file.

```typescript theme={null}
import * as Y from "yjs";

async function loadYdoc(documentId: string) {
  const ydoc = new Y.Doc();
  const update = await storage.get(`ydocs/${documentId}.bin`);

  if (update) {
    Y.applyUpdate(ydoc, new Uint8Array(update));
  }

  return ydoc;
}

async function saveYdoc(documentId: string, ydoc: Y.Doc) {
  const update = Y.encodeStateAsUpdate(ydoc);
  await storage.put(`ydocs/${documentId}.bin`, Buffer.from(update));
}
```

The Yjs document carries the document body, package parts, media, comments, and
document metadata needed for SuperDoc to rebuild the editor state.

### DOCX archive snapshots

DOCX exports are still useful in real-time collaboration. They are just not the
live collaboration store.

Use DOCX exports for:

* User downloads
* Word or Microsoft 365 workflows
* Audit snapshots
* Version pinning
* Legal review packages
* Backup and restore workflows

```typescript theme={null}
const blob = await superdoc.export({
  triggerDownload: false,
  isFinalDoc: true,
});

await storage.put(`versions/${documentId}/${versionId}.docx`, blob);
```

### Low collaboration

For scenarios where one user edits at a time, use a locking flow. Users check
out a document, edit it, and save or check it back in.

<Info>
  **Complexity: low**: Requires storing and querying document lock state
</Info>

**How it works:**

* The active user opens a DOCX.
* Your app prevents other users from editing the same document.
* On save or check-in, export a DOCX and upload it to your backend.

<Steps>
  <Step title="Create a version ID">
    Generate a unique identifier for the document version.

    ```
    document_revision1764976265.docx
    ```
  </Step>

  <Step title="Export the DOCX">
    Ask SuperDoc for the raw `Blob` so your app can upload it.

    ```typescript theme={null}
    const blob = await superdoc.export({
      triggerDownload: false,
      isFinalDoc: true,
    });
    ```
  </Step>

  <Step title="Store the version">
    Save the DOCX binary to your storage layer.

    ```
    s3://documents_bucket/versions/document_revision1764976265.docx
    ```
  </Step>

  <Step title="Save metadata">
    Store the version ID, storage path, author, and timestamp in your database.
  </Step>
</Steps>

## Export methods

The export APIs are covered in [Import/Export](/getting-started/import-export#export-options).

## Best practices

<CardGroup cols={2}>
  <Card title="Store Yjs for live rooms" icon="database">
    In real-time collaboration, store Yjs updates or snapshots as the canonical state.
  </Card>

  <Card title="Export DOCX snapshots" icon="file-output">
    Create DOCX versions for downloads, audit records, Word workflows, and pinned releases.
  </Card>

  <Card title="Keep version history" icon="clock">
    Store enough history to audit, compare, and recover documents.
  </Card>

  <Card title="Use durable storage" icon="cloud">
    Use S3, Google Cloud Storage, Azure Blob Storage, PostgreSQL, or your existing storage layer.
  </Card>
</CardGroup>
