AlgoMaster Logo
AlgoMasterRoute a Sticky Strangler Rolloutmedium

Route a Sticky Strangler Rollout

medium

A strangler facade can migrate one path slice at a time and expose only a stable percentage of subjects to the new service. Sticky routing prevents the same user or tenant from bouncing between old and new implementations.

Design a StranglerRouter class:

  • addRule(pathPrefix, rolloutPercent) adds a rule and returns false when that exact prefix already exists.
  • setRollout(pathPrefix, rolloutPercent) updates an existing percentage and returns false for a missing prefix.
  • route(path, subjectId) returns "new" or "legacy".

A prefix matches when the path is exactly equal to it or starts with prefix + "/". The special prefix / matches every path. Choose the longest matching prefix; when none exists, return "legacy".

Use this deterministic unsigned 32-bit hash for subjectId:

Return "new" exactly when bucket < rolloutPercent. Thus 0 always routes to legacy and 100 always routes to new.

Example 1:
Example 2:

Constraints

  • At most 500 rules and 10^4 operations exist per object.
  • Prefixes and paths are normalized, begin with /, and have no trailing slash except /.
  • Prefixes contain 1 to 200 printable ASCII characters.
  • Subject ids contain 1 to 100 printable ASCII characters.
  • 0 <= rolloutPercent <= 100
Hints

Loading...
CallReturns
new StranglerRouter()null
addRule("/api/profile", 50)true
route("/api/profile/42", "alice")"new"
route("/api/profile/42", "dave")"legacy"
route("/api/profiles/42", "alice")"legacy"

alice hashes to bucket 40 and enters the 50-percent rollout; dave hashes to 76. The similar /api/profiles path does not satisfy the slash-boundary prefix rule.

Run checks these cases. Submit also runs a larger hidden set.