Overcoming Challenges with Azure Translation Service

Nikita P. Patil
Villa Plus Engineering
4 min readApr 15, 2024

In today’s interconnected world, the demand for seamless translation services has never been higher. As businesses expand globally and audiences become increasingly diverse, the need to bridge language barriers is paramount. Amidst this landscape, Azure Translation Service stands as a beacon of hope, offering powerful capabilities to facilitate cross-lingual communication.

However, like any technology solution, its implementation is not without its challenges. In this blog post, we’ll explore some of the hurdles encountered and the strategies employed in overcoming them.

Use case where we used machine translation

In our project, we are using Prismic as a Content Management System (CMS).

Traditionally, managing multilingual content has been a labor-intensive task, requiring following steps:

1. Content Creation in Prismic: Our team diligently enters all information pertaining to a specific document within the Prismic platform. This includes text, images, and other relevant media elements.

2. Language-Specific Content Entry: Next, our team meticulously enters language-specific content for each supported language variant of the document. This step ensures that our content is tailored to the linguistic preferences of our diverse audience base.

3. Then the text will be reflected on the website

For any single change, our team needs to make changes in all related documents.

Ex: If the website supports 20 languages, then for a single change team needs to change all 20 documents.

Solution: To reduce manual efforts we started using Azure translation service to translate information from Prismic

Overcoming Challenges in Translation Service: Technical Solutions

During our journey of working with translation services, we encountered several challenges that hindered our workflow. In this blog, we will explore the technical solutions we implemented to address those challenges effectively.

Challenges Faced

1. Request Quota Exceeded Errors

When our translation service requests exceeded the predefined quota, we encountered errors indicating the quota was exceeded, impacting our translation processes.

2. “Too Many Requests” Errors

Similarly, encountering errors due to too many requests hindered the smooth operation of our translation service, leading to disruptions in our workflow.

3. Cost Management

If your usage of the Azure Translation Service has increased, it’s natural for the cost to go up accordingly. More translations mean more computing resources are utilized, leading to higher charges

Technical Solutions Implemented

1. Cost Management

a. Caching and Hashing Mechanism

To mitigate the need for unnecessary translation requests, we introduced a caching and hashing mechanism. Here’s how it works:

· We store translated data in a database with an additional column for the hashed value of content.

· Before sending a translation request to Azure Translation Service, we compare the hashed value of the input content with the hashed value stored in the database.

· If the values match, it indicates no changes in the data, and we retrieve the existing translated data from the database.

· If the values differ, we proceed with sending the translation request and store the translated information in the database.

2. Request Quota Exceeded Errors

a. Use of Caching

· To reduce the overall number of translation requests and optimize performance, we leveraged caching:

· If the same text is translated frequently, we cache the translated results locally.

· We are comparing existing saved data in DB and new data and only changed part of the data we are sending to the translation service.

· This reduces the need for repeated translation requests and the size of requests will become small, leading to a more efficient translation process.

· The request limit depends on the subscription we used for a translator.

3. “Too Many Requests” Errors

a. Optimizing Batch Size

Instead of making multiple small requests, we optimized our translation requests by batching multiple translations into a single larger request. If the data is not that much.

· This reduces the number of HTTP calls made to the service, helping us stay within the rate limits and improving efficiency.

b. Implementation of Chunking Technique:

In our specific case, we opted for the technique of dividing data into chunks. This approach not only allows us to effectively handle large volumes of data but also ensures optimal performance and reliability throughout the translation process. This ensures that if data is too big then sending chunks of data with a delay will prevent exceeding character limits to translation service.

c. Implementing Exponential Backoff

· To handle errors caused by exceeding the limit of characters translated within a minute (error code 429), we implemented exponential backoff:

· This technique involves retrying the translation request with increasing delays, allowing the service to recover and respond effectively.

 private const int _maxRetries = 3;
private const int _baseDelayMs = 1000;
private string BuildTranslationRequest(string textToTranslate, string route)
{
int retries = 0;
while (retries < _maxRetries)
{
try
{
HttpResponseMessage response = GetResponseFromTranslateAPI(textToTranslate, route);
if (response.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
{
Task.Delay(GetDelay(retries));
retries++;
}
if(response.IsSuccessStatusCode)
{
return response.Content.ReadAsStringAsync().Result;
}
}
catch (Exception ex)
{
retries++;
}
}
return "";
}
private int GetDelay(int retries)
{
return _baseDelayMs * (int)Math.Pow(2, retries);
}

In conclusion, while Azure Translation Service offers powerful capabilities for multilingual communication, it does come with its own set of challenges. These challenges primarily revolve around the limitations imposed by subscription plans, including character limits and request quotas.

It is essential to optimize code, implement caching mechanisms, and monitor usage closely. Additionally, considering rate limiting and upgrading subscription plans can also help mitigate these issues.

--

--