How do you handle ties in cursor pagination?
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.
Verify This Answer
Cross-check this information using these trusted sources:
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.
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.
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.
Still have questions?
Browse all our FAQs or reach out to our support team
