Web Development 4 min read 774 words

Protomaps: the world map in a single file for about 5 dollars a month

ES
Protomaps: the world map in a single file for about 5 dollars a month

In any app with a map there’s a part nobody looks at and everybody pays for: the basemap. The streets, the rivers, the city names, that background you then draw your points, routes or polygons on. The usual thing is to use a commercial provider, drop in the API key and forget about it… until the bill arrives. And if the project has the bad luck of becoming popular, the bill arrives sooner.

Bruce Röttgers explains it in Self-hosting map tiles has gotten cheap and easy: looking for maps for a personal project, he came across Protomaps and ended up serving the whole world map from a CDN for about five dollars a month. His line sums it up well: for most non-commercial projects, commercial APIs become prohibitively expensive if you ever go viral.

One map, one file

The key is PMTiles, Protomaps’ format. Traditionally, a vector map is millions of small tiles (one for each area and zoom level) served by a tile server you have to maintain. PMTiles puts all those tiles into a single file, with an index inside, and the browser requests only the pieces it needs with HTTP Range requests (the same mechanism that lets you jump to minute 40 of a video without downloading all of it).

That completely changes the infrastructure: there’s no server anymore, you just put the file in object storage with a CDN in front.

flowchart LR
    N["Browser · MapLibre GL"] -->|"HTTP Range · only what is visible"| C["CDN"]
    C -->|cache| S[("Storage · world.pmtiles")]

It’s an idea I love, and it’s very reminiscent of what Parquet and Iceberg did with analytical data: well-organised files on cheap storage, with the client reading only what it needs.

How he sets it up

Protomaps publishes a daily build of the world map from OpenStreetMap. It’s 139 GB, but you don’t need to use all of it: with the pmtiles tool you can cut out an area or limit zoom levels and end up with a much smaller file. For example, to keep only Madrid (the date is whichever build you want to use):

pmtiles extract https://build.protomaps.com/20261115.pmtiles madrid.pmtiles \
  --bbox=-3.89,40.31,-3.52,40.56

The author serves it from Bunny.net, a European CDN, with a few settings worth copying:

  • An S3-compatible storage zone, uploading with rclone copyurl, which transfers the file straight from the build URL. With the HTTP API, the 139 GB upload timed out after 15 minutes (and if your connection is poor, he recommends doing it from tmux or a temporary VPS).
  • On the CDN, restrict the domains allowed to use the map, so nobody embeds it on their site at your expense.
  • Enable large object optimisation, so the CDN caches Range requests properly.
  • Throttle speed to 10 kB/s after the first 10 MB of a single request, to discourage anyone wanting to download the whole file.

Cloudflare works too, but you need an edge function to translate classic tile paths into Range requests.

In the browser it’s drawn with MapLibre GL and the pmtiles package, registering the protocol and pointing the source at the file:

import maplibregl from "maplibre-gl";
import { Protocol } from "pmtiles";

const protocol = new Protocol();
maplibregl.addProtocol("pmtiles", protocol.tile);

// and in the map style:
// "url": "pmtiles://https://your-cdn.example.com/world.pmtiles"

The numbers

ItemCost
Storing the world (139 GB, replicated 5 times)~$5/month
Traffic in Europe and North America~$0.01/GB
Viewing Europe and zooming into a city (~5 MB)~$0.00005
Mapbox, beyond the free tier$5 per 1,000 loads

With those figures, the author estimates it comes out about a hundred times cheaper than Mapbox. He notes that real traffic varies a lot: a user who glances at the map uses a few MB, and one who wanders across half a continent can use tens. But even so, the difference is huge.

Things to keep in mind

Not everything is free, of course. You have to configure the CDN by hand, keep an eye on usage and update the file when you want fresher data. The data comes from OpenStreetMap, under the ODbL licence, so you need to include the corresponding attribution on the map. And a self-hosted map is your map: if something breaks, there’s nobody to write to.

Working in the geospatial world, I’ve often seen the basemap taken for granted until someone looks at the bill. That today you can serve the world map with one file, a CDN and five dollars a month, without a single server to maintain, is one of those things that seemed impossible a few years ago. For a personal project, an internal tool or something that might have ten users or ten thousand, it’s an option well worth considering.