Skip to content

createPartitionedRateLimitKeyFactory

createPartitionedRateLimitKeyFactory(partitionFactory, options?): RateLimitKeyFactory

Defined in: packages/pipeline-rate-limit/src/helpers/partitioned-key.ts:77

Creates a RateLimitKeyFactory for per-caller limits.

Segments are escaped and joined through the core key helper so tenant, caller/account identity, and request name remain distinct even when values contain separator characters.

RateLimitPartitionFactory

Resolves the stable caller/account identity.

PartitionedRateLimitKeyOptions = {}

Tenant and missing-partition policy.

RateLimitKeyFactory

A RateLimitKeyFactory suitable for RateLimitBehaviorOptions.keyFactory.

When a required tenant or caller partition is absent.

The produced key is <tenantId>:<partition>:<requestName> when tenant inclusion is enabled, <partition>:<requestName> otherwise. RateLimitBehaviorOptions.keyPrefix is still applied afterwards by buildRateLimitKey(), so environment/service prefixes remain orthogonal.

Per authenticated user, tenant-aware and fail-closed by default

const perUserKey = createPartitionedRateLimitKeyFactory((ctx) =>
ctx.items.get('currentUserId') as string | undefined,
);
class CreateOrderHandler {
@pipeline.wrap({ kind: 'command' }, [RateLimitBehavior, { keyFactory: perUserKey, keyPrefix: 'write-api' }])
async handle(command: CreateOrderCommand) {}
}

Single-tenant deployment — say so explicitly

createPartitionedRateLimitKeyFactory(readUserId, { includeTenant: false });

Account-wide bucket shared by every user in the account

createPartitionedRateLimitKeyFactory(readAccountId, { includeTenant: true });