Skip to content

[Refactor] generateId() in feature-flag store uses Date.now() without collision protection under high throughput #782

Description

@RUKAYAT-CODER

Overview

src/lib/feature-flags/store.ts generates IDs with a pattern combining a prefix, Date.now().toString(36), and a small random number. Under high concurrent throughput, two requests that arrive within the same millisecond can produce identical Date.now() values, and the small random suffix provides inadequate collision resistance. Collisions would cause one flag creation to silently overwrite another.

Specifications

Features:

  • Feature flag IDs are guaranteed unique even under concurrent high-throughput scenarios
  • IDs are generated using a collision-resistant method

Tasks:

  • Replace the custom generateId() with crypto.randomUUID() which provides 122 bits of randomness and guaranteed uniqueness
  • Update existing ID format tests to accept UUID format
  • If a human-readable prefix is required, use the format: prefix_uuid

Impacted Files:

  • src/lib/feature-flags/store.ts

Acceptance Criteria

  • IDs are generated using crypto.randomUUID() or equivalent with at least 122 bits of entropy
  • No two concurrent ID generations produce the same ID
  • Existing tests that check ID format are updated

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions