Back to blog

One upload, five features watching: who tells them all?

Thắng Đoàn
Thắng Đoàn

FotoFlow's upload handler grew a chain of favors: save the photo, call the thumbnail service, call email, update search, bump loyalty points, notify analytics. At 200,000 users the email service hiccups for ten minutes and uploads fail with it, because the handler waits on all of them. A confirmation job that could run an hour later just stopped photo uploads.

Publish, do not call

Multiply the availabilities: four dependencies at 99.9% each leave the caller about 99.6% up. With direct calls, availability multiplies: four services at 99.9% each give the caller about 99.6%.

Instead the upload service saves the photo and publishes one event, PhotoUploaded, to a topic on an event bus, then answers the phone immediately. Thumbnails, email, search, loyalty and analytics each subscribe, and every one gets its own copy.

The last lesson spread work out; this spreads news. Queue: someone do this. Topic: this happened. Real systems combine both: each subscribing service gets its own queue of events, shared by its own instances.

New features just subscribe

The trust and safety team wants to scan every upload. They write a service that subscribes to PhotoUploaded and are done: no change to the upload service, no coordinated release, the publisher does not even know they exist. This is loose coupling, and it is the property that makes teams stop stepping on each other.

A subscriber being down is no longer an outage. The bus keeps its copy of the event until the subscriber returns, then delivers the backlog: late, but nothing lost. Other subscribers are unaffected.

What this does not solve

Events trade clarity for reach. "What happens when a photo is uploaded" is now an answer spread across five codebases, and only tracing can show the whole flow. Subscribers act a little later, events can arrive twice or out of order, and every subscriber must be idempotent, same rule as the last lesson.

One failure mode is quiet: the upload service saves the photo, then crashes before publishing. The photo exists; nothing reacted to it. The fix is the transactional outbox: write the event into an outbox table inside the same database transaction as the photo, and let a relay publish from that table, retrying until the bus accepts. Either the order and its event are saved, or neither is. The relay can poll the table or tail the database log itself.

Replay

A log-based bus like Kafka keeps events for days or weeks, not just until delivery. Analytics finds a bug that miscounted for 30 days, fixes its code, rewinds its position and reprocesses every event, while other subscribers are untouched. A brand-new service can also build its whole dataset from history instead of starting empty. Once events are your record of what happened, they become worth keeping.

Your release process coordinates six teams because one handler calls five services. What would those teams stop negotiating if the handler only published an event?
A bug miscounted revenue for a month. Could you reprocess history, or is it gone once consumed?

Uploads now fan out on their own. Next in the series: How do new likes appear without hitting refresh?

Sources

Apache Kafka

Netflix Technology Blog

RabbitMQ

Share:

Recommended for you

Enjoyed this article?

Subscribe for new articles. No spam. Unsubscribe anytime.

No pasting. This is the challenge.0/200

Typed live, never pasted.