Exercise — Configuration and Feature Flags: roll out a feature to 5% of users.

Topic: microservices, Deployment. Level: Intermediate.

Answer

Use a deterministic hash of the user id to bucket users into a stable percentage, so the same user consistently sees the same variant and you can ramp the percentage centrally. Read the rollout percentage from config so it changes without redeploy. ```java class PercentageRollout { boolean enabled(String flag, String userId, int percent) { int bucket = Math.floorMod( (flag + ":" + userId).hashCode(), 100); // stable 0..99 per user return bucket < percent; // percent read from config } } // percent=5 -> ~5% of users; bump to 25, 50, 100 centrally to ramp the rollout. ```