DynamoDB Distributed Lock
Reference · Applies to Brighter V10
The DynamoDB locking provider implements Brighter's distributed lock on top of Amazon DynamoDB, so a single Outbox Sweeper and Archiver run when you scale out. It is a natural fit when you already use the DynamoDB Outbox.
DynamoDB Distributed Lock Package
Add the locking package for AWS SDK v4:
Paramore.Brighter.Locking.DynamoDB.V4
Prefer the V4 package for new projects. The earlier Paramore.Brighter.Locking.DynamoDB package targets AWS SDK v3, which is out of support on AWS, and exists only to aid migration.
The provider stores its locks in a DynamoDB table that you must create in advance (see Provisioning).
DynamoDB Distributed Lock Configuration
Configure the provider with DynamoDbLockingProvider, passing your IAmazonDynamoDB client and a DynamoDbLockingProviderOptions:
using Paramore.Brighter.Locking.DynamoDB.V4;
new DynamoDbLockingProvider(
dynamoDb,
new DynamoDbLockingProviderOptions(
lockTableName: "brighter-locks",
leaseholderGroupId: "sweeper-group"));DynamoDbLockingProviderOptions takes two required values in its constructor and exposes two optional settings:
LockTableName
string
none
Names the DynamoDB table that holds the locks.
LeaseholderGroupId
string
none
Identifies the group of instances that share the lock; every instance that must coordinate uses the same value.
LeaseValidity
TimeSpan
60000 ms
How long the lease is held before it expires automatically.
ManuallyReleaseLock
bool
false
Whether the provider releases the lock on completion rather than letting it expire.
Both constructor parameters are required, and both properties are init-only: set them in the constructor call or in an object initialiser, not afterwards. Set LeaseValidity comfortably longer than a Sweeper or Archiver cycle.
DynamoDB Distributed Lock Example
DynamoDB Distributed Lock Provisioning
The lock table must exist before the provider runs. Create a table whose partition key matches the provider's lock items, with the name you pass as LockTableName. If you already provision a DynamoDB Outbox table, provision the lock table the same way (for example with the AWS SDK, CDK, or Terraform). Consider enabling DynamoDB's time-to-live feature so expired lock items are cleaned up automatically.
DynamoDB Distributed Lock Notes
Use the same
LeaseholderGroupIdfor every instance that must share the lock; a different value creates an independent lock.Keep
LeaseValiditylonger than a typical Sweeper or Archiver batch so the lease does not expire mid-run. See Lease Expiry vs Manual Release.
Further Reading
Distributed Lock — concepts and the full provider list
DynamoDB Outbox — the matching Outbox
Outbox Support — the Sweeper and Archiver
Last updated
Was this helpful?
