Offset for small collections or when the client needs page numbers. Cursor for large collections or infinite scroll (faster, stable). Both need an index on the sort or cursor field.
Feed API Design Interview Questions and Answers
Offset or cursor pagination?
The answer
More FAQs in Feed API Design Interview Questions and Answers
GET /feed?skip=&limit=. Exclude the current user and already-swiped users. Build a filter from whitelisted query params. Use .lean() and .select(). Return { data, total, skip, limit }. Run find and countDocuments in parallel. Index the filter and sort fields.
Fetch the seen IDs with a distinct query. Filter the feed with _id: { $nin: seenIds }. For a dating app, exclude users the current user has already swiped on.
Add a tiebreaker. .sort({ createdAt: -1, _id: 1 }). Without a tiebreaker, two items with the same createdAt can cause cursor pagination to skip or duplicate items.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.