S3Snapshots
S3-based snapshot storage for caching bootstrap payloads.
Import
import { S3Snapshots } from '@gluonic/snapshots-s3'Signature
function S3Snapshots(config: S3SnapshotsConfig): SnapshotsInterfaceParameters
config: S3SnapshotsConfig
| Property | Type | Required | Description |
|---|---|---|---|
bucket | string | Yes | S3 bucket name |
keyPrefix | string | No | Prefix for snapshot keys (default: snapshots/) |
intervalMinutes | number | No | Regeneration interval (default: 60) |
region | string | No | AWS 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
- Initial Request: Client requests
/sync/v1/bootstrap - Check Cache: Server checks S3 for cached snapshot
- Cache Hit: Return cached payload (fast! ~50-100ms)
- Cache Miss: Query database, cache result, return payload
- 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-snapshotsSee Also
- Snapshots Guide - Full setup and configuration
- Performance - Optimization strategies
- SnapshotsInterface - Interface details
Last updated on