Description
The backend's campaign projection currently assumes a single writer region; running active-active across two regions for availability requires conflict resolution for concurrent writes to the same campaign row from both regions, which last-write-wins cannot safely provide for accumulating fields like pledged amounts.
Requirements and Context
- Model the campaign projection's mutable fields as CRDTs (e.g. a PN-counter for pledged amount, an OR-set for participant list) that merge deterministically regardless of arrival order or origin region
- Implement a merge process that reconciles concurrent updates from two simulated regions into a single converged state, with a test proving convergence regardless of merge order
- Document which fields can be safely modeled as CRDTs and which genuinely require single-writer semantics, and how those are handled instead
- Proof of work (required): this is a hard/complex issue — the PR description must include (1) a screenshot of the full relevant test suite run showing all tests passing, and (2) a screenshot of a successful project/module build or compile (
npm run build) with no errors. PRs missing either screenshot will not be reviewed.
Suggested Execution
Branch: feat/integration-crdt-campaign-projections
Implement Changes
- Implement PN-counter and OR-set CRDT types for the relevant campaign projection fields
- Add a merge function invoked when reconciling two regions' projection state, with conflict-free, order-independent merging
- Add a property test (using
fast-check) asserting merge(A, B) == merge(B, A) and convergence under randomized concurrent update sequences
- Document the single-writer fields left out of CRDT modeling and why
Test and Commit
Run npx vitest run src/__tests__/crdtCampaignProjection.test.ts — property-based merge-order-independence and convergence tests both pass. Then run npm run build and confirm it completes with no errors. Attach a screenshot of both the passing test run and the successful build to the PR description as proof of work.
Example Commit Message
feat(integration): CRDT-based multi-region active-active campaign projections
Closes #<issue>
Guidelines
- Branch from
main, open a PR back to main
- All new code must have corresponding tests
- Run
npm run lint and npm run test before pushing
- Follow existing naming conventions and file structure
- PR description must reference this issue number (e.g.,
Closes #<issue>)
- Keep commits atomic and use conventional commit format
- This is a hard/complex issue: PR must include a screenshot of the test suite passing and a screenshot of a successful build/compile — PRs without both screenshots will be marked incomplete and not merged
Description
The backend's campaign projection currently assumes a single writer region; running active-active across two regions for availability requires conflict resolution for concurrent writes to the same campaign row from both regions, which last-write-wins cannot safely provide for accumulating fields like pledged amounts.
Requirements and Context
npm run build) with no errors. PRs missing either screenshot will not be reviewed.Suggested Execution
Branch:
feat/integration-crdt-campaign-projectionsImplement Changes
fast-check) assertingmerge(A, B) == merge(B, A)and convergence under randomized concurrent update sequencesTest and Commit
Run
npx vitest run src/__tests__/crdtCampaignProjection.test.ts— property-based merge-order-independence and convergence tests both pass. Then runnpm run buildand confirm it completes with no errors. Attach a screenshot of both the passing test run and the successful build to the PR description as proof of work.Example Commit Message
Guidelines
main, open a PR back tomainnpm run lintandnpm run testbefore pushingCloses #<issue>)