S2 models data as many independent durable streams, often one per user, device, session, or job. This creates a cost challenge when storing data in S3: a few hot streams produce most of the bytes, but numerous quiet streams generate most of the storage writes. Because S3 charges for each PUT regardless of size, a typical 14 KiB segment written every 20 seconds can cost about $0.66 per stream monthly in requests, far more than storing its data. Delaying writes to combine more data from each stream would reduce requests, but keeps shared chunks in memory longer and increases crash-recovery work.
Instead, S2 combines small segments from different streams into packed objects, generally uploading when a batch reaches 16 MiB or after four seconds. Large segments from hot streams remain standalone. Even with only 50 streams per packed object, the example PUT cost falls to about $0.013 per quiet stream monthly; across 100,000 streams, estimated monthly request costs drop from $65,700 to $1,314, and small-segment PUTs decline by more than 100 times. Segment metadata identifies each segment’s byte range, allowing readers to fetch only that stream’s data with a ranged GET. Access controls, checksums, and encryption remain intact, and deterministic testing checks that failures cannot lose data. Packing can retain space unnecessarily and does not improve long-history reads; compaction can regroup surviving data by stream, trading rewrite costs against storage and read efficiency.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.