Prepare and test your skills
Prepare and test your skills
Resiliency for Gemini-based applications means the serving path keeps answering requests when a zone, region, quota limit, accelerator, or stateful dependency fails. That outcome depends on Vertex AI Agent Platform (opens in a new tab) endpoints spread across regions (opens in a new tab), global routing of inference traffic, replicated data layers, reserved throughput for quota exhaustion, and continuous monitoring of serving metrics. Traffic flows from clients to global load balancing and then to healthy endpoints, while telemetry flows from serving infrastructure to monitoring and analysis tools that drive capacity decisions.
Multi-region serving distributes real-time inference and generative model deployments across multiple locations for high availability and low latency. Traffic flows from clients to global load balancing, which routes requests to healthy Vertex AI Agent Platform endpoints in available Google Cloud regions. Regional endpoints keep data in specific regions, while the global endpoint pools Google-managed capacity across regions or countries.
| Endpoint strategy | Routing scope | Choose when |
|---|---|---|
| Multiple regional Agent Platform endpoints | Traffic routes from global load balancing to endpoints in selected regions | Low-latency serving is needed with control over data location |
| Global endpoint | Traffic routes to shared capacity across multiple regions or countries | Data can be shared across regions and resilience to regional failure matters most |
Use regional distribution when residency or proximity requires it, and use the global endpoint when cross-region data sharing is permitted and survival of a regional failure is the priority.
Redundant dependencies prevent a single zonal failure from stopping Gemini inference, retrieval-augmented generation (RAG), or agent state. The serving compute depends on storage, metadata, and retrieval layers that must each survive zone loss, so each layer replicates independently rather than relying on a single copy.
When one zone fails, surviving zones continue to serve inference, retrieval, and metadata reads without rebuilding state from scratch.
Rate-limit handling for Agent Platform centers on resource-exhausted 429 errors, which are returned when request volume exceeds allocated capacity. The application must detect the 429 response from the model endpoint, then apply logging, exception handling, and retry mechanisms with exponential backoff so transient exhaustion does not become a user-visible outage. For business-critical workloads with consistently high throughput, the service depends on Provisioned Throughput to reserve capacity in advance rather than competing for shared on-demand quota.
Exam tip: A 429 error means requests exceeded allocated capacity; reserve throughput with Provisioned Throughput for sustained high-throughput workloads instead of relying only on retries.
Proactive capacity management uses historical telemetry to forecast accelerator and quota needs before serving degrades. Telemetry flows from Cloud Monitoring and logs in Cloud Logging to analysis in BigQuery or Looker Studio, where teams forecast demand for graphics processing units (GPUs) and tensor processing units (TPUs) from utilization and throughput trends. Teams then validate estimates with load testing using tools such as Apache JMeter or LoadView, testing generative serving under high concurrent load to find where accelerator availability limits performance.
Continuous monitoring tracks latency, throughput, errors, and GPU and TPU utilization in production, with alerts for quota pressure and agent health. The model observability dashboard exposes queries per second (QPS), token throughput, and first-token latencies, which reveal saturation, cold-start effects, and quota pressure before timeouts spread.
Elastic compute lets inference scale with request volume while remaining schedulable when a specific machine family or accelerator is unavailable. In GKE, the cluster autoscaler and node auto-provisioning adjust node count from pending Pod requests for central processing unit (CPU), memory, GPU, and TPU, while the Horizontal Pod Autoscaler scales deployments on CPU, memory, or custom metrics such as GPU or TPU utilization and prediction requests per second. In Cloud Run (opens in a new tab), services autoscale between configured minimum and maximum instances based on incoming requests and scale to zero when idle, including GPU-enabled instances for agents and third-party inference such as quantized models with Ollama and large language model inference with vLLM.
Obtainability improves when Pods accept alternative hardware instead of binding to one static type. Pod specifications use node affinity and tolerations on labels such as cloud.google.com/machine-family to permit scheduling across families, so GKE provisions whichever pool has capacity. General-purpose pools can fall back from N2 to N2D, C2 or C2D, or E2; GPU pools can fall back from A2 with NVIDIA A100 GPUs to L4 or T4 tiers using separate node pools or ComputeClasses; TPU pools can fall back from TPU Ironwood (TPU7x) to TPU v6 (Trillium) or TPU v5 (v5e or v5p) when slice provisioning is constrained.
Resilient agent runtimes separate stateless execution from durable state and scale horizontally behind a load balancer. Multiple instances of the agent application run behind load balancing, which distributes requests across instances to reduce latency and timeouts, with runtimes such as Cloud Run providing instance autoscaling automatically. State flows from the runtime to an external datastore such as Memory Bank, Memorystore for Redis, or Cloud SQL, so the agent can restart gracefully and retain context after an outage. Before production, teams simulate failures in a production-like environment to expose unexpected behavior.
Accelerator failures in training and self-hosted serving on GKE or Compute Engine managed instance groups require explicit detection and remediation:
gcloud command to report a faulty host when resets do not recover the node.For larger training, elastic frameworks such as recipes with the Google Resiliency Library for GPU workloads or resilient training with Pathways logic for TPU workloads let jobs continue despite individual hardware loss.
Model selection, prompt optimization, and context caching are the three primary levers for controlling cost, latency, and throughput of Gemini (opens in a new tab) workloads on Vertex AI Agent Platform. Model selection sets the baseline price and capability, prompt design determines how many input and output tokens are processed on every call, and context caching avoids reprocessing repeated long-context content. Together they minimize token consumption and reduce time-to-first-token in long-context applications.
Model selection is the choice of which Gemini model serves an application, and that choice directly affects both cost and performance. The recommended pattern is to test iteratively, starting with the most cost-efficient model and progressing gradually to more powerful options until quality requirements are met. For agentic systems, selection must also match required capabilities, since a smaller model may handle classification or summarization while multi-step reasoning needs a larger tier.
Expert optimization ties model selection to measured load on Vertex AI Agent Platform (opens in a new tab). To analyze and manage costs, create baseline metrics for queries per second (QPS) and tokens per second (TPS), then monitor those metrics after deployment. The baseline supports capacity planning and determines when Provisioned Throughput, which reserves throughput for business-critical workloads with consistently high throughput, is needed versus pay-as-you-go inference.
Prompt optimization is the practice of reducing input tokens and constraining output tokens without losing task quality, because prompt length and response length directly affect performance and cost. Effective prompts are short, direct, and provide sufficient context, while response instructions force conciseness with phrases such as "summarize in 2 sentences" or "list 3 key points". Shorter inputs lower per-request token charges and processing time, and shorter outputs reduce generation latency and output-token charges.
The Agent Platform prompt optimizer automates this work at scale and removes the need for manual rewriting across many cases. The optimizer takes an existing prompt as input, improves its performance, and adapts that prompt across different models when the selected model tier changes. Use manual prompt compression first for token discipline, then use the optimizer when prompts must be tuned across many use cases or ported from a cost-efficient model to a more powerful model.
Vertex AI context caching is a caching mechanism that stores repeated high-token content once and reuses it across requests to lower cost and latency. Without caching, data flows from the client to the model as full input tokens on every request, so the model reprocesses the same system instructions, documents, or few-shot examples each time. With caching, the repeated prefix flows from the client to a cache on the first call, and later requests flow from the client to the model as a cache reference plus only the new delta, so billed input tokens and prefill work drop sharply.
Context caching fits long-context applications where many requests share the same large prefix but differ in the final question, especially with high input token counts and high QPS against the same context. The benefit grows on every cache hit because time-to-first-token falls when the model skips reprocessing the cached prefix. Choose caching when repeated content dominates the prompt; it does not reduce cost for one-off prompts or for output length, so prompt compression still matters for the uncached remainder and for retrieval pipelines that may use Vector Search (opens in a new tab).
| Optimization | Cost effect | Latency and performance effect |
|---|---|---|
| Model selection | Lower tiers lower per-token price; iterative testing finds cheapest tier that meets quality | Larger tiers increase reasoning ability but increase latency and throughput needs |
| Prompt optimization | Shorter inputs and constrained outputs reduce input and output token consumption | Shorter prompts and concise responses improve response time and TPS efficiency |
| Context caching | Reusing repeated high-token content reduces billed input tokens on cache hits | Skipping reprocessing of cached content reduces latency and time-to-first-token |
Exam tip: Start with the most cost-efficient Gemini model and move up only after testing, and use context caching only for requests with repeated high-token content — it lowers both cost and latency on repeats, not on one-off prompts.
Inference modes in Gemini Enterprise Agent Platform are consumption options that decide how model compute is allocated, billed, and scaled for a workload. The platform provides five options — Provisioned Throughput (opens in a new tab), Standard PayGo, Priority PayGo, Flex PayGo, and batch inference — that trade guaranteed capacity and latency consistency against pay-per-use flexibility and discounted pricing. Selecting a serving architecture means matching traffic shape to the right mode: reserved capacity for steady baseline traffic, shared pay-per-use capacity for variable online traffic, discounted deferred capacity for latency-tolerant traffic, and offline batch jobs for asynchronous work.
Gemini Enterprise Agent Platform consumption options cover the range from prototyping to production with strict latency service-level agreements (SLAs). Provisioned Throughput reserves guaranteed throughput for a commitment period, while the PayGo family shares capacity without commitment and batch inference (opens in a new tab) processes queued jobs offline. The choice controls reliability, latency variability, and per-token price.
| Consumption option | Capacity model | Best fit |
|---|---|---|
| Provisioned Throughput | Guaranteed throughput for 1-week, 1-month, 3-month, or 1-year commitment; measured in throughput units (GSUs) and tokens per minute (TPM) | Critical, steady-state, always-on workloads where an SLA is needed |
| Standard PayGo | Flexible pay-per-use at standard per-token rate, no upfront commitment | Default for everyday use with variable traffic demand |
| Priority PayGo | Pay-per-use at premium per-token rate with priority processing, subject to ramp limit | Important workloads needing higher reliability and limits than Standard PayGo |
| Flex PayGo | Pay-per-use at discounted per-token rate with slower response and higher throttling | Latency-tolerant workloads such as offline analysis, annotation, and translation |
| Batch inference | Asynchronous batch jobs at discounted per-token rate | Large-scale jobs where results are needed within a longer timeframe |
Commitment length changes Provisioned Throughput cost, and deferred processing changes online cost: a 1-year Provisioned Throughput commitment is priced at a 26% discount compared to 1-month, Flex PayGo cuts costs by about 50% for non-latency-sensitive stages, and batch processing is about 50% cheaper than sequential Standard PayGo requests.
Provisioned Throughput is the reserved-capacity mode for critical production traffic that needs consistent performance and an SLA. The application sends online requests to reserved capacity up to its provisioned TPM limit, and the platform guarantees that throughput for the commitment period instead of competing for shared PayGo capacity. Because capacity is reserved, Provisioned Throughput removes variability from cold starts or queuing that can occur in PayGo models during high traffic. Right-sizing is central to its economics: provision to cover baseline and highest-priority traffic or a specific percentile based on risk tolerance, not peak demand, because provisioning for peaks lowers utilization and drives up cost.
Exam tip: Traffic that exceeds the Provisioned Throughput TPM baseline, called spillover traffic, is handled by Standard PayGo by default; use Priority PayGo when spillover needs more reliable performance at a premium price.
Batch inference is the offline serving architecture for asynchronous, high-volume workloads where immediate latency does not matter. The client formulates many requests into a JSON file or spreadsheet and submits them as a batch job, and the platform processes the backlog asynchronously and returns results within a longer timeframe. Data flows from the request file to the batch queue to the model and back to output storage, which lets the platform schedule work efficiently. Batch inference is the most cost-effective option for high-volume inference, suited to millions of documents to summarize, image labeling, bulk document processing, and sentiment analysis on historical data.
The hybrid serving strategy combines Provisioned Throughput and PayGo to balance reliability and cost for latency-sensitive workloads with spikes. First, the workload owner analyzes minute- or second-level traffic patterns and provisions throughput to cover the steady baseline and highest-priority traffic, which keeps reserved utilization high and economical. Then, traffic above the baseline flows as spillover from Provisioned Throughput to Standard PayGo or Priority PayGo, so variable peaks get flexibility without paying for idle reservations. If spillover shows higher performance variance above the TPM limit, latency and prompt optimizations reduce that variance while Priority PayGo provides a higher-reliability overflow path.
Response streaming (opens in a new tab) is the serving technique that optimizes user-perceived response time for interactive applications. Latency has two measures: time to first token (TTFT), the time from prompt receipt to the first output token, and time to last token (TTLT), the total time to process the prompt and generate the full response. With streaming through streamGenerateContent, tokens flow from the model to the application before generation completes, so the application can update its user interface and run concurrent tasks in real time. TTFT matters most for streaming responsiveness, while TTLT grows directly with the number of generated tokens.
Latency controls that reduce TTFT and TTLT include:
max_output_tokens parameter to cap length, which shortens TTLT but can cut responses mid-sentence if set too low.Availability controls protect online Gemini workloads against throttling and regional capacity limits, signaled by 429 resource-exhaustion errors. The global endpoint draws on Google's global capacity pool to minimize throttling from regional constraints, while traffic shaping and scheduling avoid the higher throttling rates associated with high PayGo TPM spikes and diurnal peaks. Provisioned Throughput quota must be monitored as TPM consumption, with throughput units increased before anticipated events such as product launches, automated by a monitoring alert policy.
Resiliency practices that keep production serving available include:
streamGenerateContent improves perceived latency measured as time to first token and time to last token.Use multiple regional Vertex AI Agent Platform endpoints when low-latency serving is needed with control over data location, and use the global endpoint when data can be shared across regions and resilience to regional failure matters most. Regional endpoints keep data in specific regions while the global endpoint pools Google-managed capacity across regions or countries, with global load balancing routing traffic to healthy endpoints.
A 429 error means request volume exceeded allocated capacity. Handle transient exhaustion with logging, exception handling and retry mechanisms with exponential backoff, and reserve capacity in advance with Provisioned Throughput for business-critical workloads with consistently high throughput rather than competing for shared on-demand quota.
Use Vertex AI context caching when many requests share the same large repeated high-token prefix but differ in the final question, especially with high input token counts and high queries per second (QPS) against the same context. On cache hits later requests send a cache reference plus only the new delta, which reduces billed input tokens and time to first token (TTFT), while it does not reduce cost for one-off prompts or for output length.
Provision throughput to cover the steady baseline and highest-priority traffic based on minute- or second-level patterns to keep reserved utilization high, and let traffic above the tokens per minute (TPM) limit flow as spillover to Standard PayGo by default or Priority PayGo when more reliable performance is needed. Provisioned Throughput reserves guaranteed throughput measured in throughput units and tokens per minute (TPM) for 1-week to 1-year commitments, while spillover handling avoids paying for idle reservations for variable peaks.
Last updated