Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syncstorage Postgres Backend

Tables Overview

TableDescription
user_collectionsPer-user metadata about each collection, including last_modified, record count, and total size
bsosStores Basic Storage Objects (BSOs) that represent synced records
collectionsMaps collection names to their stable IDs
batchesTemporary staging of BSOs in batch uploads
batch_bsosStores BSOs that are part of a batch, pending commit

User Collection Table

Stores per-user, per-collection metadata.

ColumnTypeDescription
user_idBIGINTThe user id (assigned by Tokenserver). PK (part 1)
collection_idINTEGERMaps to a named collection. PK (part 2)
modifiedTIMESTAMPLast modification time (server-assigned, updated on writes)
countBIGINTCount of BSOs in this collection (used for quota enforcement)
total_bytesBIGINTTotal payload size of all BSOs (used for quota enforcement)

Supports last-modified time tracking at the collection level.

Enables /info/collections, /info/collection_counts, and /info/collection_usage endpoints.

BSOS Table

Stores actual records being synced — Basic Storage Objects.

ColumnTypeDescription
user_idBIGINTThe user id (assigned by Tokenserver), FK (part 1) to user_collections
collection_idINTEGERMaps to a named collection. PK (part 2) & FK (part 2) to user_collections
bso_idTEXTUnique ID within a collection. PK (part 4)
sortindexBIGINTIndicates record importance for syncing (optional)
payloadTEXTBytes payload (e.g. JSON blob)
modifiedTIMESTAMPAuto-assigned modification timestamp
expiryTIMESTAMPTTL as absolute expiration time (optional)

Indexes bsos_modified_idx: for sorting by modified descending (used in sort=newest)

bsos_expiry_idx: for pruning expired records and TTL logic

Implements all BSO semantics from the API spec

Collections Table

Maps internal numeric IDs to collection names.

ColumnTypeDescription
collection_idINTEGERPrimary key
nameVARCHAR(32)Collection name, must be unique

Used to reference collections efficiently via ID.

Collections can include bookmarks, tabs, passwords, etc.

Batches Table

Temporary table for staging batch uploads before final commit.

ColumnTypeDescription
user_idBIGINTThe user id (assigned by Tokenserver), FK (part 1) to user_collections
collection_idINTEGERMaps to a named collection. PK (part 2) & FK (part 2) to user_collections
batch_idUUIDClient-generated or server-assigned batch ID. PK (part 3)
expiryTIMESTAMPTime at which batch is discarded if not committed

Indexes: batch_expiry_idx: For cleaning up stale batches

Batch BSOS Table

Stores BSOs during a batch upload, not yet committed to bsos.

ColumnTypeDescription
user_idBIGINTFK to batches
collection_idINTEGERFK to batches
batch_idUUIDFK to batches
batch_bso_idTEXTUnique ID within batch
sortindexBIGINTOptional, for sort priority
payloadTEXTPayload
ttlBIGINTTime-to-live in seconds

Database Diagram and Relationship

erDiagram
    USER_COLLECTIONS {
        BIGINT user_id PK
        INTEGER collection_id PK
        TIMESTAMP modified
        BIGINT count
        BIGINT total_bytes
    }

    COLLECTIONS {
        INTEGER collection_id PK
        VARCHAR name
    }

    BSOS {
        BIGINT user_id PK
        INTEGER collection_id PK
        TEXT bso_id PK
        BIGINT sortindex
        TEXT payload
        TIMESTAMP modified
        TIMESTAMP expiry
    }

    BATCHES {
        BIGINT user_id PK
        INTEGER collection_id PK
        UUID batch_id PK
        TIMESTAMP expiry
    }

    BATCH_BSOS {
        BIGINT user_id PK
        INTEGER collection_id PK
        UUID batch_id PK
        TEXT batch_bso_id PK
        BIGINT sortindex
        TEXT payload
        BIGINT ttl
    }

    USER_COLLECTIONS ||--o{ BSOS : "has"
    USER_COLLECTIONS ||--o{ BATCHES : "has"
    BATCHES ||--o{ BATCH_BSOS : "has"
    COLLECTIONS ||--o{ USER_COLLECTIONS : "mapped by"