The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
docs new deadlock fixing architecture
Ishaan Jaffb48b8366c292
diff --git a/docs/my-website/docs/proxy/db_deadlocks.md b/docs/my-website/docs/proxy/db_deadlocks.mdnew file mode 100644index 00000000000..39498a7ec1c--- /dev/null+++ b/docs/my-website/docs/proxy/db_deadlocks.md@@ -0,0 +1,48 @@+import Image from '@theme/IdealImage';+import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';++# High Availability Setup (Resolve DB Deadlocks)++Resolve any Database Deadlocks you see in high traffic by using this setup++## What causes the problem?++LiteLLM writes `UPDATE` and `UPSERT` queries to the DB. When using 10+ pods of LiteLLM, these queries can cause deadlocks since each pod could simultaneously attempt to update the same `user_id`, `team_id`, `key` etc.++## How the high availability setup fixes the problem+- All pods will write to a Redis queue instead of the DB.+- A single pod will acquire a lock on the DB and flush the redis queue to the DB.+++## How it works++### Stage 1. Each pod writes updates to redis++Each pod will accumlate the spend updates for a key, user, team, etc and write the updates to a redis queue.++<Image img={require('../../img/deadlock_fix_1.png')} style={{ width: '900px', height: 'auto' }} />+++### Stage 2. A single pod flushes the redis queue to the DB++A single pod will acquire a lock on the DB and flush all elements in the redis queue to the DB.+++<Image img={require('../../img/deadlock_fix_2.png')} style={{ width: '900px', height: 'auto' }} />+++## Setup+- Redis+- Postgres++```yaml showLineNumbers title="litellm proxy_config.yaml"+general_settings:+ use_redis_transaction_buffer: true++litellm_settings:+ cache: True+ cache_params:+ type: redis+ supported_call_types: []+```diff --git a/docs/my-website/img/deadlock_fix_1.png b/docs/my-website/img/deadlock_fix_1.pngnew file mode 100644index 00000000000..3dff86a4d20Binary files /dev/null and b/docs/my-website/img/deadlock_fix_1.png differdiff --git a/docs/my-website/img/deadlock_fix_2.png b/docs/my-website/img/deadlock_fix_2.pngnew file mode 100644index 00000000000..345acff586fBinary files /dev/null and b/docs/my-website/img/deadlock_fix_2.png differdiff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.jsindex 1542edceb5d..1cb3e02707d 100644--- a/docs/my-website/sidebars.js+++ b/docs/my-website/sidebars.js@@ -53,7 +53,7 @@ const sidebars = {{type: "category",label: "Architecture",- items: ["proxy/architecture", "proxy/db_info", "router_architecture", "proxy/user_management_heirarchy", "proxy/jwt_auth_arch", "proxy/image_handling"],+ items: ["proxy/architecture", "proxy/db_info", "proxy/db_deadlocks", "router_architecture", "proxy/user_management_heirarchy", "proxy/jwt_auth_arch", "proxy/image_handling"],},{type: "link",diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yamlindex 17658df9031..fe8d73d26aa 100644--- a/litellm/proxy/proxy_config.yaml+++ b/litellm/proxy/proxy_config.yaml@@ -4,3 +4,12 @@ model_list:model: openai/fakeapi_key: fake-keyapi_base: https://exampleopenaiendpoint-production.up.railway.app/++general_settings:+ use_redis_transaction_buffer: true++litellm_settings:+ cache: True+ cache_params:+ type: redis+ supported_call_types: []\ No newline at end of file