Feat: Transaction batch upload - #7
Draft
Chriztiaan wants to merge 1 commit into
Draft
Conversation
Chriztiaan
commented
Aug 18, 2026
| updateBatch: async (batch: CrudEntry[]) => { | ||
| // TODO: Use batches & transactions. | ||
| // Transactions require a replica set or sharded cluster. | ||
| const session = client.startSession(); |
Collaborator
Author
There was a problem hiding this comment.
I took the liberty of changing the mongodb persister to use transactions, this means that users will need to run mongodb with a replica sets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For the current DemoConnect, the client uploads one transaction per attempt so a queue that built up offline drains one
round-trip at a time. This PR adds
POST /api/data/batch(which will eventually merge with /api/data - just separate for illustration), which takes an ordered run of whole transactions from the head of the upload queue and applies each one in its own database transaction.Batching is opt-in. Leave
VITE_BATCH_MAX_TRANSACTIONSunset and the connector keeps the existingsingle-transaction path.
How it works
A transaction is never split across batches. The client fills a batch until it hits either
VITE_BATCH_MAX_TRANSACTIONSorVITE_BATCH_MAX_OPERATIONS(default 1000), whichever comes first,and the backend applies them in order.
The response holds one result per transaction sent, in the same order and always the same length as
the request, so the client never has to infer which transactions were applied. Transactions the
batch never reached come back as
not_attemptedrather than being omitted.The client then completes once, at the last result that is
successorfatal_error. Completing atransaction also completes every transaction before it, so a single
complete()at that boundary isenough, and a retry resumes from the failure instead of re-uploading transactions that already
committed.
on_fatal_errorcontrols what a fatal failure does to the rest of the batch:not_attempted.poison operation can still drain. Its result still reports
fatal_errorwith the errorclassification, so the client can record what it discarded. Alternatively, there is room to divert these entries to a dead-letter queue instead of throwing them away.
skipcovers fatal failures only. A retryable failure always ends the batch.Error classification
For a batch to know where to stop, each failure has to be sorted into retryable vs fatal, so this PR
adds per-engine classification for Postgres, MySQL, MSSQL and MongoDB:
or out-of-range value, schema mismatch). Where the client discards the transaction.
AI disclosure
This PR was created with the help of Claude Code. Help constitutes assistance in research, planning,
and rough outline of implementation. Beyond having a hand in the implementation, I have also manually
tested this work.