Skip to content

Add concurrent subscription update conflict resolution with OCC #613

Description

@Smartdevs17

Context

When multiple admin users or automated processes operate on the same subscription simultaneously, last-writer-wins causes silent data loss.

Current Limitation/Problem

A support agent updating subscription notes can be overwritten by billing's status change. No conflict detection exists.

Expected Outcome

Optimistic Concurrency Control (OCC) using version numbers: each entity has a version field incremented on write. Updates include WHERE version = N and fail with 409 on conflict.

Acceptance Criteria

  • Version field: add integer version column to subscription, invoice, plan entities (default 1)
  • Optimistic update: UPDATE ... WHERE id = $1 AND version = $2 returning rowcount (0 = conflict)
  • Conflict response: 409 Conflict with current version in response body
  • Client retry: fetch latest entity version and retry mutation (up to 3 attempts)
  • Conflict notification: show diff UI when automatic retry exhausted after 3 attempts
  • Mutation history: log conflicting writes with field-level diff for audit
  • Edge case: bulk operations increment version individually per row
  • Edge case: admin bypass parameter (?force=true) for emergency overrides (logged)

Technical Scope

  • db/migrations/ - add version column to subscription, invoice, plan tables
  • backend/shared/occ/ - OptimisticLockService (version check + increment)
  • backend/subscription/controller/ - version validation in update endpoints
  • backend/billing/controller/ - version validation in billing operations
  • mobile/app/services/ - conflict retry logic with exponential backoff

Metadata

Metadata

Assignees

Labels

200-points200 point issueStellar WaveIssues in the Stellar wave programdrips-waveIssues in the Drips Wave programhighHigh complexity issue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions