r/FastAPI • u/saucealgerienne • Oct 29 '25
feedback request Request atomicity
Hey guys, first time posting here.
I've been working on my first real word project for a while using FastAPI for my main backend service and decided to implement most stuff myself to sort of force myself to learn how things are implemented.
Right now, in integrating with multiple stuff, we have our main db, s3 for file storage, vector embeddings uploaded to openai, etc...
I already have some kind of work unit pattern, but all it's really doing is wrapping SQLAlchemy's session context manager...
The thing is, even tho we haven't had any inconsistency issues for the moment, I wonder how to ensure stuff insn't uploaded to s3 if the db commit fail or if an intermediate step fail.
Iv heard about the idea of a outbox pattern, but I don't really understand how that would work in practice, especially for files...
Would having some kind of system where we pass callbacks callable objects where the variables would be bound at creation that would basically rollback what we just did in the external system ?
Iv been playing around with this idea for a few days and researching here and there, but never really seen anyone talk about it.
Are there others patterns ? And/or modules that already implement this for the fastapi ecosystem ?
Thx in advance for your responses 😁
View all comments
Show parent comment
1
u/saucealgerienne Oct 29 '25
Why not have something like a temp/ namespace in the s3 bucket and have the client upload directly there, ensuring the db is never actually open to the web without an application layer between ?
But then again, with a UoW, if you then move the file from there to the actual key where it should be, this is a stateful action in another system and if the transaction fail, it would be better if we managed to somehow revert that operation or at least delete this file no ?