Protomaps PMTiles: self-hosting map tiles on Bunny.net CDN for about $5/month

Bruce, a Computer Science student at ETH Zurich, wrote a guide to self-hosting map tiles with PMTiles, part of the Protomaps ecosystem. He came across it while researching his latest project, Mapboard. His starting point is cost: for most non-commercial projects, commercial map APIs become prohibitively expensive if a site goes viral. As an example, he says Mapbox charges $5 per 1,000 map loads once the free tier is used up.

PMTiles is a tile format that ships as a single file and is read through HTTP Range requests, so it can sit in a storage bucket. On CDNs that cache Range requests for large files, deployment needs no effort beyond downloading the file and uploading it to storage. On others, such as Cloudflare, the author says an edge function can translate between the traditional x/y/z URL path and Range requests.

Getting the data is simple. For the whole world, you go to the build page and download the latest daily build. The CLI offers more control: you can extract only a bounding box or specific zoom levels and end up with a much smaller file.

The author's CDN of choice is Bunny.net (the link in the post is an affiliate link). He lists its support for HTTP Range requests, no personal data collected by default, EU headquarters, and low-cost access to a global network of CDN and edge storage servers. Pricing depends on region and the replication factor of the edge storage. Bandwidth to Europe and North America is generally $0.01/GB, or $0.005/GB on the smaller Volume network. Storage runs from $0.01/GB/month with no replication to $0.055/GB/month with maximum replication. A high replication level mostly matters for latency on a cache miss, because data is replicated further as the CDN points of presence cache it.

In practice, he says, storing the 139GB world map with replication to most continents (5x) costs about $5/month. Loading a map of Europe on a laptop and zooming in on a city transmits about 5MB, which would cost $0.00005 in bandwidth. Later navigation and reloads are cheaper because more of the map is cached locally. That works out to $0.05 per 1,000 map loads, which he says could be 100x cheaper than Mapbox. He adds that real bandwidth varies: less for visitors who bounce immediately, possibly tens of MB for heavy users. Mapbox, by contrast, charges a flat fee per visit.

For the upload, he recommends creating a Bunny storage zone with S3 compatibility enabled, because uploading through the HTTP API timed out after 15 minutes for him. With rclone installed, you configure an S3 remote pointing at the zone, then run rclone copyurl with the build URL, a destination path ending in .pmtiles, a 256M S3 chunk size and a progress flag, which streams the file straight into storage. He suggests running it in tmux or from a temporary VPS if your connection is poor.

Then comes the pull zone. In theory you create one, select the storage zone as the origin, and you are done. In practice he changes a few settings. Allowed referrers (under Security > General) stop other websites embedding your tiles. Under Caching, "Optimize for large object delivery" should be enabled, since that makes caching of Range requests possible. To discourage people from downloading the whole file and leaving you a large CDN bill, he limits download speed to 10kB/s after 10MB transmitted in a single request, using the "Download speed limits" and "Limit after" settings under Network limits. Regular usage should never reach that amount. He also suggests considering a requests-per-second limit, noting that legitimate use can quickly reach high numbers, or a monthly bandwidth cap on the pull zone.

The last step is embedding. You use MapLibre GL, for example: install the pmtiles npm package, then add the protocol and a style to MapLibre as described in the official installation guide.

Key facts

  • PMTiles, part of Protomaps, is a single-file tile format served through HTTP Range requests, so it can be deployed to a storage bucket behind a CDN.
  • On Bunny.net, the author estimates the 139GB world map costs about $5/month to store with 5x replication; bandwidth is $0.01/GB for Europe and North America ($0.005/GB on the Volume network).
  • A typical map load of Europe on a laptop transmits about 5MB, or $0.00005, which the author puts at $0.05 per 1,000 loads against Mapbox's $5, so it could be 100x cheaper.
  • Setup uses an S3-compatible Bunny storage zone and rclone copyurl with a 256M chunk size, because the HTTP API upload timed out after 15 minutes for the author.
  • Suggested pull zone settings: restrict allowed referrers, enable 'Optimize for large object delivery', and cap speed at 10kB/s after 10MB in a single request to deter bulk downloads.

Why it matters

Map APIs are a common cost trap for small projects. The author's argument is that a hobby or non-commercial site that goes viral can face a large Mapbox bill, at $5 per 1,000 map loads after the free tier. PMTiles changes the shape of the problem: instead of running a tile server, you host one static file and let a CDN serve byte ranges from it. By his estimate, the cost drops to roughly $0.05 per 1,000 loads plus about $5/month for storing the full world map.

Who it affects

Developers building websites or apps with an embedded map, especially non-commercial or side projects with unpredictable traffic. It also suits anyone who wants map tiles served from an EU-headquartered CDN that, per the author, does not collect personal data by default. Teams on other CDNs, such as Cloudflare, can still use PMTiles with an edge function that translates x/y/z paths into Range requests.

How to use it

Download the latest daily world build from the Protomaps build page, or use the CLI to extract just a bounding box or chosen zoom levels for a much smaller file. Create a Bunny.net storage zone with S3 compatibility enabled, configure rclone with the zone name, storage key and regional S3 endpoint, and stream the file in with rclone copyurl using --s3-chunk-size 256M. Create a pull zone with the storage zone as origin. Restrict allowed referrers, confirm 'Optimize for large object delivery' is on, and add a speed limit of 10kB/s after 10MB per request. Optionally add a requests-per-second or monthly bandwidth limit. Then embed with MapLibre GL by installing the pmtiles npm package and registering the protocol and a style, following the official installation guide.

How solid is it

This is a single author's practical walkthrough, and the cost figures are his estimates for a typical load, not measured production results. The 100x advantage is explicitly hedged ('could be') and depends on how much bandwidth each visitor uses. No measurements of latency, cache-hit rate or real traffic from a deployed production site are given. No comparison with other CDNs' prices or with other self-hosting options is given. The Bunny.net link is an affiliate link, which the author discloses.

Risks and caveats

Self-hosted cost varies with actual bandwidth, while Mapbox charges a flat fee per visit. Heavy users may pull tens of MB per session rather than the typical 5MB. Anyone could download the whole file and run up a CDN bill, so the author recommends referrer restrictions, a speed limit after 10MB in one request, and possibly request-rate or monthly bandwidth caps, noting that legitimate usage can also reach high request rates quickly. Uploading through the Bunny HTTP API timed out for him, so plan on S3 and a stable connection or a temporary VPS. The size of Mapbox's free tier is not stated, so the comparison starts from the point where it is exhausted.

“At $0.05/1k map loads that could be 100x cheaper than Mapbox.”

— Bruce, author of the post