Skip to content

#1044 Implement optimistic locking for concurrent vault operations #571

Description

@vic-Gray

Area: backend · Effort: M

What: Add optimistic locking to vault and deposit entities to detect and handle concurrent modification conflicts without using database locks.

Why: Without concurrency control, simultaneous deposit requests can exceed vault capacity or produce incorrect balance calculations due to race conditions.

Acceptance Criteria:

  • Vault and deposit entities have a version column managed by TypeORM @VersionColumn
  • Concurrent modification throws an OptimisticLockVersionMismatchError
  • The error is caught and retried up to 3 times with jitter before returning a 409
  • A test demonstrates that two concurrent deposits to a near-full vault are handled correctly

Hints:

  • Add @VersionColumn() version: number to entity classes
  • Use TypeORM's save(entity, { version: entity.version }) syntax
  • Retry decorator: @Retryable({ maxAttempts: 3, backOff: 100 })

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions