Using Traffic Director for Header-Based Routing
Short answer
A Use Traffic Director to enable header-based routing and loose coupling for backend services on Compute Engine.
Question
Key Takeaways
Traffic Director is the correct Google Cloud feature for invoking backend services based on HTTP headers while maintaining loose coupling. It provides global service discovery and advanced traffic management for Compute Engine instances and Docker containers. This approach abstracts infrastructure details from the calling application.
Expert Analysis
The scenario requires a mechanism to route HTTP requests to distinct backend service implementations based on the value of an HTTP header, while maintaining loose coupling between the calling application and the Compute Engine instances hosting Docker containers. Option A (Traffic Director) is the correct choice because it provides global load balancing and traffic management for services within Google Cloud, supporting header-based routing through its integration with Istio/Service Mesh capabilities or via specific load balancer configurations that can inspect headers. Options B, C, and D fail to meet the specific requirement of header-based invocation or loose coupling in this context.
Traffic Director Enables Header-Based Routing for Loose Coupling
Option A leverages Traffic Director, which acts as a global service discovery and load balancing controller. It integrates with Envoy sidecars (via Anthos Service Mesh or standalone) to manage traffic flow. Crucially, Traffic Director supports advanced routing rules, including those based on HTTP headers. This allows the calling application to send requests without needing to know the specific IP addresses or instance groups of the backends; it simply sends requests to a logical endpoint or uses the service mesh's internal DNS. The backend selection logic resides in the traffic management layer, not the application code, achieving the desired loose coupling. The system inspects the incoming HTTP header and routes the request to the appropriate backend service implementation running in Docker containers on Compute Engine instances managed by managed instance groups. This architecture abstracts the physical infrastructure from the application logic.
Service Directory Lacks Dynamic Routing Capabilities
Option B, Service Directory, is a service registry that provides a centralized way to discover services. While it helps with loose coupling by allowing applications to look up service endpoints via DNS, it does not inherently provide the logic to route requests based on HTTP header values. Service Directory resolves names to IPs or ports but does not intercept and modify traffic flows based on content like headers. To achieve header-based routing with Service Directory, one would still need a separate load balancer or proxy layer that understands both the directory and the routing policies. Since the question asks for the feature to invoke services based on headers, Service Directory alone is insufficient as it is a discovery tool, not a traffic router. It cannot enforce the conditional logic required to choose distinct service implementations based on header values.
Anthos Service Mesh Requires Specific Configuration Context
Option C, Anthos Service Mesh, is a powerful platform that includes traffic management features. However, in the context of this specific exam question and the provided options, Traffic Director is often the designated answer for managing traffic across multiple regions and services, especially when integrating with GKE and Compute Engine. While Anthos Service Mesh can perform header-based routing, it is typically deployed on GKE. For Compute Engine instances running Docker containers, Traffic Director provides a more direct integration path for service discovery and traffic management without requiring a full Kubernetes cluster overhead if not already present. Furthermore, the question emphasizes "multiple regions" and "managed instance groups" on Compute Engine, which aligns well with Traffic Director's global scope and ability to manage non-Kubernetes workloads alongside Kubernetes ones. Choosing Anthos Service Mesh might be technically feasible in some setups, but Traffic Director is the more precise fit for the described infrastructure of VMs and MIGs.
Internal Load Balancing Cannot Inspect Headers for Routing
Option D, Internal HTTP(S) Load Balancing, terminates HTTPS connections and distributes traffic based on URL paths, host headers, or other simple criteria. However, standard Internal HTTP(S) Load Balancers do not support complex header-based routing rules to select different backend services dynamically based on arbitrary HTTP header values in the way described. They are generally used for basic distribution within a VPC. To achieve header-based routing, one would need to use a more advanced solution like Traffic Director or a custom proxy. Therefore, Internal HTTP(S) Load Balancing is incorrect because it lacks the granular control over traffic splitting based on header values required by the scenario. It cannot invoke distinct service implementations based on header content, making it unsuitable for this specific requirement.
The decisive condition is the need for header-based routing combined with loose coupling across Compute Engine instances. Traffic Director provides the necessary service discovery and traffic management layer to inspect headers and route to the correct backend. Other options either lack routing logic (Service Directory), are less suited for the specific VM/MIG setup (Anthos Service Mesh in this context), or lack header inspection capabilities (Internal LB). Candidates should remember that for advanced traffic management involving headers and global service discovery across mixed workloads, Traffic Director is the primary Google Cloud feature.
Exam Strategy
When faced with requirements for advanced traffic routing based on HTTP attributes like headers, prioritize solutions that offer service mesh-like capabilities or global traffic management. Differentiate between service discovery tools (which resolve names) and traffic routers (which direct flow based on content). For Compute Engine workloads requiring complex routing, Traffic Director is often the key enabler rather than standard load balancers or registries.
Related Analysis
Practice All PCD Questions
Access 84 questions with complete answers and detailed explanations.
View Full PCD Practice Test →