How to fix cosmos db latency in non primary region

Chaitanya Singh 20 Reputation points Microsoft Employee
2024-11-05T16:45:35.3966667+00:00

We are using Azure CosmosDB with both EUS/WUS regions in PPE environment. We are observing more latency in WUS region. In our EUS service the Read latency is below 100 ms which is the CosmosDB primary region. But Read latency is around 400ms our WUS service. So can you suggest how to reduce it, is there any settings. Also, we are using azure-spring-data-cosmos java library. And the diagnostic logs from the library always shows that our EUS/WUS service try to connect with physical address rntbd://<cosmosdbname>-eastus-documents.azure.comimage (3)

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,671 questions
0 comments No comments
{count} votes

Accepted answer
  1. NIKHILA NETHIKUNTA 3,265 Reputation points Microsoft Vendor
    2024-11-05T18:35:10.2+00:00

    @Chaitanya Singh
    Thank you for the question and for using Microsoft Q&A platform.

    It sounds like you’re experiencing higher latency in the West US (WUS) region compared to the East US (EUS) region for your Azure Cosmos DB. Here are a few suggestions to help reduce the latency:

    1. Ensure Preferred Region Is Set Correctly in Client SDK
    1. Check Connection Mode and Protocol
    • Since you’re observing rntbd:// in diagnostic logs, this means the SDK is using direct (TCP) mode.
    • While direct mode is usually faster, if network or routing issues are affecting latency, try switching to gateway (HTTPS) mode for the WUS service to see if it reduces latency. This change can sometimes alleviate latency issues caused by direct TCP connections in complex network environments.
    1. Adjust Consistency Level for WUS Service
    • With multi-region writes, using a less stringent consistency level can reduce latency further.
    • Try using session or consistent prefix consistency for WUS to strike a balance between consistency and latency.
    • This approach is especially helpful when there’s high read latency but consistent reads from the same region are required.
    1. Monitor Replication Latency in Azure Monitor
    • Multi-region setups can sometimes have replication lag between regions. Azure Monitor can show if there’s any delay in data replication from EUS to WUS.
    • In the Azure Portal, navigate to Metrics under your Cosmos DB account and look for Replication Latency for each region.
    • If WUS is experiencing significant replication latency, this may cause stale data reads or increased read latency.
    1. Analyze Diagnostic Logs and Azure Insights
    • Diagnostic logs from the azure-spring-data-cosmos library and Application Insights can help pinpoint specific calls that have higher latency.
    • Look at metrics like Request Latency by Region to see if specific requests (e.g., queries, inserts, etc.) are more prone to latency in WUS.

    For more information, please refer to these links:
    https://video2.skills-academy.com/en-us/java/api/overview/azure/spring-data-cosmos-readme?view=azure-java-stable
    https://video2.skills-academy.com/en-us/azure/cosmos-db/consistency-levels
    https://video2.skills-academy.com/en-us/azure/cosmos-db/nosql/how-to-manage-consistency?tabs=portal%2Cdotnetv2%2Capi-async
    https://video2.skills-academy.com/en-us/azure/cosmos-db/nosql/sdk-connection-modes
    https://video2.skills-academy.com/en-us/azure/cosmos-db/consistency-levels#write-latency-and-strong-consistency
    https://video2.skills-academy.com/en-us/azure/cosmos-db/monitor-server-side-latency
    https://video2.skills-academy.com/en-us/java/api/com.azure.cosmos.cosmosclientbuilder?view=azure-java-stable

    If the above steps do not help for resolving the issue, if you have a support plan could you please file a support ticket for deeper investigation and do share the SR# with us? In case if you don't have a support plan please let us know here.

    Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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