Optimizing Web Service Usage


If your application exceeds the usage limits for a Google Maps Platform web service, the service returns an error message. If your application continues to exceed the usage limits, it might be blocked from accessing the web service and, in some cases, receive "403 Forbidden" responses.

If your application’s web service requests receive error messages, you can do the following:

  1. Lower usage by optimizing applications to use the web services more efficiently.
  2. Increase usage limits, when possible, by purchasing additional Maps APIs Credits.

Before you begin

Before optimizing your application’s web service usage, check that you’re using the correct service for your use case and the correct Maps APIs license.

Validate your use case

Google Maps Platform web services are best for applications that don’t require real-time input from users or when a web browser is not used. For example, you should use web services if your application uses a dataset that is independent of user input—for example, a fixed set of addresses on a real estate web site that needs to be geocoded.

Note that with web services, the queries-per-second (QPS) limit applies to your Premium Plan license, regardless of how many IP addresses requests are sent from.

On the other hand, the client-side services available with the Maps JavaScript API are rate limited per browser session, so that requests are distributed across all your users and scale as the number of users grows. Therefore, client-side services are best for applications that geocode address input from users in real time, such as a store locator that searches for stores near a user’s home address.

For a more detailed discussion on when to use web services, see Geocoding Strategies. Although specific to geocoding, the recommendations in this document apply to all web services, explaining when you should use server-side web services or their client-side equivalents.

Use your Google Maps APIs Premium Plan license

Make sure your application’s requests include the correct authentication details for your Google Maps APIs Premium Plan license—that is, your client ID or an API key from your Premium Plan project in the Google Cloud Platform Console.

If your application doesn’t use the Premium Plan license correctly, it’s subject to the Standard Plan usage limits and the license restrictions in the Google Maps Platform Terms of Service. It isn’t covered by the Premium Plan SLA. In addition, you won’t receive technical support for the application.

How to optimize web service usage

To use web services more efficiently, you can lower usage by sending requests only when necessary and spreading usage evenly to keep it under the limits.

Cache results

Section 10.5.d of the Google Maps Platform Terms of Service specifies that you can temporarily cache Google Maps data, for a period of up to 30 days, to improve performance of your application. By caching web service responses, your application can avoid sending duplicate requests over short periods of time. In fact, web service responses always include the Cache-Control HTTP header, which indicates the period for which you can cache the result—for example, Cache-Control: public, max-age=86400. For efficiency, ensure your application always caches results for at least the amount of time specified in this header, but no more than the maximum time specified in the Google Maps Platform Terms of Service.

You can implement caching using web proxies, most of which perform this function out of the box. Or, you can use your own web proxy implementation. Note that some HTTP client libraries also cache HTTP responses.

To increase cache hit rates, make sure you normalize latitude/longitude (lat/long) coordinates by rounding to 6 decimal places, which provides a precision of about 11 centimeters around the equator. If you add more decimals, results from web services won’t change but cache hit rates will decrease.

Throttle requests

To avoid exceeding usage limits, you can configure your application to throttle requests, by placing them in a queue that keeps track of when the requests are sent. If your application receives one additional request beyond the QPS limit, it should check the timestamp of the first request and wait 1 second.

Even with throttling, applications might still receive responses with the status code OVER_QUERY_LIMIT. Configure your application to insert a small delay (20 ms) and try again if it receives such response.

Increase QPS limit

If you implement throttling correctly, your application should not send requests in excess of the usage limits. However, your application might receive input that’s too large or at a higher speed than allowed by the Google Maps Platform web service usage limits (typically, 50 QPS). In this case, the throttling queues can become large, creating a backlog of requests. Also, the Places API is initially limited to 50 QPS. If your application consistently receives such a backlog, either at specific times each day or throughout the day, you might need to increase the QPS limits for your Google Maps APIs Premium Plan license. To request a QPS increase, contact your Google Maps Platform Sales Account Manager.