Skip to main content

S3 Storage Layer

S3 serves three roles: durable storage for data (SSTables, blobs), coordination layer (manifests, leases), and garbage collection target.

Loading diagram...

Object Layout

s3://{bucket}/{hash(id) % 128}/flushdb/{namespace}/
├── manifests/ 00000000000000000001.json, ...
├── sstables/
│ ├── L0/ {ulid}.sst
│ ├── L1/ {run-id}/frag-0000.sst, ...
│ ├── L2/ ...
│ └── L3/ ...
├── blobs/ {blob-id}.blob
├── chunks/ {chunk-group-id}/chunk-0000, ...
└── leases/ partition-{id}/lease-{version}.json

128-way prefix sharding avoids S3 partition throttling. SSTable IDs are ULIDs (time-sortable, hash-distributable).

Conditional Writes

S3 If-None-Match: * (available since August 2024) is the coordination primitive. Used for manifest CAS and lease acquisition. No external coordination service needed.

Distributed Leases

Partition ownership via versioned S3 lease keys:

Loading diagram...

30-second TTL, 10-second renewal interval (three chances before expiry).

Large Value Handling

Value SizeStrategy
< 32 KBInline in SSTable
32 KB – 4 MBValue separation: blob object on S3, SSTable holds (blob_id, offset, size) pointer. Compaction rewrites only pointers, not data. Write amplification drops from 10-30x to ~1x.
≥ 4 MBChunked: split into 4 MB S3 objects, fetched in parallel (up to 32 concurrent GETs).

The separation threshold is adaptive — adjusted based on observed write amplification and read patterns.

Garbage Collection

WhatWhen GarbageHow
SSTablesCompaction removes from manifestReference tracking → deferred DELETE after no active readers hold the old manifest version
OrphansCrash during flushList objects not in manifest, delete after 1 hour
ManifestsAfter 100+ newer versionsDelete beyond 2-snapshot retention
BlobsLive ratio < 50%Rewrite live entries, pointer migration during compaction
ChunksReferencing entry removedScan references, delete orphans after 4h grace
Multipart uploadsCrash during uploadS3 lifecycle rule (24h)

SSTable GC protocol: each reader holds a manifest version reference. GC only deletes SSTables removed in versions older than the minimum active reader version. 30-minute timeout for stuck readers.