Why LiteLLM spend writes become the bottleneck above 1,000 RPS
At high volume, spend writes need batching and a Redis buffer so that PostgreSQL does not become the bottleneck of a shared LiteLLM gateway. Every request through the proxy has to be accounted for: spend, key usage and budget counters are recorded against virtual keys, users and teams. LiteLLM stores this state in PostgreSQL, which it names as the primary supported database, and virtual keys cannot run without it. Per-key budgets, TPM and RPM limits, temporary budget increases and model restrictions all read and update rows in that database, so the write rate grows with the request rate across every proxy instance.
LiteLLM's production guidance addresses this by batching spend updates to the database every 60 seconds at scale rather than writing on every request. Above roughly 1,000 RPS or 10 instances, LiteLLM states that the Redis transaction buffer is what keeps Postgres from becoming the bottleneck, which makes Redis part of the accounting path and not only a cache. Redis 7.0 or newer is already required once more than one proxy instance runs for shared rate limits and router state, so the buffer adds a dependency your team must run, monitor and fail over, not a new product choice. Confirm the Redis and PostgreSQL versions your deployment uses against the supported lines before planning.
Plan this work before traffic grows, not after the first slowdown. It applies when you expect sustained load near the thousand-RPS range, when you scale beyond about 10 instances, or when budgets must be enforced close to real time for many keys. Ask your team to measure current request rate, instance count and database write latency, then decide whether the buffer design and its failure behavior need to be part of the first production release. Teams running a small number of instances with modest traffic can usually defer it, but should still know where the threshold sits.
Request flow from LiteLLM pods to Redis buffer and PostgreSQL
The diagram starts with client requests passing through a load balancer to several LiteLLM pods. Each pod calls the model provider directly and records spend in its own in-memory queue. The queue is capped by LITELLM_ASYNCIO_QUEUE_MAXSIZE (default 1000), and entries are aggregated once the queue reaches 80 percent of that cap. Pods push spend entries into the shared Redis transaction buffer, and a periodic batched flush writes the buffered totals to PostgreSQL. When you review this path, check queue depth on each pod and watch for the Spend update queue is full warning.
Spend writes leave each pod in memory and reach PostgreSQL through Redis.
Queue and buffer settings and when each fits
This table compares the four settings that govern spend write behavior at high traffic: the in-memory queue size, the batch interval, the Redis transaction buffer and PostgreSQL connection capacity. Read each row for when to keep the default, when a change is worth testing and what the change trades away. Treat every change as a hypothesis to confirm with a load test on your own setup.
| Setting | Leave the default when | Consider changing when | Trade-off to weigh |
|---|---|---|---|
| LITELLM_ASYNCIO_QUEUE_MAXSIZE (default 1000) | The spend update queue warning does not appear in gateway logs under your peak load test | The warning appears at sustained peak and aggregation is delaying spend visibility | A larger queue holds more unwritten spend in process memory and extends the window of spend lost if a pod crashes |
| Spend write batch interval (60 seconds at scale) | Budgets and spend reports can tolerate up to a minute of lag and you have not seen database write pressure | Database write load is high in testing, or a budget check needs fresher spend data | A shorter interval raises write frequency to PostgreSQL, while a longer one increases how much spend is at risk between flushes |
| Redis transaction buffer | Traffic is below the scale where LiteLLM recommends Redis in the accounting path and you run a single proxy instance | You run above roughly 1000 RPS or 10 instances, or PostgreSQL write contention shows up in testing | Redis becomes part of the accounting path, so its availability, memory and persistence settings affect spend accuracy |
| Redis high availability (Sentinel or managed service) | Redis holds only non-critical cache data and a short outage is acceptable | The buffer carries spend data that must survive a Redis failure | Sentinel needs at least three Sentinel instances and adds operational work, and failover can lose recent writes that were not replicated |
| PostgreSQL connection capacity | Connection counts stay well below the server limit during the load test | Connection exhaustion appears as pods scale out or the batch flush competes with request traffic | More connections add memory load on PostgreSQL, so connection pooling with PgBouncer is often tested before raising limits |
| PostgreSQL replication and recovery | A single primary with tested backups meets your recovery objectives | You need read traffic offloaded or a standby ready for failover | Asynchronous standbys can lose the latest commits on failover, and automatic failover requires external tools |
| Pod count and workers per pod | Scaling stays within the one-Uvicorn-worker-per-pod layout LiteLLM recommends on Kubernetes | Pod count growth multiplies connections and batch flushes faster than the database can absorb | More pods spread load but each adds its own queue and connection pool, so changes need a retest |
What the spend update queue full warning means
What does the spend update queue full warning mean in LiteLLM?
The warning means the in-memory spend update queue has reached 80 percent of its capacity, set by LITELLM_ASYNCIO_QUEUE_MAXSIZE (default 1000 entries). Once that threshold is reached, LiteLLM starts aggregating queued spend entries before writing them to PostgreSQL, so the gateway is signaling that spend writes are arriving faster than they are being flushed. It is a pressure signal, not a failure notice on its own, and it usually appears when database writes slow down or traffic grows past what the current layout was sized for.
Does the spend update queue full warning mean I am losing spend data?
Not by itself. When the queue fills to the threshold, LiteLLM aggregates entries rather than discarding them, so spend is still recorded, but the write path is under strain and the margin before the queue reaches its maximum is shrinking. Whether any spend is lost depends on what happens next in your environment, which you should confirm in your own logs and by reconciling gateway spend totals against provider billing for the same period. Ask your implementation team to check the queue behavior under your load before you rely on spend figures for chargeback.
Which checks should I run first when the warning appears?
Start with the parts that feed the queue and drain it. Check:
- PostgreSQL write latency and lock waits during the warning window
- Connection pool saturation on the gateway, since each worker and pod opens its own database connections
- Redis health, including memory, latency and whether the instance is reachable from every proxy pod
- The number of running proxy instances, which multiplies write volume and connection demand
Compare the timing of the warning with these metrics before changing any setting.
Should I raise LITELLM_ASYNCIO_QUEUE_MAXSIZE to stop the warning?
Raising the limit can give the queue more room during short bursts, but it does not fix a database that cannot keep up. If the warning persists, a larger queue mostly delays the point where entries are aggregated and holds more unwritten spend in memory per pod, which matters if a pod restarts before flushing. Treat the queue size as one setting to test alongside the batching interval and the Redis buffer, and confirm the effect with a load test that matches your real traffic shape.
How do I confirm the warning in my own environment?
Search the proxy logs for the message Spend update queue is full on each pod and note the timestamps, then match them against request rates, PostgreSQL metrics and Redis metrics for the same minutes. Record the configured LITELLM_ASYNCIO_QUEUE_MAXSIZE value and the number of running instances at the time. Repeat the test after each change so you can show whether the warning stopped, and keep these records with your operations runbook. The LiteLLM spend queue troubleshooting page is the next read for the exact log text and the configuration options it covers.
Who is responsible for fixing the warning: my team or an implementation partner?
Your team owns the production environment, the database and the spend data, so it should own the decisions about queue size, batching and capacity. An implementation partner can plan the investigation, run controlled load tests, tune the settings with you and document the result, under a fixed scope agreed in writing before work starts. If your team already runs PostgreSQL and Redis in production, most of the diagnosis can be done internally, and outside help is usually most useful for load testing and for reviewing the results before go-live.
Does a quiet queue mean the spend writes are fully healthy?
A quiet queue is a good sign, but it does not prove the accounting path is healthy at higher traffic. The warning only appears when the queue crosses its threshold, so a gateway can run without it at moderate load and still show pressure during peaks, after a database failover or when another instance is added. Keep monitoring database write latency and Redis health through growth events, and rerun the check after any change to instance count, database sizing or queue settings.
How to tune spend writes for high traffic
This sequence takes a LiteLLM gateway from its default spend-write behavior to a tuned configuration that keeps PostgreSQL from becoming the bottleneck at high request volume. Each step ends with a check so the team knows whether to move on or roll back.
Confirm the traffic and instance profile
The platform engineering lead records the sustained requests per second, peak bursts, average and peak token volume, and the number of gateway instances running in production. Compare these figures with the threshold the LiteLLM Redis sizing guidance gives, which is roughly 1,000 requests per second or 10 instances. Below that profile, the default spend path may be sufficient, so the team should not add the Redis buffer without evidence. The step is complete when the team has a written traffic profile that names the measurement source, such as Prometheus metrics or load balancer logs, and the instance count is confirmed from the deployment platform.
Confirm Redis 7.0 or newer is in place
The platform team checks that a Redis deployment is reachable from every proxy instance and runs version 7.0 or newer, as the LiteLLM production guide requires once more than one proxy instance runs. Confirm the license edition chosen for Redis with legal or procurement, because Redis 8.0 and later are offered under a choice of RSALv2, SSPLv1 or AGPLv3, while 7.4.x to 7.8.x remain under RSALv2 or SSPLv1. Also confirm the high availability design, since Redis Sentinel requires at least three Sentinel instances for a robust deployment when Redis Cluster is not used. The step is done when
redis-cli INFO serveron each Redis node reports a version of 7.0 or newer and the proxy health checks succeed against that endpoint.Set the spend update batch interval
The team sets the interval at which the proxy writes aggregated spend to PostgreSQL. LiteLLM's production guidance suggests batching spend updates every 60 seconds at scale, so start from that value and avoid shorter intervals that multiply write transactions. Apply the change through the proxy configuration managed as code, not by editing a running container, and restart the rollout under the same change record. Note that a longer interval holds spend data in memory longer, so the team should confirm with the budget owners how stale spend figures can be before a key reaches its limit. The step is complete when the rendered configuration in the cluster shows the chosen value and a sample of spend records updates at the expected cadence.
Review the spend queue maximum
The engineer reviews
LITELLM_ASYNCIO_QUEUE_MAXSIZE, the cap on the in-memory spend update queue. The documented default is 1000 entries, and the queue begins aggregating entries once it reaches 80% of that size, logging the spend update queue is full warning. Raise the value only after confirming the memory headroom on each pod, because a larger queue holds more pending spend in process memory. Record the chosen value next to the pod memory limit so the two stay in sync during later changes. The step is done when the setting is applied in every proxy instance, and the team can show the environment value on a running pod.Size PostgreSQL connections and consider PgBouncer
The database owner counts the connections each proxy worker opens, multiplies by the number of pods and workers, and compares the total with the connection limit configured on the PostgreSQL server. Because every pod and worker can hold connections, a growing fleet can exhaust the server before CPU does. If the total approaches the limit, evaluate PgBouncer as a connection pooler in front of PostgreSQL and test its pooling mode with LiteLLM before production use, since the proxy's transaction behavior determines which modes are safe. Confirm that the PostgreSQL version in use is still supported under the versioning policy, which lists 17 and 18 as supported releases at the time of writing. The step is complete when a connection count worksheet shows headroom below the server limit at the target pod count.
Load test at target volume
The performance engineer runs a load test against a fake or mock model endpoint so provider rate limits do not distort results, using the traffic profile from the first step as the target. The test should include the expected mix of streaming and non-streaming requests and the virtual keys that production traffic uses, so spend writes are exercised across realistic key counts. Run the test long enough for the batch interval to fire several times, and record PostgreSQL write latency, lock waits and connection counts alongside gateway latency. The step is done when the test report shows the target volume sustained without failed spend writes and the database metrics stay within the limits the DBA set in the previous step.
Watch the warning and queue metrics
The on-call team sets alerts on the spend update queue full warning in proxy logs and on the database write latency and connection usage metrics gathered during the load test. A recurring warning means entries are being aggregated before they are written, which reduces write volume but signals that the queue or the batch interval is under pressure, so the team should check the queue size and the database before changing either value again. Treat any sustained growth in pending entries as a reason to hold the change and rerun the load test. The step is complete when the alerts are routed to the owning team and a staged rollout runs for an agreed period with no unexplained warnings.
Document the settings and rollback path
The platform lead writes a change record listing the batch interval, queue maximum, Redis version and endpoint, connection limits, PgBouncer decision and the load test results, all stored with the deployment configuration. The record also includes the previous values and the exact steps to restore them, such as reapplying the earlier configuration and restarting the rollout. Assign an owner for each setting so future upgrades or traffic changes trigger a review of the spend write design. The step is done when the rollback has been rehearsed in a non-production environment and the change record is reviewed and approved by the database owner and the security reviewer.
Choosing a Redis deployment for the accounting path
A single primary Redis with one replica is the simplest layout that keeps a copy of the transaction buffer. It suits a gateway that runs a few proxy instances and where a short interruption to spend buffering is acceptable. Replication copies data from the primary to the replica, but promotion to primary is manual in this layout, so someone must act during an outage.
- Operational load: You operate two nodes and the runbook for manual promotion and client reconfiguration.
- Failover: Without Sentinel or another orchestrator, the gateway does not switch to the replica on its own.
- Data loss window: Replication is asynchronous by default, so recent writes on a failed primary may not reach the replica.
- Memory sizing: Plan memory for the buffer on both nodes, since the replica holds the same dataset.
- License: Redis 7.2 and earlier are under BSD-3-Clause. Redis 8.0 and later offer a choice among RSALv2, SSPLv1 and AGPLv3, so confirm with counsel which version and license you will run.
Confirm the promotion procedure, the recovery time you need and the Redis version before you choose this layout.
Redis Sentinel provides high availability for Redis when you do not use Redis Cluster. It monitors the primary and replicas and performs automatic failover by promoting a replica to primary. The Sentinel documentation says a robust deployment needs at least three Sentinel instances, so the monitors can agree on a failover without a single point of judgment.
- Minimum topology: One primary, at least one replica and at least three Sentinel processes, placed on separate hosts or failure domains.
- Client support: The gateway must connect through a Sentinel-aware client path. Confirm how your LiteLLM version and its Redis settings discover the current primary.
- Failover effects: Writes in flight during promotion can be lost, and the gateway must tolerate reconnection.
- Testing: Rehearse failover in a non-production environment and record the observed interruption.
- License: The same license choice applies to Redis 8.0 and later. Review which terms apply to your distribution and any modified code you run.
Confirm the Sentinel topology, the failure domains and the client configuration with your platform team and the Redis Sentinel documentation.
Redis Ltd. sells Redis Software, a self-managed product with added compliance, reliability and resiliency features, and Redis Cloud, a managed service on AWS, Google Cloud and Azure. Neither is open source. This option moves operations to a vendor or adds vendor-supported features, but it changes the contract, the data location and the license terms you accept.
- Cost components: Subscription or consumption fees recur, and integration effort is one-time. Ask for a written quote that names the deployment model, support level and data regions.
- Data location: For Redis Cloud, confirm the cloud regions and whether the accounting data stays inside the boundary your policy requires.
- Feature parity: Confirm which Redis commands, modules and client libraries the offering supports for the buffer.
- Exit path: Ask how data and configuration move if you leave the service.
- License: Redis Software and Redis Cloud are proprietary, so review their terms separately from the open-source licenses.
Confirm the offering, its support terms and its data residency with the vendor, and have counsel review the license before you sign.
License review belongs in the decision because the Redis license has changed across versions. Redis 7.2.x and earlier remain under BSD-3-Clause. Redis 7.4.x through 7.8.x, then called Redis Community Edition, are under RSALv2 or SSPLv1, which are not OSI-approved. Redis 8.0 and later can be used under a license of your choice among RSALv2, SSPLv1 and AGPLv3. The Redis licenses page notes that the change in March 2024 frustrated some community members, and that Redis Ltd. plans to keep Redis Open Source under AGPLv3.
- Version choice: The license depends on the version you deploy, so record the exact version in your design.
- Modified code: The Redis licenses FAQ says teams that offer modified Redis code as a network service must make the modified source available to that service's users.
- Unmodified artifacts: Teams moving from Redis 7.2 or earlier with unmodified artifacts see no impact, according to the FAQ.
- Vector features: The Intel SVS-VAMANA optimizations are closed source and only usable under RSALv2, so avoid them unless counsel approves that license.
- Policy alignment: Check whether your procurement policy accepts each license option.
Confirm the license for your exact Redis version with counsel using the Redis licenses page as the starting reference.
Security and data-path risks in the accounting layer
Once Redis and PostgreSQL hold spend and budget state for a high-traffic gateway, they become part of your accounting controls. The cards below cover the access, secrets, recovery and change controls that protect that data path and should be reviewed before traffic grows.
Redis access control and placement
Redis holds the transaction buffer that sits in the spend accounting path, so anyone who can write to it can distort recorded spend. Confirm that Redis is reachable only from the LiteLLM proxy pods and Sentinel nodes, that it requires authentication, and that it sits on a private network segment with no public exposure. Check the Redis version you run against the Redis licenses page, since the license terms changed from Redis 7.4 onward and from Redis 8.0 onward.
Redis licensesPostgreSQL authentication methods
PostgreSQL stores virtual keys, budgets and the spend ledger, so its login path protects the accounting record itself. Configure the LiteLLM database role to use SCRAM-SHA-256 rather than MD5 password authentication, which PostgreSQL 18 deprecated. Restrict the role to the database it needs in pg_hba.conf and confirm the authentication method on every connection path, including replicas and any connection pooler.
LITELLM_MASTER_KEY in a secret manager
The LITELLM_MASTER_KEY grants administrative control over every virtual key, budget and spend record, and it must start with sk-. Store it in a secret manager rather than in a values file, container image or shell history, and rotate it through the same process you use for other administrative credentials. Limit which service accounts and operators can read the secret, and log every read where your secret manager supports it.
Backups and point-in-time recovery
Spend writes that were buffered in Redis but not yet committed to PostgreSQL can be lost if Redis fails before the flush, so the recoverable spend record depends on both stores. Define a PostgreSQL backup schedule with continuous WAL archiving so you can restore to a point in time, and test a restore against a non-production copy. Document how you will reconcile spend totals after a restore, and agree with finance which figure is authoritative.
PostgreSQL archiving docsAudit of queue setting changes
Changes to LITELLM_ASYNCIO_QUEUE_MAXSIZE, the batch interval and Redis connection settings alter how quickly spend reaches the database and how much is held in memory at once. Record who changes these values, when, and through which deployment pipeline, and require review for each change. Keep the previous value so you can roll back, and watch for the Spend update queue is full warning after any change, since that signals entries being aggregated under load.
- Default queue size
- 1000
Questions buyers ask before outside help on spend write tuning
What drives the effort and cost of tuning spend writes at high traffic?
The biggest drivers are instance count, the Redis and PostgreSQL topology, and how much load testing the work includes. A single gateway instance with one database needs far less analysis than a fleet of pods behind a shared Redis buffer with replicas and failover. Tuning work splits into one-time items (topology review, queue settings, a load test plan and the test runs themselves) and recurring items (re-testing after upgrades, traffic growth or new models). Ask any partner for a quote that lists instance count, Redis and PostgreSQL layout, the traffic profile to reproduce, and which retests are included. DeployOpen does not publish prices; a quote follows from the written scope.
How long does spend write tuning take for a typical gateway?
Duration depends on scope, not on a fixed number of days. A review of an existing deployment that checks the spend queue warning, the queue size setting and the Redis buffer is the smallest scope. Adding a load test that reproduces real traffic, plus changes to PostgreSQL connections and Redis failover, makes the work longer because each change needs a measured retest. Before agreeing on a timeline, confirm which of these you need, who controls the staging environment, and how many test cycles are included in the written scope.
What must our team provide before an outside engineer can start?
The engineer needs evidence of current behavior and access to the systems involved. Provide the gateway and database metrics for peak periods, the LiteLLM version in use, the deployment configuration (with secrets removed), and a description of the traffic profile: request rate, prompt sizes, streaming share and the number of distinct keys and teams. Also provide read access to the PostgreSQL and Redis topology, logs that show whether the Spend update queue is full warning appears, and a staging environment that matches production closely enough for load tests. Confirm access paths and change windows in the written scope.
Can our internal platform team tune spend writes without outside help?
Yes, if the team already runs Kubernetes, PostgreSQL and Redis and can measure the gateway under load. The settings themselves are few: the in-memory queue size controlled by LITELLM_ASYNCIO_QUEUE_MAXSIZE, the Redis transaction buffer, and the database connection limits. The harder work is building a realistic load test, reading the results against provider and queue metrics, and proving that a change does not move the bottleneck elsewhere. Teams without load testing experience often benefit from an outside review of the test design and the results before they change production settings.
What does the spend update queue full warning mean for our PostgreSQL load?
The warning means the in-memory spend queue has reached 80% of its capacity and entries are being aggregated before they are written. The queue defaults to 1000 entries, set by LITELLM_ASYNCIO_QUEUE_MAXSIZE, so the warning is a signal that writes are arriving faster than they are flushed. Repeated warnings at high traffic usually mean the Redis transaction buffer and batching interval need review, and that PostgreSQL write pressure should be measured before raising the queue size. Confirm the cause with your own metrics rather than treating the warning as a single setting to change.
How does a tuning engagement relate to LiteLLM Enterprise support?
They cover different things. LiteLLM Enterprise support, as described in the LiteLLM Enterprise documentation, includes a dedicated channel with the engineering team and optional 24/7 SLAs, with a 1 hour response for critical issues and 72 hours for security patches. Those terms come from the vendor and apply to a license you hold with LiteLLM. An outside tuning engagement from DeployOpen is a scoped piece of work on your environment, delivered in writing. Confirm which vendor terms apply to your license, and whether any tuning changes need vendor review before they go into production.
Does buying outside help guarantee a specific throughput result?
No engagement can guarantee a throughput figure, because results depend on your providers, network, hardware, traffic mix and database sizing. A well-scoped engagement defines what will be measured, the test conditions and the deliverables, and reports the observed results with their conditions. Ask for the test plan, the acceptance criteria agreed in advance, and a written record of which settings changed and why. Treat published benchmarks as a starting point, and confirm what they exclude before comparing them with your own numbers.
How DeployOpen scopes and delivers high-volume LiteLLM tuning
DeployOpen treats high-volume LiteLLM tuning as a written, fixed-scope engagement inside your own infrastructure. We start from your measured request rate, instance count, database and Redis topology, then change spend queue settings and the Redis buffer only where your measurements show a need.
How we scope
- We record current requests per second, instance count, and whether PostgreSQL write load is already visible in your metrics.
- We confirm the PostgreSQL and Redis versions, hosting model, and whether Redis is shared across all proxy instances.
- The written scope lists the configuration changes, load tests, documentation and handover items before any work starts.
How we build
- We apply the spend queue and Redis buffer settings in a staging environment that mirrors your production topology.
- We run load tests against a fake model endpoint so provider limits do not hide database and queue behavior.
- We watch for the spend update queue full warning and check PostgreSQL write latency and connection counts during each test run.
How we hand over
- You receive the final settings, the configuration as code, and a record of each test run and its measured results.
- We document the queue and buffer runbook, including what to collect before escalating a spend write warning.
- Your team walks through the handover with us so the people on call can explain each setting and its trade-offs.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer, scoped in writing.
- Retainers can cover re-running load tests after LiteLLM or Redis upgrades, and after changes to traffic patterns.
- Quotes follow from the written scope, so ask us to list each component, one-time work and recurring support separately.

