Appwrite Database + Appwrite Functions: Ensuring consistent pagination under concurrent writes
29K reputation · 10 Mar 2021, 21:34 UTC
Goal: Retrieve all documents from a collection in a deterministic order while using an Appwrite Function to process each batch, without missing or duplicating entries when writes occur between batches.
Constraints: The Database listDocuments endpoint only offers limit and offset, with a hard limit of 100 documents per request; offset‑based pagination is sensitive to concurrent inserts, updates, or deletes, which can shift the offset window and cause duplicates or gaps. Appwrite does not provide native cursor or keyset pagination, and the Server SDK inside Functions exposes only the limit/offset helpers.
Questions: Is it advisable to implement manual keyset pagination inside the Function using a monotonic field (e.g., timestamp or auto‑increment ID) to avoid offset‑sensitivity? Given the 100‑document ceiling, what batch size balances latency and consistency for large collections under moderate write traffic? Should the Function tolerate occasional duplicates/skips and rely on client‑side deduplication, or enforce strict server‑side ordering?