APIs Are Not In the Efficiency Business

Dated Apr 11, 2020; last modified on Mon, 05 Sep 2022

CityFlo Reduces Google Maps API Bill by 94%

Google Directions API limited their free tier . CityFlo uses this API to calculate ETAs. Initially, CityFlo queried the API every time a stop was registered.

This was the problem. The number of API calls should be dependent on the stops themselves, not the buses. For an MVP, sure - make that query - but if you’re running a growing business, those calls add up!

With some pre-processing, one can reduce the number of API calls. Because the stops, \(S\), are well-defined, we can enumerate ordered pairs \((a, b)\) where \(a, b \in S \) and stop \(a\) is adjacent to stop \(b\). Any trip in the system can be expressed as the sum of several pairs.

CityFlo’s solution was similar to the construction above. Additionally, CityFlo used linear interpolation to give ETAs for locations that are not in \(S\).

However, a linear extrapolation may not always be correct, e.g. a traffic accident.

If such a change slashes API usage by 94%, what incentive does Google have to promote efficient API calls?

All the Restrictions Have Been On Display in the ToS; Don’t Make a Fuss Now

Having a pool of free-tier API keys reads like textbook fraud. But smart caching is looks a bit more nuanced.

The general terms prohibit scraping, caching, derivative content, use with non-Google maps, circumventing fees, use in embedded vehicle systems, etc. The more specific terms allow caching of latitude/longitude data .

The meat is in the ETA estimates though, so I don’t know how much caching will help. Furthermore, if one could cache ETA estimates, then one could somewhat get enough trend data to not need Google Maps.

Open-Source to the Rescue?

To turn latitude/longitude pairs into place names, OfflineReverseGeocode used a creative commons placename database provided by GeoNames .

The Open Source Routing Machine (OSRM) could use more data. With a good Kalman filter, one can get achieve ETAs. However, how can fancy statistics on historical data match up to Google’s live feed of Android devices? Furthermore, OSRM is running short on maintainers.

Android is designed such that keeping the location services running is the easier thing to do (dark pattern?). This data ends up making Google hard to beat.

Kalman filtering takes in a series of measurements observed over time and produces estimates of unknown variables that tend to be more accurate than those based on a single measurement. The increased accuracy results from estimating a joint probability distribution over the variables for each timeframe. Kalman filter - Wikipedia

References

  1. How we reduced our Google Maps API cost by 94%. Sudhanshu Mishra. blog.cityflo.com . Apr 2, 2020.
  2. HN Discussion: How we reduced our Google Maps API cost by 94%. news.ycombinator.com . Apr 4, 2020.
  3. Google Maps Platform Terms of Service | Google Cloud. cloud.google.com . cloud.google.com .