RésuméSay hello
All write-ups

Infra · 4 min read

Ground Zero

Letting the monolith storage architecture go.

We’re close to launching a SaaS with a feature that lets anyone make short-form videos just by chatting with AI. It runs on Railway, it serves 33 active test users, and before launch it has to run on more than one replica. Right now it can’t.

That’s a choice I made, not an accident. One container with one volume was the fastest path to a working product: Railway’s abstractions took the infrastructure off my plate while I built the agentic features, and at that stage features were the risk, not scale. The cost of shipping that fast is that you lose track of how reliable the storage architecture is.

This post is about paying that cost: how we store the image and video data the service generates, and what has to change before real customers arrive.

०१Where we are today

Today, the web service does 3 jobs in one container:

  1. Holds the database: an SQLite file in the volume.
  2. Holds every video: uploads → takes → renders, in the same volume.
  3. Runs heavy work: renders run inside the web process as well.
Today
Browser
Next.js pages + API
streams every video byte
Jobs, same process
ffmpeg · Remotion · whisper
/data volume
SQLite + every video
one mount at a time
backend
Python
postgres
backend only
web service
×1 only
all traffic
incl. video
read/write disk
HTTP
SQL
One container, one volume. Pages, renders and every video share the same disk, and every video byte a viewer watches leaves through the web service.

Everything the web knows sits on one disk that only one deployment can mount. A Railway volume can be mounted on one deployment only, so that means:

  1. One replica only
  2. No failover
  3. A short outage on every deploy
  4. Limited render capacity

And every video byte a viewer watches in the app is streamed through the web service, which costs egress and memory.

०२The change I made before launch

The change is simple yet effective: no service owns a disk anymore. State lives in Postgres and a bucket, which every replica reaches over Railway’s private network, so the web and the worker can each run more than one copy. The rest of the backend doesn’t change.

After
Browser
web ×2
no volume · checks owners
postgres
rows + job queue
Bucket
all media · free egress
worker ×1…n
ffmpeg · Remotion
pages + API
video bytes,
presigned links
rows + jobs
signs links
claims jobs
SKIP LOCKED
files in / out
No service owns a disk any more. Two web replicas share Postgres; the browser fetches video straight from the bucket through presigned links; workers claim jobs from Postgres and move files in and out of the bucket.

a)Single-attach block storage

A volume is a virtual hard drive attached to one machine (on AWS that’s EBS). If two replicas each had their own copy, the copies would drift apart after the first write: user A uploads to replica 1, and replica 2 never sees the file.

What workedSplit state by kind.
  • Files → object storage (a bucket). Files are stored under keys like projects/123/video.mp4 and fetched over HTTP. Any number of machines can read and write them. On AWS this is S3.
  • Rows → a shared database server (Postgres). It handles concurrent writes from many clients properly, which SQLite can’t do across machines.

b)Non-durable in-process jobs

A job runs as a JavaScript function inside the web process with setImmediate. This causes two problems:

  • Another machine can’t pick the job up, because a function in memory can’t be sent anywhere.
  • If the process crashes or redeploys, the job silently disappears. Nothing sweeps jobs left as “running”, so the user just sees a render stuck forever.
What workedA job queue in Postgres plus a separate worker service. A job becomes data (a type name and a JSON payload) instead of code in memory, and any worker can claim it. Capacity becomes elastic: add workers when the queue is long, remove them when it's short.

c)Process-local singletons

Several things live only in the web process’s memory:

  • the publish scheduler (a setInterval every 30 s)
  • a couple of background sweepers
  • a few counters that need to be the same on every copy

With two replicas, both schedulers would post the same scheduled post twice, and each replica would only see its own half of those counters.

What workedAdvisory locks in Postgres for the timers, so each tick only the replica holding the lock runs it. The counters move into a Postgres table.

०३What it costs

Item, per monthChange
Render CPU
moves to the worker, same amount
0%
RAM
more services running
+25% to +50%
Media storage, 200 GB
volume → bucket
−90%
Video egress, ~600 GB
bucket egress is free
−100%
Hosting total−60% to −68%
Seen this exact bug?Say hello
  • Railway
  • Postgres
  • Object storage
  • Job queues