As you may know, Google has increased the price of their Maps APIs more than 10x since July 16, 2018. Naturally, this has caused a lot of grief for projects which make heavy use of Google Maps APIs. Another point to consider is that most of the competitors of Google Maps APIs don’t have sufficiently advanced implementations for many complex use cases. Hence for at least the next 3-4 years, most of the logistics apps will be required to use Google Maps APIs. Hence it’s critical to put together some good programming guidelines to ensure that you are using Google Maps optimally and don’t get charged an astronomical sum, in case your app sees good traction.
Since at Mobisoft, we create a lot of advanced logistics and on-demand booking systems, Google Maps APIs are an important part of our solutions. Hence we have put together following the set of guidelines to ensure optimal usage Google Maps APIs:
Create separate Gmail account for billing for each of your clients
Create a separate Gmail account for Google Maps for every project and enable billing on it. This is just good management practice. By making a separate billing account for each of your projects for your different clients, you can isolate the billing and API usage per application very quickly. This also makes reporting easy for your clients.
Also, make sure that all the emails from this account are forwarded to your common alerting and monitoring email. This way you can ensure that none of the warning emails get lost in an obscure unused account.
Enable Budget Alarms
This is another standard cloud programming practice that one should follow. All your “pay as you go” vendor accounts should have budget alarms set. This way if your application suddenly becomes very popular, you can get the budgeting alarm early. This will help you to ensure that there are those additional funds available to support such demand.
Enable only those APIs which are required by your system
Google Maps and Places API suite comes with around 14 different APIs. A lot of programmers have a tendency to enable all of these APIs for their systems. This is just a laziness on the behalf of the programmers. One should not enable the APIs which are not needed by the system. This helps you to isolate excessive API usage patterns later. Also if in case your API keys get leaked somehow, attackers can abuse an only limited number of features which have been enabled for those keys. Some of the new APIs, such as Find Places, Advanced Distance Matrix API, Roads API, have become very expensive. So make sure that they are not enabled if not required so that you can be sure, that your junior team members don’t use them accidentally without proper peer review.
Specify restrictive API quotas
By default, most of the default quotas allocated by Google are too generous. You should evaluate the API call requirements with careful analysis. Extrapolate those numbers with the estimated traffic that your application will receive. Based on these numbers you should set restrictive quotas for each of the required Google Maps API. Later during the monitoring phase, you can always increase the allocated quotas as needed.
Document all the use cases which use Google Maps APIs
Ensure that all your use cases which use Google Maps APIs are documented properly in a separate document. Make sure that this document is updated from time to time as new use cases are implemented. This will help you later during the capacity planning stage to decide quotas for various Google Maps APIs.
Pay attention to use cases which call Google Maps APIs periodically
The use cases which need to call Google Maps APIs periodically are the worst offenders. Isolate such use cases and try to optimize them as much as possible. Never do something like, call directions API on every location update. If you need to call some API periodically, try to use the biggest possible time interval possible. Discuss the use case with your client and make sure that they understand the cost implication of these use cases. Come up with creative ways so that such features are activated by users only when they are necessary.
Avoid full map reloads
While creating logistics reporting dashboards, clients often demand that such dashboards should auto refresh with the latest data. Discuss with the client if the whole dashboard needs to be refreshed. You can give options to refresh only certain portions of the dashboard periodically, which others can be refreshed manually. The dashboard queries also OLAP in nature and put a lot of stress in your database. From the Google Maps API usage point of view, you should avoid full page refresh. Instead, use AJAX calls to bring the latest asset tracking locations and redraw only the relevant pins on the map.
Create different API keys for different sub-projects
Most likely your logistics application will have different sub-projects such as iOS frontend, Android frontend, Web frontend, Admin backend, etc. For all such projects create different Google Maps APIs keys. This way in the Google Maps API console, you can track the usage of the APIs by different clients. This helps you to identify the clients which are consuming excessive API calls.
Restrict Google Maps API keys by different clients
Google allows you to restrict API keys to be used on specific subdomains, from Apps with specific client IDs. These restrictions should always be followed. This will help you to prevent misuse of your API keys if any of them gets leaked. It’s a very simple security practice which should always be followed.
Don’t hardcode your APIs keys in the frontend clients
Don’t ever hardcode the API keys in your client applications. They should be fetched from the server periodically. This allows you to rotate the keys frequently. This prevents the possible misuse of your Google Maps keys. Don’t transmit API keys in plain text over the internet. Always use HTTPS. Also while using HTTPs you might also want to encrypt your API keys some additional secret. Also, use SSL certificate pinning if possible.
Encourage your clients to opt for Google’s volume usage plan
The way current Google Maps pricing is structured, the “pay as you go” pricing plan for Google Maps API can quickly become very costly for most of the serious applications. Encourage your clients to get in touch with Google sales team to discuss various options for Google Maps Volume usage plan. This will allow your clients to plan their budget with clear visibility and alleviate fears of a sudden large unanticipated bill from Google.
Google Maps APIs though expensive are a necessary requirement for complex on-demand logistics solutions. With careful planning, you can make sure that you don’t end up paying too much for these mapping features. I hope this article has given you enough ideas to optimize your Google Maps API usage.
If you are planning an on-demand logistics application to give your business a strategic edge, then why not get in touch with us? We deal with complex logistics planning related applications daily. We can definitely provide you with optimal solutions on this front. Looking forward to hearing from you!
Pritam Barhate, with an experience of 11+ years in technology, heads Technology Innovation at Mobisoft Infotech. He has a rich experience in design and has been a consultant for a variety of industries and startups. At Mobisoft Infotech, he primarily focuses on technology resources and develops the most advanced solutions. Follow him @pritambarhate