GEO for AWS

The GEO Project: How We Adapted OpenStreetMap for AWS

Accurate and up-to-date geopositioning is business critical for TemaBit eCom service. The map is used by customers who place orders, couriers who deliver these orders, drivers who plan optimal routes, etc. That is why, it was strategically important for us to unify the way different departments of the company process addresses.

Different departments used to have their own databases for geo data. This was not convenient as the search options were limited, and there were discrepancies in addresses. We decided to centralize all addresses in a single database and chose the service called OpenStreetMap for this. This is when the project we nicknamed GEO started. 

With OpenStreetMap (OSM), we consolidated the address system and enabled automatic access to up-to-date, reliable and complete geo information for all departments of the company. Furthermore, we adapted OpenStreetMap, an open-source software, for our AWS environment. In this post, we’d like to share our experience and the challenges we overcame along the way.

Why Is OpenStreetMap Not ‘Just a Map’?

If you have never worked with OpenStreetMap closely – just like we never did before the GEO project – we’ll give a quick glance into this service. Spoiler alert: OSM is not ‘just another map’ out there but a whole ecosystem of open-source services.

OSM is a free, community-driven set of geolocation data, or an editable map of the world, which is being crowdsourced and released under an open-source license. 

Components of ​​OpenStreetMap

Title: Components of ​​OpenStreetMap (source)

As of now, the software has approximately 10M users. Here is what Wired wrote about OSM shortly after it appeared: “it was designed to reduce map licensing fees to zero, and it was also meant to improve the accuracy of maps. The project was seeded with satellite imagery, and then the world-at-large was invited to put labels and borders on the images, otherwise known as “volunteered geographical information,” or VGI.” 

All manipulations with the OSM geographical data, like map rendering, search, routing, etc., are done with the help of separate services and components, which form a whole ecosystem:

  • tile server (e.g. Mapnik)
  • stylesheet for rendering (e.g., OSM-Carto) 
  • JavaScript library for mobile-friendly interactive maps (e.g., leaflet.js)
  • geocoder for map search (e.g., Nominatim)
  • routing engine (e.g., OSRM and Valhalla)
  • data exporting and processing service (e.g., Overpass API)
  • data editor – iD, currently being run by OSM Foundation.

Most of these services are distributed under an open-source license, too. 

Why Did We Choose OSM Over Google Maps?

Before opting for OSM as our main geo data provider, we naturally considered the other giant in the field, Google Maps. However, it did not work well for us. Here is why. 

In terms of costing, there was no big difference between the two services. Though OSM is distributed under an open-source license, the cost of the infrastructure we needed to deploy for it was commensurate with the price of Google’s commercial product. 

In terms of the maps detailing our region, both services also look more or less the same. However, when using Google Maps, we can only build on top of what is received in an API call and render what Google wants us to render. With OSM, we can manipulate and update map data as we see fit. 

The decisive factor in favor of OSM was the speed of updates. Google Maps has a complex and bureaucratized process for adding new objects and addresses on the map. With OSM, on the contrary, updates of the map are easy and take a very short time to be visible to the end-users. 

By choosing OSM, we gained the updates speed and flexibility we could never have with Google. Compared to our previous addresses database, OSM enabled higher accuracy in address searching, especially for the recently renamed streets.

How We Adapted OpenStreetMap for the Cloud

Digital transformation in client projects as well as in internal ones is TemaBit’s priority. As a part of the transformation strategy the company made a strategic decision to switch from Hetzner, our hosting provider, to AWS. Though the former seemed more cost-effective compared to Amazon, it no longer catered for our needs in security and scalability. 

We planned to replicate the GEO project in the cloud and started to prepare the underlying infrastructure for it. Our solution consisted of multiple open source components, which we planned to adjust for the cloud environment. And this is when the challenges hit us hard!..

Architecture Diagram of OpenStreetMap Setup in Our AWS Environment

Title: Architecture Diagram of OpenStreetMap Setup in Our AWS Environment

The Challenges We Faced with OSS

