Skip to content

feat: pluggable backends (Redis / SQLite) for cross-host idempotency #1

Description

@samuelagents

Motivation

The default store is filesystem-backed, giving crash-safe at-most-once semantics on a single host. Operators running the same job from multiple hosts/containers (HA schedulers, k8s CronJobs with >1 replica) need a shared marker store so the effect is deduplicated across hosts.

Proposal

Extract a Backend interface so the lock/marker store is pluggable, and ship adapters:

  • RedisBackendSET key val NX PX <lease> for the lock; marker in a hash.
  • SqliteBackend — single-table marker store with a transaction-guarded acquire.
interface Backend {
  readMarker(key: string): Promise<Marker | null>;
  writeMarker(key: string, marker: Marker): Promise<void>;
  acquireLock(key: string, leaseMs: number): Promise<boolean>;
  releaseLock(key: string): Promise<void>;
}
createOnceStore({ backend: new RedisBackend(client) });

Acceptance

  • Backend interface extracted; current fs logic becomes the default FsBackend.
  • Redis + SQLite adapters run the same parametrized test suite.
  • Two-process concurrency test passes against a shared backend.
  • Adapters are optional peer deps — core stays zero-dependency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions