Skip to content

Make photo ordering atomic so concurrent uploads cannot write the same order value #16

Description

@rioredwards

Summary

New photo order is derived from count() + 1, which is race-prone. Concurrent uploads can read the same count and write duplicate order values, producing unstable feed ordering.

Why this matters

  • Feed order becomes nondeterministic under concurrent uploads
  • Duplicate order values make sort behavior depend on database implementation details
  • This gets worse as usage increases

Evidence

  • app/db/actions.ts:117-133

Suggested fix

Replace the count-based order assignment with an atomic monotonic strategy. Options include a database sequence, ordering by created_at plus a tiebreaker, or an insert that derives the next order inside a transaction with proper locking.

Acceptance criteria

  • Concurrent uploads cannot generate duplicate ordering keys
  • Feed ordering is deterministic
  • The chosen strategy is documented in code comments or schema notes
  • Add a regression test or concurrency-focused integration check if practical

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions