Using Feature Flags for Selective Rollouts in Cloud Run
Short answer
C Migrate the traffic to the new service by using a feature flag for registered customers.
Question
Key Takeaways
Feature flags enable selective activation of new API versions for specific users in Cloud Run, avoiding the complexity of blue/green deployments or imprecise traffic splitting.
Expert Analysis
Cloud Run revision tags enable gradual traffic shifting for zero-downtime deployments of the new API version. Canary with new service (A) requires service URL change. Blue-green with separate project (B) adds complexity. In-place update (D) causes downtime.
The scenario presents a classic requirement for controlled, conditional feature exposure within a serverless containerized environment. The core constraint is that optimizations must be enabled for "select customers who registered" prior to a full rollout. This necessitates a mechanism that can evaluate user identity or registration status at the request level and route traffic accordingly without requiring complex infrastructure changes or external load balancers.
Option C, utilizing a feature flag, is the correct approach because it decouples deployment from release. In a Cloud Run context, you deploy the new version containing the optimization logic. The application code itself, or an edge proxy/gateway managing the gRPC interface, evaluates a feature flag configuration stored in a centralized service (such as Firebase Remote Config or Secret Manager). If the flag is enabled for a specific customer ID, the optimization runs; otherwise, standard behavior persists. This allows for immediate, granular control over who sees the new code without changing network routing rules or deploying multiple distinct services.
Option A suggests migrating traffic based on a percentage of registered customers using Cloud Run’s traffic split. While Cloud Run does support splitting traffic between revisions via tags, this mechanism is designed for A/B testing or canary releases where traffic is divided by volume (e.g., 10% to New, 90% to Old), not by specific user identity. You cannot easily map "registered customers" to a precise percentage split without significant external state management that defeats the purpose of simple cloud-native scaling. Furthermore, if the goal is to give all registered users access immediately, a percentage split is inefficient and imprecise compared to a direct identity-based check.
Option B proposes a blue/green deployment approach. Blue/green typically involves running two complete environments (old and new) and switching all traffic from one to the other instantly upon validation. While robust, it is overkill for enabling features for a subset of users. It implies maintaining two full sets of resources until the switch, which increases cost and operational overhead. More importantly, blue/green is a binary switch for the entire service population; it does not natively support selective activation for specific users within the same live environment without additional complex routing logic, making it less suitable than a feature flag for this specific "select customers" requirement.
Option D suggests enabling session affinity. Session affinity (sticky sessions) ensures that requests from a particular client are routed to the same backend instance. This is primarily used for applications that maintain local state on the server side. For a stateless financial risk calculation API, session affinity is unnecessary and potentially harmful, as it reduces the elasticity benefits of Cloud Run by preventing even distribution of load across available instances. It does not provide any mechanism for feature toggling or selective rollout.
The decisive factor here is the need for conditional execution based on user attributes (registration status) rather than traffic volume or environment parity. Feature flags allow the deployed code to behave differently for different users dynamically, aligning perfectly with the requirement to optimize for select customers before a general rollout.
Exam Strategy
When asked about releasing features to specific users or groups in a serverless environment, prioritize feature flags or dynamic configuration services over infrastructure-level traffic splitting. Traffic splits handle volume-based canarying, while feature flags handle identity-based conditional logic. Always distinguish between deployment strategy (how code gets there) and release management (who sees it).
Related Analysis
Practice All PCD Questions
Access 84 questions with complete answers and detailed explanations.
View Full PCD Practice Test →