feat: Redis distributed locking for concurrent payroll runs + correlation ID logging - #1131
Merged
Wilfred007 merged 2 commits intoJul 31, 2026
Conversation
…ging Closes Gildado#1027 — add RedisLockService (SET NX / Lua unlock / auto-renewal) and integrate it into the payroll worker so only one payroll run per organisation can execute concurrently across horizontally-scaled instances. The worker concurrency setting is also relaxed to 5 now that the per-org lock provides the safety guarantee. Closes Gildado#1028 — add correlationContext (AsyncLocalStorage) that injects a x-correlation-id into every Winston log entry, matching the pattern already used by the request-ID middleware. PayrollQueueService propagates the caller's correlation ID into job data; the worker restores it at the start of each job so the entire async chain shares a single traceable ID. Closes Gildado#1029 Closes Gildado#1032
|
@Williams-1604 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RedisLockService) prevents two payroll runs for the same organisation executing concurrently across horizontally-scaled worker instances. UsesSET NX PXfor atomic acquisition, a Lua script for safe token-matched release, and a background renewal interval to keep long-running runs from expiring the lock mid-flight.correlationContext.ts) adds a per-operationx-correlation-idto every Winston log entry viaAsyncLocalStorage— the same mechanism as the existing request-ID middleware.PayrollQueueServicestamps a correlation ID onto each enqueued job (inheriting the HTTP caller's ID when available), and the payroll worker restores it at job start so all async log lines share a single traceable token.Changed files
backend/src/services/redisLockService.tsRedisLockServicewithacquire()/withLock()/ auto-renewalbackend/src/utils/correlationContext.tsAsyncLocalStoragecorrelation ID contextbackend/src/utils/logger.tsx-correlation-idinto every log entrybackend/src/services/payrollQueueService.tsbackend/src/workers/payrollWorker.tsbackend/src/services/__tests__/redisLockService.test.tsbackend/src/utils/__tests__/correlationContext.test.tsCloses #1027
Closes #1028
Closes #1029
Closes #1032