# Strategy Pattern

The Strategy Pattern encapsulates interchangeable behaviors behind a common interface so an application can select an implementation at runtime without changing its calling code.

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/strategy-pattern

> The pattern separates what an application needs to do from the implementation chosen to do it. For foundation model integrations, it enables configuration-driven selection among supported models or providers while keeping business logic stable and enforcing consistent operational and compliance controls.

Practice exams covering Strategy Pattern: [AIP-C01 AWS Certified Generative AI Developer - Professional](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional).

## 6 key aspects of Strategy Pattern

The pattern combines a stable interface, interchangeable implementations, and runtime selection while preserving capability, security, and operational constraints.

1. **Stable behavioral contract**: Define a common request and response interface that business workflows depend on. Keep model-specific payload construction, authentication, and error translation outside those workflows.
2. **Runtime strategy selection**: Select an approved implementation using request context and externally managed policy. Refresh configuration during execution so switching among existing integrations does not require changing or redeploying application code.
3. **Capability-aware interchangeability**: Declare requirements such as streaming, tool calling, context length, and supported input modalities. Reject incompatible strategies rather than assuming that every implementation can satisfy every request.
4. **Policy-constrained routing and fallback**: Apply provider approval, data residency, access permissions, and safety requirements before considering performance or cost. Restrict fallback to compliant alternatives and bound additional attempts.
5. **Controlled configuration deployment**: Validate strategy identifiers and model settings before releasing routing changes. Use gradual deployment, health monitoring, and rollback to limit the impact of an unsuitable model selection.
6. **Independent testing and evaluation**: Use contract tests to verify that each implementation satisfies the shared interface. Evaluate task quality separately because interface compatibility does not establish equivalent model behavior.

## Cloud services for Strategy Pattern

Amazon API Gateway provides a stable entry point, while AWS Lambda selects and executes an approved model strategy. AWS AppConfig supplies routing policy and model settings that the runtime refreshes independently of code deployment. Strategies can invoke supported models through Amazon Bedrock or use separately implemented provider integrations, retrieving external credentials from AWS Secrets Manager when necessary. The application remains responsible for capability checks, compliance filtering, bounded fallback, and response normalization. Configuration deployment controls reduce routing-change risk, but a new provider protocol still requires implementation and testing before configuration can select it.

