Skip to Content

S3Snapshots

S3-based snapshot storage for caching bootstrap payloads.

Import

import { S3Snapshots } from '@gluonic/snapshots-s3'

Signature

function S3Snapshots(config: S3SnapshotsConfig): SnapshotsInterface

Parameters

config: S3SnapshotsConfig

PropertyTypeRequiredDescription
bucketstringYesS3 bucket name
keyPrefixstringNoPrefix for snapshot keys (default: snapshots/)
intervalMinutesnumberNoRegeneration interval (default: 60)
regionstringNoAWS region (default: from env)

Returns

SnapshotsInterface

interface SnapshotsInterface { get(orgId: string): Promise<{ lastSid: number; rows: WireRow[] } | null> set(orgId: string, payload: { lastSid: number; rows: WireRow[] }): Promise<void> regenerateAll(orgIds: string[]): Promise<void> }

Examples

Basic Usage

import { S3Snapshots } from '@gluonic/snapshots-s3' const server = SyncServer({ database, auth: JWTAuth({ secret: process.env.JWT_SECRET }), snapshots: S3Snapshots({ bucket: 'my-app-snapshots', intervalMinutes: 10 }) })

With Custom Key Prefix

const snapshots = S3Snapshots({ bucket: process.env.SNAPSHOT_BUCKET, keyPrefix: 'prod/snapshots/', intervalMinutes: 60 })

With Specific Region

const snapshots = S3Snapshots({ bucket: 'my-snapshots', region: 'us-west-2', intervalMinutes: 30 })

How It Works

  1. Initial Request: Client requests /sync/v1/bootstrap
  2. Check Cache: Server checks S3 for cached snapshot
  3. Cache Hit: Return cached payload (fast! ~50-100ms)
  4. Cache Miss: Query database, cache result, return payload
  5. Background: Snapshots regenerated every intervalMinutes

Performance: 10-50x faster than querying database every time.

AWS Setup

# Set up AWS credentials export AWS_ACCESS_KEY_ID="..." export AWS_SECRET_ACCESS_KEY="..." export AWS_REGION="us-east-1" # Create S3 bucket aws s3 mb s3://my-app-snapshots

See Also

Last updated on