-
Notifications
You must be signed in to change notification settings - Fork 0
Implement idempotency key pattern (Redis + persistent table) #264
Copy link
Copy link
Closed
Labels
area:dbPostgres schema, migrationsPostgres schema, migrationsarea:jobsBackground jobs, cronBackground jobs, cronphase:P1-cms-corePhase 1 — CMS CorePhase 1 — CMS Corepriority:P1Important — should land in phaseImportant — should land in phaseskill:goGo programmingGo programmingskill:sqlSQL / PostgresSQL / Postgrestype:featNew feature or implementation taskNew feature or implementation task
Milestone
Metadata
Metadata
Assignees
Labels
area:dbPostgres schema, migrationsPostgres schema, migrationsarea:jobsBackground jobs, cronBackground jobs, cronphase:P1-cms-corePhase 1 — CMS CorePhase 1 — CMS Corepriority:P1Important — should land in phaseImportant — should land in phaseskill:goGo programmingGo programmingskill:sqlSQL / PostgresSQL / Postgrestype:featNew feature or implementation taskNew feature or implementation task
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary
Implement the idempotency pattern from §7: every mutating task payload carries an optional
idem_key; the handler's first action isidemStore.Claim(ctx, taskType, idemKey, ttl)— RedisSET NX EX. Persistent idempotency for "must not fire twice ever" tasks (e.g., webhook delivery) uses thetask_idempotencytable written inside the same DB transaction as the side effect.Design reference
Acceptance criteria
internal/jobs/idem/idem.goexposesidemStore.Claim(ctx, taskType, key, ttl) (bool, error)(RedisSET NX EX)idem:{task_type}:{idem_key}; value:worker_id + completed_atfor debuggabilitytask_idempotency(task_type TEXT, idem_key TEXT, completed_at TIMESTAMPTZ, result_hash TEXT, PRIMARY KEY (task_type, idem_key))idemStore.ClaimPersistent(ctx, tx, taskType, key)writes to the table inside the caller's TXemail.send→sha256(template+":"+to+":"+content_hash)TTL 24h;webhook.deliver→(subscription_id, event_id)TTL 7d; etc.gonext_jobs_idempotency_skips_total{task_type}increments on claimed-alreadyDependencies
#258
Complexity
M