- **[AWS Lambda](https://blowstack.com/tools/cloud-services-hub/aws-lambda)**: Lambda can host the strategy registry, routing logic, and model invocation implementations. Its code selects an approved strategy using runtime configuration rather than hard-coding one provider into every business workflow.
- **[AWS AppConfig](https://blowstack.com/tools/cloud-services-hub/aws-appconfig)**: AppConfig distributes model-selection rules and strategy settings independently of application deployments. Validators, deployment strategies, and alarm-based rollback help control changes; application code or an integration such as the AppConfig Agent must retrieve updated configuration.
- **[Amazon API Gateway](https://blowstack.com/tools/cloud-services-hub/amazon-api-gateway)**: API Gateway exposes a stable API while backend strategies change. It can provide authorization and throttling, but capability-aware model selection and provider-specific translation must be implemented in the backend or an appropriate integration.
- **[Amazon Bedrock](https://blowstack.com/tools/cloud-services-hub/amazon-bedrock)**: Bedrock provides access to foundation models, and its Converse API offers a consistent messaging interface for supported models. A strategy can select supported model identifiers while still checking differences in capabilities, inference parameters, access, and regional availability.
- **[AWS Secrets Manager](https://blowstack.com/tools/cloud-services-hub/aws-secrets-manager)**: Secrets Manager can store credentials used by strategies that invoke external model providers. Keep credential references separate from routing policy and grant each execution role access only to the secrets its approved integrations require.

## Strategy Pattern exam questions

Real practice exam questions on Strategy Pattern, with the correct answer and its explanation.

### Question 1 (AIP-C01)

**Question:**

A media company processes long-running document-generation jobs asynchronously. An AWS Lambda submission function reads AWS AppConfig to select an approved foundation model integration for a workload and places each job on a durable queue. Lambda workers later invoke the selected integration. All supported integrations are already deployed behind a common interface, and the workers have the required permissions.

Jobs can remain queued for several hours and can be retried in a different Lambda execution environment. Operators must be able to switch the integration for newly accepted jobs without deploying code. However, every processing attempt for an already accepted job must use the provider, model, and generation settings selected when that job was accepted. AppConfig updates must continue while older jobs are pending. Historical configuration documents are not available to the workers.

Which design best meets these requirements?

**Correct answer:** At submission, resolve and validate the routing configuration, then persist an immutable execution specification with the job, including the integration identifier, provider, model, generation settings, and configuration revision. Have every worker attempt dispatch through the deployed integration registry using that specification rather than the current routing mapping.

**Explanation:** The persisted specification carries the acceptance-time selection across queue delays, retries, and Lambda execution environments. Workers use the same supported integration and settings for every attempt, while the submission function can adopt AppConfig changes for newly accepted jobs without code deployments. The revision provides traceability without requiring historical configuration retrieval.

## Practice Strategy Pattern in a full exam

Questions on Strategy Pattern in each practice exam, with every answer option and an explanation for each:

- [AIP-C01](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional): 4 questions

## What is Strategy Pattern

The Strategy Pattern defines a family of interchangeable implementations behind a shared contract. A caller delegates an operation to the selected strategy rather than embedding implementation-specific logic throughout the application. In a generative AI application, that contract might accept messages, generation settings, and request metadata, then return generated content, usage information, and a normalized completion status. Each strategy handles a supported model integration while the business workflow remains independent of the selected implementation.

A practical cloud architecture exposes a stable inference endpoint through an API gateway. A compute component receives the request, evaluates routing policy, and selects a strategy from a registry of approved implementations. External configuration maps workload names, tenant tiers, or task types to strategy identifiers and model settings. For example, summarization requests might use a lower-cost model, while complex reasoning requests use a model that has passed a separate quality evaluation. Changing that mapping switches subsequent eligible requests without modifying application code.

On AWS, Amazon API Gateway can provide the client-facing endpoint, AWS Lambda can execute the selection and invocation logic, and AWS AppConfig can distribute routing configuration. The application must retrieve or refresh configuration at runtime; merely storing configuration externally does not make selection dynamic. Configuration should identify approved strategies, model identifiers, supported Regions, timeouts, and generation settings. Secrets belong in a secrets-management system rather than in routing documents.

The strategy interface needs explicit capability boundaries. Models differ in context limits, tool calling, structured output, image support, streaming behavior, and safety controls. A request requiring tool use must not be routed to a strategy that cannot support it. Provider-specific adapters can translate payloads and errors beneath the shared contract. Amazon Bedrock Converse provides a consistent messaging interface for supported models, but it does not make every model equally capable or cover arbitrary external provider APIs.

Configuration-driven switching has limits. Switching between already implemented, authorized, and tested strategies can avoid a code deployment. Adding a provider with a different authentication mechanism or request format usually requires a new integration, tests, and deployment. The pattern is therefore not a promise that any future model can be adopted through a configuration change alone. It also differs from simple load balancing: selecting a strategy can change behavior and capabilities, not merely the destination serving an identical implementation.

Routing policy must preserve security and compliance requirements. Filter candidates by approved provider, data residency, model access permissions, and required safeguards before optimizing for cost or latency. A fallback must satisfy the same constraints as the primary strategy. Do not silently send sensitive prompts to an unapproved provider after a timeout. Bound retries and fallback attempts because another invocation can increase cost, repeat tool side effects, or generate a materially different answer.

The main trade-offs are integration complexity, abstraction maintenance, and possible loss of provider-specific features. Validate configuration before deployment, retain a last-known-good version, and roll out changes gradually. Track model quality, latency, error rates, token usage, and estimated cost by strategy and configuration version without logging sensitive prompt content unnecessarily. Contract tests check interface compatibility, while representative evaluations determine whether a replacement model is suitable for the actual task.

## Learn Strategy Pattern in lessons

2 short lessons on Strategy Pattern in 1 certification course.

- AIP-C01: Adapter Pattern vs Strategy Pattern: translation versus selection (Premium), https://app.blowstack.com/lessons/adapter-pattern-vs-strategy-pattern-translation-versus-selection-aip-c01
- AIP-C01: Strategy Pattern: configuration-driven model selection (Premium), https://app.blowstack.com/lessons/strategy-pattern-configuration-driven-model-selection-aip-c01
