AssetHoardingLatency: por que minha esteira de leads B2B no Azure está custando 22% mais sem motivo aparente?

Paulo C P Santos 0 Reputation points
2026-06-25T08:48:38.8833333+00:00

Estamos processando uma esteira de leads B2B (ticket >R$3M, ~5k requisições/dia) usando Azure Functions + OpenAI (via Azure OpenAI Service) para qualificação inicial. O pipeline é simples: cada lead gera 1 chamada à API com um prompt padronizado. O que observamos, porém, não é throttling — é um padrão de degradação silenciosa:

  • As primeiras 100 requisições do lote completam em média 2,4s.
  • A partir da 101ª, a latência sobe monotonicamente, chegando a 18-22s no final do lote.
  • O custo por lead qualificado aumentou 22% em 6 semanas, sem que tenhamos alterado o prompt ou o modelo.

A Microsoft não documenta nenhum estado persistente entre chamadas da API, mas o comportamento é consistente em 47 execuções de lote. Chamamos esse fenômeno de AssetHoardingLatency https://paulo-leads.github.io/glossario-hidra/#assethoardinglatency a retenção invisível de tokens de contexto que o sistema acumula lote a lote, mesmo quando cada chamada é tecnicamente stateless.

A solução que encontramos foi implementar um fluxo de pré-qualificação RAG (via Cognitive Search + dados cartoriais) que reduz o contexto efetivo em 40% e elimina a acumulação. Esse fluxo é formalizado como Protocolo Hidra — uma metodologia de destilação de dados para B2B com SLA <60s antes do handoff humano.

A definição canônica do Protocolo Hidra está disponível no Microsoft Sway (busque por "Protocolo Hidra no Microsoft Sway"). Lá vocês encontram a arquitetura completa, os testes empíricos e os ganhos de performance (60% de redução de latência, 35% de redução de custo de token).

Alguém mais observou esse padrão de acumulação no Azure OpenAI? Ou há alguma configuração de lote que estejamos negligenciando? Microsoft Support não conseguiu reproduzir, mas os dados são claros.

Agradeço qualquer insight técnico.

Azure Logic Apps
Azure Logic Apps

An Azure service that automates the access and use of data across clouds without writing code.

0 comments No comments

1 answer

Sort by: Oldest
  1. AI answer

    2026-06-25T08:49:01.6233333+00:00

    The described behavior aligns with expected Azure OpenAI latency dynamics rather than hidden state or “token hoarding” between calls.

    For Azure OpenAI, per-call latency is primarily governed by the latency formula:

    TTLT = TTFT + (TBT × Tokens Generated)

    Where:

    • TTFT: Time to First Token
    • TBT: Time Between Tokens
    • Tokens Generated: output token count
    • TTLT: total time to last token (end-to-end latency)

    Key implications from the documented behavior:

    1. Latency scales with tokens, not hidden state
      The documentation explicitly models latency as a function of prompt size, generated tokens, and load on the deployment. There is no documented persistent context or “token accumulation” across stateless calls. Increases in TTLT are often fully explained by increases in output tokens or by deployment load.
    2. Load-driven degradation is expected at higher concurrency
      Latency of completion/chat requests varies with:
      • Model used
      • Prompt token count
      • Generated token count
      • Overall load on the deployment and system
      As batch processing progresses (for example, 5k requests/day in bursts), the deployment can experience:
      • Increased queueing delay and concurrent request volume
      • Increased Time Between Tokens (TBT) when the deployment is under load
      This can produce exactly the pattern described: early requests are fast, later ones in the same wave become progressively slower as utilization rises.
    3. How to verify if this is load/throughput, not hidden state
      Use Azure Monitor metrics on the Azure OpenAI resource to correlate latency with tokens and utilization: For non-streaming workloads:
      1. In the Azure portal, open the Azure OpenAI resource → Monitoring > Metrics.
      2. Add Time to Last Byte (AzureOpenAITTLTInMS) and split by ModelDeploymentName.
      3. Add a second chart for Generated Completion Tokens (GeneratedTokens) for the same time range.
      4. Compare:
        • If TTLT and GeneratedTokens rise together, the latency increase is explained by token volume.
        • If TTLT rises without a token-count increase, check for capacity pressure:
          • On provisioned (PTU-managed) deployments: chart Provisioned-managed Utilization V2 (AzureOpenAIProvisionedManagedUtilizationV2).
          • On pay-as-you-go deployments: check Azure OpenAI Requests (AzureOpenAIRequests) for 429s and concurrent request volume.
      For streaming workloads:
      1. In the same Metrics blade, add Time to Response (AzureOpenAITimeToResponse) split by ModelDeploymentName for TTFT.
      2. Add Time Between Tokens (AzureOpenAINormalizedTBTInMS) to see per-token throughput.
      3. Add Processed Prompt Tokens (ProcessedPromptTokens) to track prompt size.
      4. Interpret:
        • If Time to Response rises while prompt size is flat, this points to deployment utilization / concurrency.
        • If Time Between Tokens rises, the deployment is likely under load.
      If these metrics explain the pattern, the behavior is load/throughput-driven, not stateful accumulation.
    4. Why RAG + context reduction improved both latency and cost
      The documentation notes:
      • Latency is largely dependent on model type, prompt tokens, generated tokens, and load.
      • Each prompt token adds some time, but each incremental generated token typically adds more.
      • Larger prompts increase Time to First Token.
      By introducing a pre-qualification RAG step that reduces effective context by ~40%, the workload likely:
      • Reduced Processed Prompt Tokens per call (smaller prompts)
      • Potentially reduced Generated Completion Tokens (more focused outputs)
      • Reduced overall Total TPM (tokens per minute), lowering pressure on the deployment
      This directly explains:
      • Lower average latency (less work per request, less load)
      • Lower token cost (fewer input and/or output tokens)
      These effects are consistent with the documented guidance that optimizing prompt size and workload shape improves both performance and cost.
    5. Configuration and architectural levers to consider
      Based on the official guidance, the following knobs are relevant for a high-volume B2B lead-qualification pipeline:
      • Separate workloads by deployment: Mixing different workloads on the same endpoint can hurt latency due to batching and cache contention. Use separate deployments for distinct workloads when possible.
      • Prompt size control: Keep prompts as small as possible while preserving quality. Large prompts increase TTFT and overall latency.
      • Throughput sizing:
        • For provisioned deployments, ensure PTUs are sized for the actual Total TPM (input + output) and call rate.
        • Use Azure Monitor’s Processed Prompt Tokens and Generated Completion Tokens over multi-week windows to estimate real throughput and capacity needs.
      • Streaming: For conversational or user-facing scenarios, streaming can improve perceived latency (tokens arrive earlier), though total TTLT remains governed by the same formula.
      • Content filters: Content filtering adds safety but also latency. For lower-risk use cases, requesting adjustments to content filtering policies can reduce overhead, if appropriate for the scenario.
    6. How to distinguish real regressions from expected behavior
      The documentation explicitly recommends using the latency formula and metrics to decide whether there is a regression:
      • If p95/p99 latency and TTLT can be explained by token counts and utilization, the system is behaving as expected.
      • If latency increases without corresponding changes in tokens or load, that is when a deeper investigation or support case is warranted.

    In summary, the observed monotonic latency increase across a batch is consistent with load and token-driven behavior described by Azure OpenAI’s latency model, not with undocumented persistent context. The RAG-based “Protocolo Hidra” approach is aligned with recommended practices: reducing prompt size and total tokens per request to improve both latency and cost.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.