How it works
The publisher sends text, media references, and an idempotency key, a client-chosen ID for this submission. The API authenticates the account, checks the rate limit and audience, validates media readiness, and stores one canonical post with a server ID and creation time. A retry using the same key returns the same post rather than publishing twice.
After commit, an event enters a durable queue. Fanout workers read a versioned follow graph and write eligible post IDs into timeline stores, per-reader lists called inboxes. The publish API does not wait for those writes: at an example 1 ms each, 5,000 followers would hold the response for 5 seconds. If the queue stalls, the canonical post survives; workers can catch up from a durable event stream or outbox.
An event emitted before the database commit can point to a post that does not exist. A commit followed by a failed enqueue can hide a valid post from feeds. A transactional outbox, a row committed in the post’s own transaction that records the fanout work, closes that gap; tools such as Debezium can relay those rows from a database change log to Kafka. It adds a table to purge and a relay to run.
Follow one crash. The post and outbox row commit at 10:00:00. The relay dies, restarts at 10:02:00, and publishes the row. A worker fills half the inboxes and crashes, so another worker repeats the job. Inserts keyed by post and recipient make the repeats harmless. Followers see the post two minutes late, and nothing is lost.
The post row is saved, but the fanout process crashes before enqueueing work. What prevents a permanently missing feed entry?
Record the fanout intent durably with the post, such as an outbox row in the same transaction. A publisher can later move that intent to the queue; workers deduplicate by post and recipient.
Use this as a guide for self review; written answers are not graded.Keep in mind
- A canonical post is the source of truth; feed entries are derived references.
- Use a reliable post-to-queue handoff and idempotent fanout.