<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rami Yakoub on Medium]]></title>
        <description><![CDATA[Stories by Rami Yakoub on Medium]]></description>
        <link>https://medium.com/@ramiyakoub?source=rss-926464f1733c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*e66P1F6mDHMODijv5IFvDg@2x.jpeg</url>
            <title>Stories by Rami Yakoub on Medium</title>
            <link>https://medium.com/@ramiyakoub?source=rss-926464f1733c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 15:48:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ramiyakoub/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Let Bots Handle the Boring Stuff: Automating Dependency Updates with GitHub Actions & Dependabot]]></title>
            <link>https://ramiyakoub.medium.com/automating-dependency-updates-with-github-actions-0411bca56050?source=rss-926464f1733c------2</link>
            <guid isPermaLink="false">https://medium.com/p/0411bca56050</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[dependabot]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Rami Yakoub]]></dc:creator>
            <pubDate>Tue, 21 Oct 2025 16:04:14 GMT</pubDate>
            <atom:updated>2025-10-21T16:05:53.004Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How we turned hours of manual dependency babysitting into a hands-free automation flow.</em></p><p><strong>The Problem: Mundane Reality of Multi-Repo Dependency Maintenance</strong></p><p>Managing dependencies in a multi-repository architecture can get… messy. Especially when maintaining a bunch of internal packages that depend on each other in a long domino effect of releases, PRs, and version bumps across multiple repositories.</p><p>That was exactly our reality at <a href="https://ergeon.com/">Ergeon</a>. Our team was spending an unreasonable amount of time every week <strong>babysitting dependency updates</strong> — waiting on CI pipelines, merging Dependabot PRs, bumping versions, releasing tags, and repeating the same routine across several repos. It wasn’t difficult work — just repetitive, boring, and expensive in terms of developer attention.</p><p>So, during one of our <a href="https://www.thoughtworks.com/insights/blog/why-your-company-should-adopt-innovation-days">innovation days</a>, I decided to do something about it.</p><p><a href="https://docs.github.com/en/code-security/getting-started/dependabot-quickstart-guide"><strong>Dependabot</strong></a> — GitHub’s dependency management tool — was already helping us a lot. It automatically checks for outdated dependencies and opens pull requests to update them. It’s great for managing both external and internal dependencies. But when you have a <strong>chain of internal dependencies</strong>, things get complicated.</p><p>To make this story easier to visualize, imagine a <strong>restaurant app ecosystem</strong> built as a set of interdependent repositories — each handling a different part of the business:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*1yZo4PTKqUFEFiuGGIzZGQ.png" /><figcaption><em>The restaurant app dependency chain — changes flow from bottom to top through multiple layers.</em></figcaption></figure><p>At the foundation, we have the ingredient-catalog package that defines all available ingredients and their properties. On top of that, we have recipe-lib (which combines ingredients into recipes) and pricing-lib (which calculates costs based on ingredient prices). These feed into menu-builder, which organizes recipes into menus, and kitchen-system, which handles the operational side of the restaurant. Finally, our top-level restaurant-app brings together both the kitchen operations and menu management.</p><p><em>And honestly, thinking about this analogy — I kind of wish I was in the food industry. Free pizza samples? Worth it.</em></p><p>Now, imagine needing to update ingredient-catalog — maybe we’re adding nutritional information or introducing a new seasonal ingredient. That change needs to travel up through the entire dependency chain before it reaches restaurant-app. Manually, that looks like this:</p><pre>1. Release `ingredient-catalog` with your changes<br>2. Trigger Dependabot in `recipe-lib` and wait till it opens the PR<br>3. Review, approve, and merge the Dependabot PR in `recipe-lib`<br>4. Release the new version of `recipe-lib` and wait till its CI/CD is done<br>5. Trigger Dependabot in `pricing-lib` and wait till it opens the PR<br>6. Review, approve, and merge the Dependabot PR in `pricing-lib`<br>7. Release the new version of `pricing-lib` and wait till its CI/CD is done<br>8. Trigger Dependabot in `menu-builder` and wait till it opens the PR<br>9. Review, approve, and merge the Dependabot PR in `menu-builder`<br>10. Release the new version of `menu-builder` and wait till its CI/CD is done<br>11. Trigger Dependabot in `kitchen-system` and wait till it opens the PR<br>12. Review, approve, and merge the Dependabot PR in `kitchen-system`<br>13. Release the new version of `kitchen-system` and wait till its CI/CD is done<br>14. Trigger Dependabot in `restaurant-app` and wait till it opens the PR<br>15. Review, approve, and merge the Dependabot PR in `restaurant-app`</pre><p>This process can easily take <strong>2–4 hours</strong>, largely due to waiting on CI/CD pipelines at nearly every step — with each build and test suite taking 10–15 minutes. It’s tedious and error-prone. Version mismatches can slip through, and the cognitive overhead of tracking which repositories are at which version is substantial. Clearly, this wasn’t sustainable.</p><p><strong>The Solution: Dependabot + GitHub Actions</strong></p><p>We needed a way to automate the entire dependency chain, so our team could focus on real development instead of babysitting PRs. While Dependabot opens update PRs, it doesn’t propagate changes through multiple internal packages automatically. That’s where <a href="https://docs.github.com/en/actions"><strong>GitHub Actions</strong></a> come in.</p><p>By combining Dependabot with custom workflows, we built a fully automated flow that takes a single dependency update and propagates it all the way up to the top-level application. Our approach revolves around two main workflows: <strong>Auto-Merge</strong> and <strong>Auto-Release</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H4o8H9QLSSD3N2dX72bjdA.png" /><figcaption><em>The automated flow: Dependabot opens PRs, Auto-Merge approves internal packages, and Auto-Release tags new versions in a continuous loop.</em></figcaption></figure><p><strong>Auto-Merge</strong></p><p>Previously, Dependabot supported auto-merge natively. However, after it became a GitHub-native feature, GitHub announced that auto-merge would not be supported for the foreseeable future. The reasoning is that automatically merging updates could potentially propagate a malicious package quickly across the ecosystem, so GitHub recommends always verifying dependencies before merging — which makes complete sense, especially for external packages.</p><p>Though, even when the native solution was available, it wouldn’t fully meet our needs.</p><p>In our case, we wanted to <strong>enable auto-merge</strong> and <strong>automate version bumping</strong> for <strong>internal packages only</strong>. While there’s still a minor risk of broken releases, the impact remains low due to the limited scope and controlled nature of our internal packages. That’s why we prioritized speed and flexibility over additional safeguards — and ultimately implemented our own Auto-Merge workflow.</p><p>Our Auto-Merge workflow takes care of approving and merging internal dependency updates automatically. The workflow is triggered whenever Dependabot opens a pull request for an internal package. It first bumps the version of the package (all tests and lints automatically run via CI), and approves and merges the PR if everything passes.</p><p>By using GitHub’s workflow_call, we implemented the core Auto-Merge logic once in a root repository (utils-js) and then reused it across all internal packages. Each internal package calls this root workflow whenever Dependabot opens a PR. While the main workflow in utils-js is triggered via workflow_call, a typical repository configures a lightweight YAML that listens to pull request events and invokes the root workflow, like this:</p><pre>name: Pizzeria Dependency Merge Trigger<br><br>on:<br>  pull_request:<br>    types: [opened, reopened]<br>    branches: [develop]<br><br>jobs:<br>  auto-merge:<br>    uses: pizzeria/utils-js/.github/workflows/pizzeria-dependency-merge.yml@master<br>    with:<br>      skip_version_bump: true<br>    secrets: inherit</pre><p>This approach separates <strong>what</strong> happens during auto-merge (centralized in utils-js) from <strong>when</strong> it happens (triggered in each repo on Dependabot PRs), keeping the workflow DRY, easy to maintain, and fully automated across all internal packages.</p><p>Here’s an example of the main Auto-Merge workflow in utils-js:</p><pre>name: Pizzeria Dependency Merge<br><br>on:<br>  workflow_call:<br>    inputs:<br>      skip_version_bump:<br>        description: &quot;Skip version bumping for application repositories&quot;<br>        required: false<br>        type: boolean<br>        default: false<br><br>permissions: write-all<br><br>jobs:<br>  auto-merge:<br>    if: |<br>      github.actor == &#39;dependabot[bot]&#39; &amp;&amp; <br>      contains(github.event.pull_request.title, &#39;Bump @pizzeria/&#39;)<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Checkout Repository<br>        uses: actions/checkout@v4<br><br>      - name: Set up Node.js<br>        uses: actions/setup-node@v4<br>        with:<br>          node-version: 18<br><br>      - name: Bump Version<br>        if: ${{ !inputs.skip_version_bump }}<br>        run: |<br>          CHANGELOG_MESSAGE=&quot;${{ github.event.pull_request.title#*] }}&quot;<br>          make bump version=&quot;patch&quot; message=&quot;$CHANGELOG_MESSAGE&quot;<br>          git push origin HEAD<br><br>      - name: Generate GitHub App Token<br>        id: app-token<br>        uses: tibdex/github-app-token@v1<br>        with:<br>          app_id: ${{ secrets.PIZZERIA_DEPENDENCY_APP_ID }}<br>          private_key: ${{ secrets.PIZZERIA_DEPENDENCY_APP_PRIVATE_KEY }}<br><br>      - name: Approve and Merge<br>        run: |<br>          gh pr review ${{ github.event.number }} --approve --body &quot;Auto-approved @pizzeria dependency update&quot;<br>          gh pr merge ${{ github.event.number }} --auto --squash<br>        env:<br>          GH_TOKEN: ${{ steps.app-token.outputs.token }}</pre><p>For application repositories like restaurant-app, we set skip_version_bump to true because we don’t want to bump versions there; merging the PR is enough to trigger deployments.</p><p>Once Auto-Merge was in place, the next challenge was making sure new versions actually got released — that’s where Auto-Release comes in.</p><p><strong>Auto-Release</strong></p><p>Auto-Release ensures that once a dependency update is merged, a new version and Git tag are automatically created so that the next package in the chain sees the update. This keeps the entire flow moving without manual intervention.</p><p>Just like Auto-Merge, the core Auto-Release logic lives in a central workflow in utils-js — here’s an example workflow for tagging and releasing:</p><pre>name: Pizzeria Tag Release<br><br>on:<br>  workflow_call:<br><br>jobs:<br>  auto-tag:<br>    if: |<br>      github.event.head_commit.author.name == &#39;dependabot[bot]&#39; &amp;&amp;<br>      contains(github.event.head_commit.message, &#39;Bump @pizzeria/&#39;)<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Checkout Repository<br>        uses: actions/checkout@v4<br><br>      - name: Create and Push Tag<br>        run: |<br>          git config user.name &#39;github-actions[bot]&#39;<br>          git config user.email &#39;github-actions[bot]@users.noreply.github.com&#39;<br><br>          VERSION=$(node -p &quot;require(&#39;./package.json&#39;).version&quot;)<br>          TAG=&quot;v$VERSION&quot;<br><br>          if git rev-parse &quot;$TAG&quot; &gt;/dev/null 2&gt;&amp;1; then<br>            echo &quot;Tag $TAG already exists&quot;<br>            exit 0<br>          fi<br><br>          make tag</pre><p>Each internal package triggers this workflow after a merge, releasing a new version that Dependabot then picks up in dependent packages — effectively closing the loop and automating the entire chain.</p><p>A lightweight trigger YAML in a package might look like this:</p><pre>name: Pizzeria Tag Release Trigger<br><br>on:<br>  push:<br>    branches: [master]<br>    paths: [&quot;package.json&quot;, &quot;package-lock.json&quot;]<br><br>jobs:<br>  auto-tag:<br>    uses: pizzeria/utils-js/.github/workflows/pizzeria-tag-release.yml@master<br>    secrets: inherit</pre><p>With Auto-Merge and Auto-Release together, any change in a foundational package like ingredient-catalog now flows all the way to restaurant-app without a single manual step. Developers no longer need to track dozens of Dependabot PRs or worry about version mismatches — the system handles it reliably in the background. On top of that, we leveraged Dependabot’s <a href="https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference#groups--">grouping</a> feature, which merges related updates together. This not only accelerates the propagation of changes but also keeps the number of automated PRs manageable, providing a cleaner and more predictable workflow.</p><p><strong>Conclusion: Automate the Busywork, Reclaim Developer Time</strong></p><p>What started as a small experiment to save a few hours a week quickly became one of the most impactful internal improvements we’ve made. Automating dependency updates wasn’t just about speeding up pipelines — it was about freeing developers from repetitive, low-value work and letting them focus on the parts of engineering that actually require human creativity.</p><p>By combining Dependabot with GitHub Actions, we built a system that keeps our repositories in sync, eliminates version drift, and ensures dependency updates propagate reliably from the bottom of the chain to the top — all without manual intervention.</p><p>This approach works best for <strong>trusted internal packages</strong>, while external dependencies still require careful review.</p><p>In short: if a task feels tedious but predictable — it’s a perfect candidate for automation. Invest once, and let the bots handle it forever. Your future self (and your team) will thank you for it.</p><p><em>How do you currently handle dependency updates in your multi-repo projects? What strategies have you found effective?</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0411bca56050" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Engineering a Geospatial Caching Solution When Google Maps Became Expensive]]></title>
            <link>https://ramiyakoub.medium.com/when-google-maps-got-expensive-geospatial-caching-solution-e4e0719c7ac7?source=rss-926464f1733c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4e0719c7ac7</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[google-maps]]></category>
            <dc:creator><![CDATA[Rami Yakoub]]></dc:creator>
            <pubDate>Mon, 22 Sep 2025 16:01:27 GMT</pubDate>
            <atom:updated>2025-09-24T06:03:41.312Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How we optimized Google Maps API usage from $12K/month to pennies with smart caching and approximation strategies</em></p><p><strong>When Google Maps Got Expensive</strong></p><p>At <a href="https://www.ergeon.com/">Ergeon</a>, a review of infrastructure costs revealed something unexpected: <strong>Google Maps APIs were taking a surprisingly large slice of the budget.</strong> Most of it came from two APIs — Geocoding and Elevation — which were deeply integrated into our tools but hadn’t been scrutinized in a while.</p><p>At first glance, these APIs seemed harmless: just a few cents per request, nothing to worry about. But at scale, the costs stacked up quickly — and the performance wasn’t optimal either. That kicked off a deeper look into how we were using Google Maps, ultimately leading to an optimization project that saved thousands of dollars every month while improving the user experience.</p><p><strong>The Problem: Geocoding and Elevation at Scale</strong></p><p>Two Google Maps APIs were driving most of the cost:</p><ul><li><a href="https://developers.google.com/maps/documentation/geocoding"><strong>Geocoding API</strong></a><strong> </strong>— converts addresses into coordinates. We used it across our tools for handling customer and project locations.</li><li><a href="https://developers.google.com/maps/documentation/elevation/overview"><strong>Elevation API</strong></a><strong> —</strong> provides altitude for any given coordinate. This was essential for our CAD tool, which needed elevation data to generate accurate 3D previews of project sites.</li></ul><p>Individually, each call was cheap. But both APIs were being used in ways that triggered far more requests than necessary. Inefficiencies at the application level multiplied into millions of calls, inflating costs and slowing down workflows.</p><p><strong>Investigation &amp; Findings: Hidden Costs and Silly Bugs</strong></p><p>The Google Maps usage metrics immediately showed something was off: the number of API calls was far higher than expected given our traffic and active users. Initially, the suggestion from the team was to implement caching — a reasonable idea. But caching isn’t free: storing, querying, and maintaining cache data comes with its own costs. Before committing to that, I wanted to understand why the usage was so high in the first place.</p><p>For the <strong>Geocoding API</strong>, the culprit was surprisingly simple: multiple frontend packages were making unnecessary calls. The most expensive one triggered a request just to load the Maps JavaScript API via @googlemaps/js-api-loader, using a hardcoded default address before any user interaction. This 1.5-year-old oversight silently generated requests every time the page loaded.</p><p>The <strong>Elevation API</strong> was trickier. In the CAD drafting tool, users draw fences, gates, decks, and other structures on a map to generate quotes. Each object required the elevation of every point to calculate slopes for accurate pricing and material calculations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PfEPcgd9QzeyUbavR597TA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Ti8zmYwu7Wd0wVH8-5UFg.png" /><figcaption><em>The draft-editor where users draw fences, decks, and other structures.</em></figcaption></figure><p>Accurate elevation data isn’t just about terrain — it directly affects material requirements and quote calculations. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v4wKd5d6zG0_Lu6OQarPTA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d2k1cXtBhsNBOJTXlNe8qA.png" /><figcaption><em>Left: Fence without slope. Right: Fence with 30% slope, affecting material and pricing.</em></figcaption></figure><p>Every endpoint of a line, corner of a shape, or point on a fence triggered a separate API request. Users often moved, redrew, and adjusted objects multiple times during drafting a quote, generating repeated calls. Individually, the calls were cheap, but multiplied across dozens of objects per draft and user sessions, the cost and performance impact quickly became significant.</p><p>It also became clear that Google’s API limits were underutilized: the Elevation API allows 512 locations per request, yet requests were being made one point at a time. Since Google charges per request rather than per location, this meant we were paying for 512 individual requests when we could accomplish the same work with a single request. This highlighted an opportunity for optimization beyond simple caching.</p><p><strong>The Solution: Smarter Caching and Approximation</strong></p><p>To tackle the inefficiency, a smarter caching system was implemented, leveraging both <strong>approximation</strong> and <strong>batching</strong>. The idea was simple in concept but powerful in practice: instead of requesting the elevation for every individual point, elevations were precomputed and cached for a grid of coordinates covering the Earth, then any point’s elevation could be approximated using nearby cached values (caching every single sand grain on the planet would have been impossible, by the way).</p><p><strong>Grid-based Tiling</strong></p><p>The Earth was divided into imaginary 50×50 meter grid cells — centered at <a href="https://en.wikipedia.org/wiki/Null_Island">Null Island</a>. Each cell contained 100 points spaced 5 meters apart.</p><pre>EARTH_GRID_CELL_WIDTH = 50  # in meters<br>EARTH_INNER_GRID_CELL_WIDTH = 5  # in meters<br><br>COORDINATES_PER_GRID = (EARTH_GRID_CELL_WIDTH / EARTH_INNER_GRID_CELL_WIDTH)**2</pre><figure><img alt="A screenshot of the interactive map with an overlay showing the grid" src="https://cdn-images-1.medium.com/max/1024/1*6iFtTa1r4lIvEW5n5cyrbg.png" /><figcaption><em>Two adjacent 50x50 meter grid cells showing our earth-tiling system. Each cell contains 100 elevation points spaced 5 meters apart. Grid cells don’t share boundary points, ensuring no duplicate API calls.</em></figcaption></figure><p>The key challenge is determining which grid cell any given coordinate belongs to. The get_enclosing_grid_cell_center_point function solves this by converting latitude/longitude coordinates to a projected coordinate system (<a href="https://en.wikipedia.org/wiki/Web_Mercator_projection">Web Mercator</a>), then using integer division to snap to the nearest 50-meter grid boundary:</p><pre>def get_enclosing_grid_cell_center_point(coordinates: Union[List[float], Tuple[float, float]]) -&gt; Tuple[float, float]:<br>    # Convert the latitude and longitude to a projected coordinate system<br>    x, y = transform_to_x_y(coordinates[0], coordinates[1])<br><br>    # Calculate the coordinates of the southwest corner of the enclosing square<br>    x_min = int(x // EARTH_GRID_CELL_WIDTH) * EARTH_GRID_CELL_WIDTH<br>    y_min = int(y // EARTH_GRID_CELL_WIDTH) * EARTH_GRID_CELL_WIDTH<br><br>    # Calculate the coordinates of the center of the enclosing square<br>    x_center = x_min + (EARTH_GRID_CELL_WIDTH / 2)<br>    y_center = y_min + (EARTH_GRID_CELL_WIDTH / 2)<br><br>    # Convert the projected coordinates back to latitude and longitude<br>    lat_center, long_center = transform_to_lat_long(x_center, y_center)<br><br>    return lat_center, long_center</pre><figure><img alt="A screenshot of the interactive map" src="https://cdn-images-1.medium.com/max/1024/1*2AmCer6gDLnWPTKxGXEYhw.png" /><figcaption><em>The red marker indicates the house location, the black marker shows the center of its 50×50 m grid cell, the gray dots represent the 100 elevation points we fetch within that cell, and the blue markers denote the cell’s corner points.</em></figcaption></figure><p><strong>Batch Elevation Fetching</strong></p><p>Once we know the grid cell center, we can calculate the coordinates for all 100 points within that cell. The generate_grid_cell_coordinates function creates a 10×10 grid of points, each spaced 5 meters apart, starting from the southwest corner of the cell:</p><pre>def generate_grid_cell_coordinates(center_coordinates: Tuple[float, float]) -&gt; List[Tuple[float, float]]:<br>    # Convert the latitude and longitude to a projected coordinate system<br>    x_center, y_center = transform_to_x_y(center_coordinates[0], center_coordinates[1])<br><br>    # Calculate the coordinates of the southwest corner of the enclosing square<br>    x_min = x_center - (EARTH_GRID_CELL_WIDTH / 2)<br>    y_min = y_center - (EARTH_GRID_CELL_WIDTH / 2)<br><br>    num_of_rows = EARTH_GRID_CELL_WIDTH // EARTH_INNER_GRID_CELL_WIDTH<br><br>    inner_squares_centers = []<br>    for row in range(num_of_rows):<br>        for column in range(num_of_rows):<br>            x = x_min + (EARTH_INNER_GRID_CELL_WIDTH / 2) + (column * EARTH_INNER_GRID_CELL_WIDTH)<br>            y = y_min + (EARTH_INNER_GRID_CELL_WIDTH / 2) + (row * EARTH_INNER_GRID_CELL_WIDTH)<br>            # Convert the projected coordinates back to latitude and longitude<br>            lat, long = transform_to_lat_long(x, y)<br>            inner_squares_centers.append((lat, long))<br><br>    return inner_squares_centers</pre><p>Now, instead of asking Google “What’s the elevation at this one specific spot?” 100 times, we ask once: “What’s the elevation at these 100 spots?”</p><pre>elevation_api = ElevationAPI(GOOGLE_API_KEY)<br>grid_cell_elevation_results = elevation_api.get_elevation(*grid_cell_coordinates)[&#39;results&#39;]</pre><p>Google allows up to 512 locations per request, so we’re well within the limits while maximizing efficiency.</p><p><strong>Persistent Caching Strategy</strong></p><p>Once we have the elevation data for a grid cell from Google, it is stored in <a href="https://aws.amazon.com/dynamodb/"><strong>DynamoDB</strong></a>, indexed by the cell’s center coordinates. This allows quick lookups whenever a point’s elevation is needed, without hitting Google’s API repeatedly.</p><pre>DYNAMODB_CELL_CENTER_HASH_KEY = &#39;center&#39;<br>DYNAMODB_CELL_COORDINATES_HASH_KEY = &#39;coordinates&#39;<br><br>db_client.update_item(<br>    hash_key=DYNAMODB_CELL_CENTER_HASH_KEY,<br>    hash_value=f&#39;{center_coordinates[0]},{center_coordinates[1]}&#39;,<br>    new_props={DYNAMODB_CELL_COORDINATES_HASH_KEY: grid_cell_elevation_results[start_index: end_index]},<br>    serialize=True,<br>    return_item=True,<br>)</pre><p>The stored data structure contains all 100 elevation points for quick lookup:</p><pre>{<br>  &quot;center&quot;: &quot;37.33228647,-121.98335532&quot;,<br>  &quot;coordinates&quot;: [<br>    {<br>      &quot;elevation&quot;: 39.40275955200195,<br>      &quot;location&quot;: { &quot;lat&quot;: 37.33212576, &quot;lng&quot;: -121.98355745 }<br>    },<br>    {<br>      &quot;elevation&quot;: 39.35855484008789,<br>      &quot;location&quot;: { &quot;lat&quot;: 37.33212576, &quot;lng&quot;: -121.98351253 }<br>    }<br>    // ... 98 more elevation points covering this 50x50m cell<br>  ]<br>}</pre><p>With our grid cells now cached in the database, the backend infrastructure is complete. But having cached elevation data is only half the solution — we still need to deliver what the CAD tool actually requires: a precise elevation number (in meters) for any coordinates requested by users while drawing on the map.</p><p><strong>Client-Side Elevation Approximation</strong></p><p>When a user requests the elevation of a point in the CAD tool, the system identifies the four cached elevation points that <strong>enclose</strong> the target location and uses <a href="https://en.wikipedia.org/wiki/Bilinear_interpolation">bilinear interpolation</a> to estimate the elevation.</p><figure><img alt="A screenshot of the interactive map" src="https://cdn-images-1.medium.com/max/1024/1*dRj2cRwFk8mJAsLNIgBiUQ.png" /><figcaption><em>The red marker indicates the point where elevation is needed. The highlighted points are the four cached elevations that enclose it, used to calculate an approximate value.</em></figcaption></figure><p>First, we identify the four corner points of the 5×5 meter square containing our target location:</p><pre>export const getEnclosingInnerCellCornerCoordinates = (coordinates: GeoPoint): GeoPoint[] =&gt; {<br>  // delta = EARTH_INNER_GRID_CELL_WIDTH / 2 because our enclosing squares are actually<br>  // centers of the inner EARTH_INNER_GRID_CELL_WIDTH x EARTH_INNER_GRID_CELL_WIDTH squares<br>  const delta = EARTH_INNER_GRID_CELL_WIDTH / 2;<br>  const [x, y] = transformToXy(coordinates.lat, coordinates.long);<br><br>  // Calculate the coordinates of the southwest corner of the enclosing inner square<br>  const xMin = Math.round(x / EARTH_INNER_GRID_CELL_WIDTH) * EARTH_INNER_GRID_CELL_WIDTH - delta;<br>  const yMin = Math.round(y / EARTH_INNER_GRID_CELL_WIDTH) * EARTH_INNER_GRID_CELL_WIDTH - delta;<br><br>  const bottomLeft = numbersToGeoPoint(transformToLatLong(xMin, yMin));<br>  const bottomRight = numbersToGeoPoint(transformToLatLong(xMin + EARTH_INNER_GRID_CELL_WIDTH, yMin));<br>  const topLeft = numbersToGeoPoint(transformToLatLong(xMin, yMin + EARTH_INNER_GRID_CELL_WIDTH));<br>  const topRight = numbersToGeoPoint(transformToLatLong(xMin + EARTH_INNER_GRID_CELL_WIDTH, yMin + EARTH_INNER_GRID_CELL_WIDTH));<br><br>  return [bottomLeft, bottomRight, topLeft, topRight];<br>};</pre><p>Then we apply bilinear interpolation to estimate the elevation based on the weighted average of the four surrounding points:</p><pre>export const calculateAltitudeBilinearInterpolation = (coordinates: GeoPoint, enclosingElevationResults: google.maps.ElevationResult[]): number =&gt; {<br>  const [bottomLeft, bottomRight, topLeft, topRight] = enclosingElevationResults;<br><br>  const [x, y] = transformToXy(coordinates.lat, coordinates.long);<br>  const [x1, y1] = transformToXy(Number(bottomLeft.location?.lat), Number(bottomLeft.location?.lng));<br>  const [x2, y2] = transformToXy(Number(topRight.location?.lat), Number(topRight.location?.lng));<br><br>  const q11 = bottomLeft.elevation;<br>  const q21 = bottomRight.elevation;<br>  const q12 = topLeft.elevation;<br>  const q22 = topRight.elevation;<br><br>  const r1 = ((x2 - x) / (x2 - x1)) * q11 + ((x - x1) / (x2 - x1)) * q21;<br>  const r2 = ((x2 - x) / (x2 - x1)) * q12 + ((x - x1) / (x2 - x1)) * q22;<br><br>  const altitude = ((y2 - y) / (y2 - y1)) * r1 + ((y - y1) / (y2 - y1)) * r2;<br><br>  return altitude;<br>};</pre><p>Now we can calculate any requested point’s elevation that lives within a cached grid cell on the fly, without doing a single additional API request.</p><p>But there’s an edge case we haven’t addressed yet.</p><p>What happens when a user draws a fence post or structure right on the boundary between two grid cells? The four points needed for interpolation might span multiple cells. The system automatically detects any additional grid data required and fetches it if not already cached, ensuring consistent accuracy across the map regardless of where users place project elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l-dbN4I_aqkyeOzrhUf1fA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLoANF6cvapuIM9L9oMqUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2L5r9QjnQj9JMjxbiiMh1A.png" /><figcaption><em>The yellow point lies on the boundary between grid cells. Calculating its elevation requires data from both Grid #1 (gray) and Grid #3 (green).</em></figcaption></figure><p>By combining batching, caching, and interpolation, the number of API calls dropped dramatically. This not only lowered costs, but also improved the drafting experience: users could move and redraw objects with minimal delay and real-time accurate pricing calculations.</p><p>In production, the system is actually a bit more advanced: it handles multiple points and grid cells in parallel, fully utilizes Google Elevation API limits (512 locations per request, 100 requests per minute), and includes robust error handling and fallbacks. To go a step further, we incorporated another layer of client-side caching that prefetches all necessary grid cells around a customer’s location when the app loads, allowing almost all requested elevations to be calculated on the fly, without any additional API calls.</p><p>The result was immediate and measurable: API usage dropped sharply, costs were reduced, and the CAD tool became faster and more responsive. Users could interact with the map and objects in real-time, with accurate pricing updates, even under heavy load.</p><p>So far, we’ve tiled ~9,735 km² — roughly twice the size of Istanbul — over the past ~2.5 years. These improvements led to savings of more than <strong>$12K per month</strong> from Geocoding and Elevation API usage, making the optimization both technically and financially significant.</p><p><strong>Conclusion: Smarter Usage, Lower Costs, Better Experience</strong></p><p>What started as a routine review of infrastructure costs turned into a deep dive into Google Maps usage, uncovering inefficiencies that were quietly inflating both costs and response times. By carefully analyzing the problem and combining batching, caching, and interpolation, we were able to dramatically reduce API calls, improve performance, and cut expenses.</p><p>This experience underscored a simple truth: small inefficiencies at scale can become expensive, but thoughtful optimization — grounded in data and careful design — can have outsized impact. With a system capable of handling thousands of requests efficiently and serving precise approximations where needed, both users and the business benefit.</p><p><strong>Further Reading &amp; References</strong></p><p>For readers interested in related spatial indexing and tiling approaches, check out:</p><ul><li><a href="https://h3geo.org/">Uber’s H3 — Hexagonal Hierarchical Spatial Index</a></li><li><a href="https://s2geometry.io/">Google’s S2 Geometry</a></li></ul><p>Google Map reference for the visualization above:</p><ul><li><a href="https://www.google.com/maps/d/u/0/edit?mid=1usHYBj45rc_eXlK4XIpKIamDUw3GM2A&amp;usp=sharing">Interactive Map — Grids &amp; Markers</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.google.com%2Fmaps%2Fd%2Fembed%3Fmid%3D1usHYBj45rc_eXlK4XIpKIamDUw3GM2A%26hl%3Den_US&amp;display_name=Google+Maps&amp;url=https%3A%2F%2Fwww.google.com%2Fmaps%2Fd%2Fviewer%3Fmid%3D1usHYBj45rc_eXlK4XIpKIamDUw3GM2A%26hl%3Den_US&amp;image=https%3A%2F%2Fwww.google.com%2Fmaps%2Fd%2Fthumbnail%3Fmid%3D1usHYBj45rc_eXlK4XIpKIamDUw3GM2A%26hl%3Den_US&amp;type=text%2Fhtml&amp;schema=google" width="600" height="450" frameborder="0" scrolling="no"><a href="https://medium.com/media/abcb5d9ccb4785e494a1660eb16b0600/href">https://medium.com/media/abcb5d9ccb4785e494a1660eb16b0600/href</a></iframe><p><em>What large-scale API optimization strategies have you implemented, and what additional techniques could further reduce costs in geospatial applications?</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4e0719c7ac7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>