The main challenges that we faced while trying to adapt open-source OSM services for our AWS environment were the following:

  • Buggy and outdated code
    As it is the case with many open source services, some OSM-related ones had bugs and were not properly documented. Some repos were outdated and had no regular contributions over the recent time.
  • Some services were stateful
    When we looked at some of the OSM services closer, it became clear that they do not fit the basic approach to microservices in the cloud. It was critical for us that all our services were dataless (stateless) and ran uninterruptedly in AWS ECS. But such services as Nominatim and Photon, for instance, are data-bound in RDS and EFS respectively. We needed to single out the data layer from the service layer and store all the critical data in Amazon RDS.

  • Lack of pre-moderation in OSM
    OSM relies on the contributions of its users, with no pre-moderation. Some of the geo data changes may be not accurate and contradict the Ukrainian legislation. For instance, the Russian OSM community marked the illegally annexed territories on the map as the ones belonging to their country. We could not accept this under any circumstances, and the modifications from our end resulted in some data updates delays.
How We Approached the Migration

Setting up each of the open-source OSM services to work under certain conditions is a relatively easy task. However, the task becomes trickier with multiple services in the cloud! We strived to make the solution as fault-tolerant and highly available as possible. We also wanted it to be heavily automated as we did not have much time and resources to manage the infrastructure manually.

When choosing a strategy to move to the cloud, we decided to move services one by one.

Our approach to adjusting OSM services to AWS varied from one service to another and took the unique peculiarities of these services into account.

Nominatim

Nominatim is a tool to search through OSM data by name and address (geocoding) and to generate synthetic addresses of OSM points (reverse geocoding). The service has a limited capability to search through the objects by their type (pubs, hotels, churches, etc.).

To adjust this service for our AWS environment, we split the service for further data import and reading in AWS Aurora PostgreSQL Serverless v2, with the following parameters for AWS Aurora PostgreSQL:

  • Engine Family: aurora-postgresql14
  • Engine Mode: provisioned
  • Deployment Model: Serverless v2 with Aurora Capacity Units (ACU) configured for dynamic scaling:
  • Minimum ACU: 0.5
  • Maximum ACU: 16

One particularly important step before we started the Nominatim service was to add changes described in this issue to the already created database, after its initialization: https://github.com/mediagis/nominatim-docker/issues/378

Photon

Photon is a multilingual, Search-as-you-Type geocoder (“Name and Address Search”) for OSM data. It was originally based on Apache Solr and is now based on Elasticsearch. As of now, Photon has 70+ reported issues on GitHub: https://github.com/komoot/photon/issues 

The top issues that are still not fixed are the following:

Adjusting it for the cloud was probably the biggest challenge for the GEO team. As a part of AWS migration strategy, we made a fork of the Photon repository and modified its ‘updater’ module. We faced a serious issue when we tried to connect a Photon docker container to an Elastic container and had to spend a lot of time addressing it. 

We singled out the Elasticsearch-5.6.16 part, which was hard-coded in Photon, using an EC2 instance type r5a.large. We found out that the instances with lower compute resources failed due to the lack of memory. We also customized the Linux OS on our Photon instance for Elasticsearch and Java_options.

We made the following changes:

  • File: /etc/elasticsearch/elasticsearch.yml
  • Cluster Name: cluster.name: photon
  • Node Name: node.name: photon
  • Transport Host: transport.host: 0.0.0.0
  • Memory Lock: bootstrap.memory_lock: true
  • File: /etc/elasticsearch/jvm.options
  • Heap Size: -Xms8g and -Xmx8g set the initial and maximum heap size to 8GB.
  • Garbage Collector: Use the G1 garbage collector: -XX:+UseG1GC
  • Heap Percentage Settings: G1 settings for reserve and occupancy.
  • Other various JVM settings to optimize Elasticsearch’s performance.

After the testing cycle, we found out that Nominatim index updates did not work properly in Photon. So, we made a fork of the repo and manually fixed this issue. This, in turn, called for more manual changes in AWS Aurora PostgreSQL Serverless v2 with Nominatim.

We have also modified SystemD Elasticsearch configuration:
 /usr/lib/systemd/system/elasticsearch.service

because the service did not start by default after a collapse by adding the following parameters:

[Service]
# Service behavior settings
Restart=always
RestartSec=30   # Delay before restart, helpful to ensure a clean stop
StartLimitInterval=0  # Disable start rate limiting
# Adjust these settings based on your system’s resources
LimitNOFILE=65536
LimitNPROC=2048
LimitAS=infinity
LimitFSIZE=infinity

