Let's design the data layer for a social feed.
API design:
GET /feed?cursor=X&limit=20
→ { posts: [...], nextCursor }
POST /posts/:id/like
→ { success, likeCount }
Caching strategy:
- Feed: In-memory, stale-while-revalidate
- User profiles: Cache for minutes
Real-time: SSE for new post notifications, polling for like counts.
Optimistic updates: Like button updates immediately, rollback if server fails.
This covers the common patterns in a real application.