Azure Cosmos DB (MongoDB): Metadata Throttling (429/3200) on startup #8619
Unanswered
thefunny1983
asked this question in
Troubleshooting
Replies: 2 comments
-
This does not always happen though, only once in a while :-) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Since CosmosDB is not officially supported by the project (only mongodb), and it’s not easily stood up on my end, I would suggest you try some changes to the database handling, report back, and contribute if you’re open to it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What happened?
When using Azure Cosmos DB as the database backend, LibreChat encounters frequent rate-limiting errors on startup. The specific error is HTTP 429 TooManyRequests with a Cosmos DB substatus of 3200.
This indicates that the application is being throttled for making too many metadata requests (e.g., checking if a container exists), not for exceeding provisioned Request Units (RU/s). This suggests an issue with the database initialization pattern.
Root cause analysis
The root cause is not insufficient RUs but an application pattern that repeatedly makes metadata calls to Cosmos DB. The Cosmos DB SDK best practice is to perform initialization checks only once per application lifecycle.
The issue likely stems from the application code calling methods like CreateDatabaseIfNotExistsAsync or CreateContainerIfNotExistsAsync frequently, perhaps in a loop or on every request, instead of once at application startup.
Proposed Fix:
Refactor the Cosmos DB initialization logic to adhere to best practices:
Use a Singleton CosmosClient: Ensure a single instance of the CosmosClient is created and reused for the application's lifetime.
Initialize Once: Perform database and container existence checks (e.g., CreateContainerIfNotExistsAsync) only once when the application process starts.
Cache Resources: The resulting container and database objects should be cached in memory and reused for all subsequent operations.
This change will prevent the application from hitting the metadata rate limits and ensure a more stable and efficient integration with Azure Cosmos DB.
Version Information
ghcr.io/danny-avila/librechat-dev latest e9b3ab7eba0d 3 days ago 1.1GB
ghcr.io/danny-avila/librechat-rag-api-dev-lite latest 8858d2bd9ff5 12 days ago 1.48GB
ghcr.io/virtuos/librechat_exporter main 3012a75299b4 6 weeks ago 283MB
Steps to Reproduce
Configure LibreChat to use an Azure Cosmos DB for NoSQL endpoint.
Start the LibreChat application.
Observe the logs during the initialization phase.
What browsers are you seeing the problem on?
No response
Relevant log output
Screenshots
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions