Design: Offline-First Feed Interview Questions

ADVANCED › System Design

What do you need to clarify before designing an offline-first news or social feed?

What a strong answer covers: How fresh content must be, whether users can post or interact offline, how much should be cached and for how long, whether the feed is personalised and ranked by the server, media types (images, video), expected scale and devices, and whether reads only or writes too must work offline. These change the storage and sync design.

How would you store and display the feed so it works offline and opens instantly?

What a strong answer covers: Store feed items in Room as the single source of truth, with the server's order kept as a position or rank column. The UI observes the database through Paging, so cached content shows immediately on launch, and a refresh fetches new items and writes them in a transaction. Cache images on disk, and show a 'you're offline' banner rather than an error when the network fails.

How do you refresh the feed without the list jumping or losing the user's place?

What a strong answer covers: Don't insert new items at the top while the user is reading; fetch them in the background and show a 'new posts' pill that scrolls to the top when tapped. Use stable ids as keys, cursor-based pagination, and Paging's getRefreshKey to keep the anchor position. Updates to existing items (like counts) change in place.

How do you handle likes and comments made while offline?

What a strong answer covers: Apply them optimistically to the local database so the UI updates immediately, record a pending action with an idempotency key, and sync with WorkManager when the network returns. If the server rejects it, roll back the local change and tell the user. Collapse redundant actions (like then unlike) before sending, and keep server counts authoritative when they come back.

How would you manage cache size, expiry and storage for months of feed data and media, and what happens when the server's ranking changes?

What a strong answer covers: Keep a bounded window: the latest N items or items from the last few days in Room, with a periodic cleanup job, and an LRU-bounded disk cache for images and video with size limits. Store fetched-at times and treat older pages as stale, refetching on scroll. When the server re-ranks, a full refresh replaces the first page and its order in a transaction, while older pages are discarded or refetched, because merging two different rankings creates duplicates and gaps.

Back to Design: Offline-First Feed