Read-After-Write Consistency
What you'll learn: How to guarantee users see their own updates immediately in a distributed social feed system, even when other users' content may appear with slight delays.
The User Experience Problem
In a distributed social media feed, posts get fanned out to thousands of followers across multiple servers and caches. This creates a timing issue: if you publish a post and immediately refresh your feed, will you see it? Or will you stare at an empty slot while your content propagates?
Read-after-write consistency ensures that when you write data (post, like, comment), you can immediately read it back. Other users can tolerate eventual consistency—they might see your post a few seconds later—but you shouldn't doubt whether your action succeeded.
Why It Matters for Social Feeds
Imagine posting "Just got engaged! 💍" and refreshing your profile, only to see nothing. Panic sets in—did it work? You post again. Now you have duplicates. This breaks trust.
The challenge: your post is being fanned out asynchronously to followers' timelines. Your own timeline cache might not have it yet if it's treated like everyone else's.
Implementation Strategies
Direct database read: When fetching your own feed, bypass caches and read directly from the authoritative source (Posts table) to include any content you just created.
Session-aware routing: Tag requests with a session or user token. When you write, the system remembers. Your next read gets routed to a replica that's guaranteed current for your writes.
Optimistic UI update: The client immediately shows your post in the feed (before server confirmation), then reconciles if the server response differs.
Key Takeaway: Read-after-write consistency prioritizes the author's experience—users must always see their own actions reflected immediately, even if background fanout to others takes longer.