PhotonSearch

PhotonSearch, a brainchild of TemaBit, stands as a bridge between the Photon and Overpass services. Programmed with C#, it encapsulates the geocoding capabilities of both services and offers a user-friendly interface for business, ensuring a seamless geocoding experience. 

To adapt this service for our AWS setup, we created a specific configuration of PhotonSearch, which ensured high availability of the service in the cloud. 

Overpass API

Overpass API is a read-only API that allows for querying the OSM dataset in a flexible and efficient manner. It is designed to extract specific OSM data by filtering based on various criteria, making it a powerful tool for developers and researchers interested in specific subsets of the OSM data. Overpass is particularly popular for complex queries that are not supported by the main OSM API.

Overpass API almost immediately started in our ECS, but it took quite considerable memory upon initialization. Task Memory for the first initialization of Overpass ECS service must be configured with 16GB.

TileServer GL

TileServer GL facilitates vector and raster tile serving based on Mapbox Vector Tiles. One can use it to render maps dynamically, serve pre-rendered raster tiles, or generate static map snapshots, all stemming from diverse data sources. As a part of our cloud migration strategy, we made a Docker image for it as we used custom styles for rendering the vector files. 

Here is how our Dockerfile looks:

FROM maptiler/tileserver-gl:v4.4.10
ARG VERSION
WORKDIR /data
COPY dark-matter /usr/src/app/node_modules/tileserver-gl-styles/styles/dark-matter
COPY fonts /usr/src/app/node_modules/tileserver-gl-styles/fonts
COPY osm-bright /usr/src/app/node_modules/tileserver-gl-styles/styles/osm-bright
COPY osm-liberty /usr/src/app/node_modules/tileserver-gl-styles/styles/osm-liberty
COPY osm-liberty-with-house /usr/src/app/node_modules/tileserver-gl-styles/styles/osm-liberty-with-house
COPY positron-gl-style /usr/src/app/node_modules/tileserver-gl-styles/styles/positron-gl-style
COPY voyager /usr/src/app/node_modules/tileserver-gl-styles/styles/voyager

Understanding the organization of the TileServer-GL setup is crucial. Here is a glimpse into the directory’s layout:

tileserver-gl
├── Dockerfile
├── README.md
├── config.json
├── dark-matter
│   ├── …
├── docker_publish.sh
├── fonts
│   ├── …
├── osm-bright
│   ├── …
├── osm-liberty
│   ├── …
├── osm-liberty-with-house
│   ├── …
├── positron-gl-style
│   ├── …
├── resources/
│   ├── config.json       # Configuration for tile creation with tilemaker
│   └── process.lua       # Script detailing how OSM data should be processed
└── voyage
 └── style.json

The styles/: directory contains subdirectories for each style available in TileServer-GL. Each style directory contains the following:

  • sprite.json, sprite.png, sprite@2x.json, sprite@2x.png: sprite resources for the map style
  • style.json: configuration for the map style
  • icons/ (if applicable): icon resources for the map style
  • fonts/: font files used in the styles of TileServer-GL, with subdirectories for each font style.

We took vector maps from AWS EFS ukraine.mbtiles, and the only issue we faced concerned auto-update for the same-name file. Auto-updates are not working even in the latest developers community version; in fact, only zurich_switzerland.mbtiles can be used by default. We did not automate the way ukraine.mbtiles file generates as this was not a business priority. Besides, this process requires considerable compute and financial resources.

Bottomline

After five months of work, we successfully launched all the open-source and internal services that support OSM for our end-users in the cloud. AWS grants us all the benefits the cloud has to offer: scalability, flexibility, high availability, security, cost effectiveness, etc. 

Grafana Screenshot Showcasing Requests to Our Services

Title: Grafana Screenshot Showcasing Requests to Our Services

The main lesson we learned while adapting the services for the cloud was that, with open-source components, you should at all times be ready to fix the bugs or add the required functionality on your own, without relying on the community. 

The project was completed according to the company’s best SRE practices.

The success of the project was due to the skills and devotion of the team, namely Stanislav Kolenkin, Oleksandr Moisieiev, Oleksandr Sapozhnikov, Mykhailo Voytko, Oleksandr Ryabtsev, Serhii Matviyuk.

Let us help you!
We will contact you to better identify your needs and set up an evaluation.