Skip to content

Spike: Persistent, multi-instance-safe storage strategy to replace in-memory service state #181

Description

@meshackyaro

Description

Every domain service in the backend — EscrowService, GigService, UserProfileService, IpfsPinningService, and the auth NonceStoreService — stores its state in a process-local in-memory Map. Only rate-limiting (src/common/rate-limit/) actually uses the Redis client that's wired up in src/common/redis/redis.module.ts.

This means:

  • All application state (open gigs, escrows, user profiles, pinned CIDs) is lost on every restart/deploy.
  • Running more than one instance behind a load balancer causes state to diverge — a request hitting instance A won't see a gig created on instance B.
  • Background sweep workers (GigExpiryWorkerService, RepinWorkerService) each run their own setInterval per process, so N instances means N-way duplicate sweeps and N-way duplicate webhook dispatches for the same expiring/degraded record.

The migration framework (src/migration/) already models schema migrations against a stand-in in-memory "gigs" table, suggesting persistence is planned but not yet decided.

Component

Backend

Difficulty

🟣 Spike — investigation required, scope not yet defined

Tasks

  • Inventory every in-memory store and its access patterns (read/write frequency, query shapes)
  • Evaluate persistence options (Postgres, DynamoDB, etc.) against the existing migration framework's expectations
  • Design a leader-election or distributed-lock strategy so sweep workers run exactly once cluster-wide (e.g. Redis-backed lock, given Redis is already a hard dependency)
  • Prototype migrating one service (recommend GigService, the newest/smallest) to the chosen persistence layer
  • Document the migration path for the remaining services

Acceptance Criteria

  • A written recommendation for the persistence layer and the singleton-worker strategy
  • A working prototype of at least one service migrated off in-memory storage
  • Follow-up implementation issue(s) filed per remaining service
  • Any blocking unknowns (infra cost, ops burden) explicitly flagged

Estimated Time

2-3 days (time-boxed spike)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions