Skip to content

High resolution fractional bucketing #1903

Closed
5 of 5 issues completed
Closed

Description

@toddbaert

Background

The current fractional operation uses a 100-bucket system, limiting the smallest allocation to 1%. This is insufficient for high-throughput environments where 1% could represent millions of users. Use cases like gradual rollouts, precise A/B testing, and canary deployments require sub-percent granularity (e.g., 0.1% or 0.01%).

Proposal

Use math.MaxInt32 (2,147,483,647) as the maximum allowed weight sum, with pure integer arithmetic for bucket assignment. This replaces the current 100-bucket float-based approach.

The bucket calculation becomes:

bucket = (uint64(hashValue) * uint64(totalWeight)) >> 32

This provides effectively unlimited precision (up to ~0.00000005%), eliminates floating-point issues, and naturally guarantees that any variant with weight >= 1 receives traffic.

Constraints

  • The sum of all variant weights must not exceed math.MaxInt32 (2,147,483,647)
  • Weights must be integers

Cross-language notes

The intermediate product (uint32 hash * int32 totalWeight) must fit in a 64-bit integer. Java's signed long is the most restrictive, which is why MaxInt32 (not MaxUint32) is the limit. JavaScript requires BigInt for the multiplication.

Language Hash Type Unsigned Conversion 64-bit Multiply Right-Shift
Go uint32 None uint64(hash) >> 32
Java int (signed) hash & 0xFFFFFFFFL long >>> 32
JavaScript Number BigInt(hash) BigInt >> 32n
Python int None Native >> 32
C#/.NET uint None (ulong) >> 32

API

No API changes. Existing fractional syntax is unchanged -- weights are just no longer limited to summing to 100.

Related

Note

This is a behavioral breaking change for existing configurations (bucket assignments will shift), but the API surface remains the same.

Activity

  1. changed the title [-][P1] Support a much higher resolution of buckets (e.g. be able to have a probability of 0,0001 of selecting a bucket)[/-] [+]Support a much higher resolution of buckets (e.g. be able to have a probability of 0,0001 of selecting a bucket)[/+] on Mar 12, 2026
  2. changed the title [-]Support a much higher resolution of buckets (e.g. be able to have a probability of 0,0001 of selecting a bucket)[/-] [+]High resolution fractional bucketing[/+] on Mar 12, 2026
  3. self-assigned this
    on Mar 19, 2026
  4. toddbaert commented on Apr 1, 2026

    @toddbaert
    MemberAuthor

    Done!

  5. moved this from Pending to Done in flagdon Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions