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