Design: Offline-First Feed Interview Questions
ADVANCED › System Design
A social feed shows new posts appearing at the top in real time. Walk me through what actually breaks about naive offset-based pagination in that scenario.
What a strong answer covers: A strong answer explains that offset pagination assumes a stable ordering; when new items are inserted at the top, every subsequent page's offset shifts, causing items to be skipped or duplicated as the user scrolls, known as page drift. It should connect this to why RemoteMediator with a RemoteKeys table decouples the client's paging position from raw offsets by tracking stable keys per page, so insertions at the top don't corrupt pages already loaded further down.
Your team's feed screen currently fetches directly from the network with no local cache. You're asked to make it offline-first without a full rewrite. Walk me through the migration path.
What a strong answer covers: A strong answer sequences the change: first introduce Room as the source of truth by writing network responses into it and having the UI observe a Flow from Room instead of the raw network response, the network-bound resource pattern, and only after that read path is stable and tested, layer in RemoteMediator and RemoteKeys for paging, then WorkManager sync. The trap is trying to introduce Paging 3, RemoteMediator, and background sync all in one change, which makes it hard to review, test, and roll back independently.
In this feed, a 'like' can be edited offline and a caption can also be edited by its author elsewhere. Would you apply the same conflict-resolution strategy to both, and why?
What a strong answer covers: A strong answer distinguishes commutative, idempotent operations like a like toggle, which are safe to resolve with simple last-write-wins or by re-deriving from server-side counts, from non-commutative edits like caption text, where last-write-wins can silently discard a user's real edit and server-authoritative resolution with explicit conflict surfacing is safer. The nuance a weak answer misses is that picking one conflict strategy for the whole feed ignores that different data types tolerate silently losing a write very differently.