Scaling AI Infrastructure for Legal AI Applications at Enterprise Scale

harvey · Legal · 2025 · source Agentic: no · promotional bias: med · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: enterprise LLM inference infrastructure for legal AI

Harvey needed to run many legal AI products across multiple model providers and deployments while keeping latency, availability, quotas, observability, security, and developer access under control.

Constraints:

Architecture

Harvey built a centralized Python inference client around model configurations, endpoint health, weighted model selection, distributed quota/rate limiting, a Redis-backed token-bucket algorithm, an OpenAI-compatible model proxy, telemetry, Snowflake accounting, and strict SLA burn-rate alerts. The library abstracts model calls for products and developers while routing traffic across healthy deployments and preventing local experiments or bursty features from degrading shared model capacity.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  A["Centralized Python client"] --> B["Model configurations"]
  A --> C["Model endpoint selector"]
  C --> D["Model health tracker"]
  C --> E["Model deployments"]
  A --> F["Quota and rate limiter"]
  F --> G["Redis key-value store"]
  H["Model proxy"] --> E
  H --> I["Telemetry pipeline"]
  A --> I
  I --> J["Snowflake warehouse"]
  I --> K["SLA burn-rate alerts"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Centralized Python client Shared abstraction for all product and developer model calls. Model configurations, Model endpoint selector, Quota and rate limiter, Telemetry pipeline
Model configurations Configuration framework describing model family, region, capacity, supported environments, and validated models. Centralized Python client, Model endpoint selector
Model endpoint selector Weighted deployment selector using health, capacity, region, SLI/SLA checks, retries, and fallback priority. Model deployments, Model health tracker
Model health tracker Tracks endpoint latency and success-rate SLIs for routing decisions. Model endpoint selector
Quota and rate limiter Feature-aware distributed rate limiter with Redis-backed approximate sliding-window token buckets. Redis key-value store, Centralized Python client
Redis key-value store Distributed state backend for rate limiting and quota checks. Quota and rate limiter
Model proxy OpenAI-compatible proxy for requests outside Kubernetes, adding instrumentation, security, and central model onboarding. Model deployments, Telemetry pipeline
Model deployments Inference servers serving legal AI model requests across providers and regions. Model endpoint selector, Model proxy
Telemetry pipeline In-house events pipeline for prompt/output token accounting, observability, and export. Snowflake warehouse, SLA burn-rate alerts
Snowflake warehouse Data warehouse used by data and finance teams to analyze token consumption. Telemetry pipeline
SLA burn-rate alerts Reliability alerting layer for rapid response to distributed-system failures. Telemetry pipeline

Data flow

A Harvey feature or developer request enters the centralized Python client with context such as feature, environment, user, workspace, model family, and prompt-token weight. The client chooses a healthy deployment using SLI/SLA-aware weighted selection and fallback priority, checks quota through Redis-backed distributed rate limiting, forwards external requests through the proxy when needed, emits telemetry, and exports prompt/output-token accounting to Snowflake.

3 supporting quotes
“the library checks the request against the quota allocated for the current context, which includes information such as requesting feature, environment, user, and workspace.”article, stated
“Each request’s weight—determined by its prompt token count—and context is evaluated against the inference server’s available capacity.”article, stated
“This data is collected through our in-house telemetry events pipeline and exported to our Snowflake data warehouse”article, stated

Why this architecture

Harvey centralized inference because independent feature teams and developers would otherwise create untracked load, quota, security, and reliability problems. A shared client and proxy keep model onboarding fast while still enforcing endpoint health checks, fallback, rate limits, telemetry, and cost accounting across all environments.

3 supporting quotes
“At Harvey we have written a centralized Python library that abstracts all model interactions for both the product and our developers.”article, stated
“The easiest way to do this is to share the API keys with our developers to use as needed. On the flip side, we must also be able to track all model calls”article, stated
“Having a model proxy adds an additional layer of security (e.g., rotating API keys) and allows our developers to focus on what matters while masking and protecting sensitive data.”article, stated

Models used: multiple model families · model providers · model deployments

Scale

Alternatives considered (roads not taken)

Direct model calls from product code

Rejected because: A centralized client is needed to abstract model interactions and enforce reliability features.

“a centralized Python library that abstracts all model interactions for both the product and our developers.”article, stated

Share provider API keys directly with developers

Rejected because: Direct access would bypass tracking, instrumentation, security, and resource protection.

“The easiest way to do this is to share the API keys with our developers to use as needed. On the flip side, we must also be able to track all model calls”article, stated

Static rate limits requiring restart

Rejected because: On-callers need to change limits and quotas in seconds during model incidents.

“allows runtime configuration of limits and quotas across all our geographically deployed clusters—without any restart and in just seconds.”article, stated

Single deployment per model family

Rejected because: Parallel deployments, weighted selection, retries, and fallbacks provide higher availability under health or capacity variation.

“Through a variety of deployments, layered fallbacks, and retries, Harvey is able to ensure high availability and performance for our customers at all times.”article, stated

Patterns

model-routing (model-ops)

Harvey chooses among model deployments based on model family, health, capacity, region, and fallback priority.

“selects a model deployment based on a weighted selection process. Each deployment is assigned a weight based on criteria including health, capacity, and region”article, stated

fallback-degradation (reliability)

Layered fallbacks and retries preserve availability when model endpoints fail health or SLA checks.

“If a model endpoint is not healthy enough to satisfy our SLA, the system reduces its weight during the weighted selection process.”article, stated
“Through a variety of deployments, layered fallbacks, and retries, Harvey is able to ensure high availability and performance for our customers at all times.”article, stated

cost-aware-routing (model-ops)

Harvey evaluates request context, prompt-token weight, quotas, and capacity before sending traffic to model servers.

“Each request’s weight—determined by its prompt token count—and context is evaluated against the inference server’s available capacity.”article, stated

observability-tracing (operations)

Harvey instruments model calls, tracks token accounting, exports telemetry, and uses burn-rate SLA alerts.

“adding granular observability across this AI infrastructure stack is critical for tracking the reliability of the system.”article, stated
“detailed accounting of every prompt and output token consumed by our system.”article, stated

privacy-preserving-processing (governance)

The proxy masks and protects sensitive data while preventing raw API-key sharing from bypassing controls.

“Having a model proxy adds an additional layer of security (e.g., rotating API keys) and allows our developers to focus on what matters while masking and protecting sensitive data.”article, stated

Tradeoffs

Rate limiter design

Chose approximate sliding-window token bucket over more exact but slower accounting.

Rationale: The system balances accuracy and speed while keeping memory constant under bursty traffic.

“It achieves high scalability and throughput by balancing accuracy and speed while maintaining a constant memory footprint.”article, stated

Developer access pattern

Chose OpenAI-compatible proxy over direct provider-key sharing.

Rationale: The proxy preserves developer convenience while adding instrumentation, centralized onboarding, key rotation, and sensitive-data protection.

“The proxy API is compatible with the OpenAI API spec, ensuring no additional changes are needed beyond updating the endpoint URL.”article, stated

Infrastructure scope

Chose centralized horizontal scaling abstractions over feature-specific model integration.

Rationale: A central client lets Harvey add models quickly while keeping reliability and usage controls consistent.

“At Harvey, we prioritize taking the simplest possible approach while ensuring our systems can scale horizontally.”article, stated

Gotchas (what bit them)

Bursty model traffic can degrade shared inference servers.

Root cause: Features vary in request volume, prompt-token count, and concurrency against finite model capacity.

Resolution: Harvey uses active load balancing, weighted endpoint selection, and Redis-backed feature-aware rate limiting.

“model usage can be bursty—while some Harvey features issue fewer requests, others with more prompt tokens may have a flurry of many lightweight requests.”article, stated
“we implemented a distributed, feature-aware rate limiting system utilizing a Redis-backed approximate sliding-window token bucket algorithm.”article, stated

Developer experiments can unintentionally harm production deployments.

Root cause: Local machines, CI/CD, tests, and experiments can call shared model infrastructure without central accounting.

Resolution: Harvey routes external requests through a thin OpenAI-compatible proxy back into the cluster.

“We also want to ensure that a developer’s local machine, CI/CD pipeline, test infrastructure, or experiment does not unintentionally degrade our model deployments.”article, stated
“our team developed a thin proxy that forwards all model requests made outside of our Kubernetes cluster back through the cluster to the model servers.”article, stated

Endpoint health can change independently across deployments.

Root cause: Latency, success rate, capacity, and region differ across parallel model deployments.

Resolution: Harvey periodically measures SLIs and changes endpoint weights or fallback order.

“To assess deployment health, we measure latency and success rate Service Level Indicators (SLI) periodically. If a model endpoint is not healthy enough to satisfy our SLA, the system reduces its weight during the weighted selection process.”article, stated
“If a model endpoint is not healthy enough to satisfy our SLA, the system reduces its weight during the weighted selection process.”article, stated

Evaluation

Harvey evaluates infrastructure health through latency and success-rate SLIs, SRT/SLA thresholds, model benchmarks, statistical significance for quality and cost, request throughput/latency under burst, burn-rate alerts, and prompt/output token accounting.

Metrics: Billions of prompt tokens · Hundreds of millions of output tokens · Millions of daily requests · Latency and success-rate SLIs · SLA burn-rate alerts · Prompt and output token accounting · Runtime quota changes in seconds

3 supporting quotes
“To assess deployment health, we measure latency and success rate Service Level Indicators (SLI) periodically. If a model endpoint is not healthy enough to satisfy our SLA, the system reduces its weight during the weighted selection process.”article, stated
“To address this, we have very strict burn rate alerts around our SLAs to ensure a rapid response by the team.”article, stated
“Another critical piece of information that we track is detailed accounting of every prompt and output token consumed by our system.”article, stated

Outcomes

Harvey reports billions of prompt tokens, hundreds of millions of output tokens, millions of daily requests, geographically deployed clusters, runtime quota changes in seconds, and active latency/success-rate monitoring.

3 supporting quotes
“The system is able to handle bursty traffic without a significant impact on request throughput or latency. It achieves high scalability and throughput by balancing accuracy and speed while maintaining a constant memory footprint.”article, stated
“It also means a new model only needs to be added to this model proxy to be used across the company. Having a model proxy adds an additional layer of security (e.g., rotating API keys) and allows our developers to focus on what matters while masking and protecting sensitive data.”article, stated
“There is always room to improve performance, reduce costs, and add new features as our requirements change.”article, stated