✏️ Explanatory Question

Trace the full request flow for posting a photo to a social feed.

👁 4 Views
📘 Detailed Answer
🟢 Easy
No previous question
No next question
💡

Answer with Explanation

A write-heavy flow with async fan-out - a very common interview walkthrough.

Synchronous path (what the user waits for):

  1. Client requests a pre-signed upload URL from the API.
  2. Client uploads the image directly to blob storage, bypassing the application servers entirely. This is the key move - never proxy large media through your API tier.
  3. Client calls POST /posts with the blob key, caption and an idempotency key.
  4. Gateway authenticates, rate limits, validates.
  5. Post service writes the row to the primary database and returns 201. The user is done here, in roughly 100 ms.

Asynchronous path (everything else):

  1. Post service publishes a PostCreated event to the queue.
  2. Image worker generates thumbnail variants and pushes them to the CDN.
  3. Fan-out worker writes the post ID into each follower's timeline cache. For a user with 1,000 followers this is fine; for a celebrity with 50 million it is not - so use the hybrid model: push for normal users, and for celebrities skip fan-out and merge their posts in at read time.
  4. Search indexer updates the index; moderation worker scans content; notification worker alerts mentioned users.

Failure handling to mention: the event must be published atomically with the database write - use the transactional outbox pattern, since a write that commits without its event causes a permanently missing timeline entry. Consumers must be idempotent because the queue delivers at-least-once.

No previous question
No next question