Fifteen patterns, and why each one earned its place
These are the patterns that shape Vitrin, the trade-offs behind each, and — for the four on ranking — how the ML actually behaves once it's running in production rather than in a notebook.
Reliability & contracts
Fourteen services sharing nothing but events means the event bus and the schema are the only things that can never quietly fail.
- 01The transactional outbox: making "commit" and "publish" one thingpost-service writes a post and announces it in the same breath — or not at all.
- 02The idempotent inbox: surviving at-least-once deliveryRabbitMQ promises every message arrives at least once. "At least" is the part that breaks counters.
- 03One writer per store: why ingestion-service owns all of ClickHouseFive services could each write their own analytics rows. Only one of them should.
- 04Proto-first contracts: the schema as the review gateNestJS, Go, Elixir, Kotlin, and Python all read the same event. One of them has to define it.
Feed architecture
“The feed” is two products wearing one UI — one precomputed to make reads free, one assembled fresh because there's no precomputed order for relevance.
- 05Fan-out-on-write: paying for ranking before anyone readsThe following feed has no ranking problem. The only real question is where to spend the work.
- 06The celebrity problem, and the hybrid strategy that fixes itEager fan-out means an author's follower count sets the latency of everyone's write path.
- 07Fan-out-on-read: the home feed's real-time scatter/gatherThere's no timeline to precompute when relevance depends on what's true right now.
- 08Candidates, features, ranking: three jobs that must stay three servicesFolding scoring into recommendation-service would save one hop and cost testability.
ML in production
A model that scores well offline is a hypothesis. These four patterns are how ml-service turns that hypothesis into something allowed to touch real traffic.
- 09Champion and challenger: how a new model earns production trafficGood offline metrics are a hypothesis, not a promotion.
- 10Why scoring is a stateless service and training never touches itTraining is a batch job that wants memory and time. Scoring is a request that can't wait for either.
- 11Retraining as a saga, not a scriptA five-step pipeline that dies two hours in shouldn't mean starting over from zero.
- 12Embeddings as a candidate source, not a ranking signalFeeding raw similarity into the ranking model makes it harder to say why anything ranked where it did.
Orchestration & concurrency
How the rest of the system stays coordinated and responsive under load.
- 13A saga for something as small as signing upRetrying registration after a failed step risks a second OTP email or a half-activated account.
- 14One process per connection: what the BEAM buys messagingA malformed frame on one connection shouldn't be able to touch anyone else's session.
- 15Choosing gRPC or RabbitMQ: the sync/async boundary ruleEvery cross-service call is one or the other. Getting it backwards once is enough to feel why.