Menu

1 / 3

A File Storage Port in Go That Streams: io.Reader In, Disk and S3 Adapters Out

DEV Community: go·Gabriel Anhaia·9 days ago
#BPobFl45
#devtogo#devto#dev#return#context
Reading 0:00
15s threshold

Book: Hexagonal Architecture in Go

Also by me: Pocket Guides for Developers — the 8-book series

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

Your storage port looks clean: Save(ctx, key string, data []byte) error . The domain never touches the filesystem, the S3 adapter sits behind the interface, and the tests use a map. Then someone uploads a 2 GB video. To call Save , the HTTP handler has to produce a []byte , so it runs io.ReadAll(r.Body) .

Read what io.ReadAll does : it builds "slices of exponentially growing size, then copy into a perfectly-sized slice at the end." For a moment, the chunks and the final slice are both alive. That 2 GB upload costs you roughly twice its size in heap before your domain code runs a single line. Under a memory limit of a few gigabytes, two uploads at the same time can be enough to get the container OOM-killed.

Blame the signature.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.