Self-Hosted Map Tiles: A Practical PMTiles Guide15 min read2,923 words

Self-Hosted Map Tiles: A Practical PMTiles Guide

Learn how PMTiles, HTTP Range requests and a CDN can cut map hosting costs, with practical steps to prepare, deploy and embed tiles without running a server.

self-hosted map tilesPMTilesmap tile hosting costsHTTP Range requestsMapLibre
Self-Hosted Map Tiles: A Practical PMTiles Guide

How to Self-Host Map Tiles Without Running a Tile Server

Commercial map APIs are convenient - until your usage grows, a project goes viral, or the pricing model stops matching how your product is actually used. For a small app, a free tier may be enough. For a public map with unpredictable traffic, per-load charges can turn "shipping the map" into an infrastructure project you didn't plan to run.

PMTiles takes a different approach: it packages map tiles into a single file, stores that file with a compatible provider, and lets a client request only the byte ranges it needs. Pair that with a CDN and a browser mapping library like MapLibre GL, and you can often skip operating a traditional tile server. It won't make maps free, and it won't fit every data pipeline. But for a lot of projects, it makes costs easier to reason about and the setup simpler to maintain.

This guide walks through how PMTiles works, how to choose and prepare tile data, how to deploy the archive to object storage and a CDN, and what to check before swapping out a commercial map API. The example uses Bunny.net, but the same core requirements apply to other services that support range requests and caching in the right way.

Why self-host map tiles with PMTiles

A typical vector tile setup exposes tiles through a URL pattern based on zoom, column, and row: z/x/y. Behind that endpoint, a tile server reads the underlying data and returns the tile you asked for. That's convenient, but it also means you either run the server yourself or pay someone else to.

PMTiles changes what "delivery" looks like. Instead of storing and serving each tile as a separate file, it keeps a tileset in a single archive. The client then uses HTTP Range requests to ask for the specific byte ranges that contain the tile it needs. The archive's internal directory information helps the client find where those bytes live without downloading the whole file first.

In practice, this means your storage provider doesn't need to "understand" map tiles. It just needs to serve the archive file reliably and support Range requests. If your CDN caches those partial responses, you can use object storage + CDN delivery instead of maintaining a dedicated tile server.

What you gain - and what you give up

The big win is operational simplicity. One archive is easy to copy, version, back up, and deploy. If your tiles don't change often, you avoid running a tile service for a dataset that's mostly static.

Costs can also line up more naturally with what you're actually doing: storage and bytes transferred, rather than a provider's "map load" abstraction.

That trade-off matters when your requirements don't match a mostly-static tileset. If you need frequent incremental updates, server-side filtering based on user permissions, or a mapping platform feature like managed geocoding and routing, PMTiles is only one part of the story. It's a tile delivery format, not a full replacement for every feature a mapping platform might provide.

Why request and map-load pricing differ

A "map load" isn't the same thing as a fixed amount of data. Someone who opens your map and leaves right away might trigger only a handful of tile requests. Someone who pans around, changes zoom levels, and explores a city may request far more.

Commercial APIs may price per visit, while self-hosting typically turns into bandwidth and storage charges. Because of that, comparison gets tricky: a rough estimate can tell you whether self-hosting is worth trying, but it can't predict your bill without actual usage patterns. The key question isn't "which price per load looks lower?" It's how much data your users request, how much is served from cache, and how much operational work your team is willing to own.

How to choose and prepare map data

Before picking a provider, figure out what you actually need to serve. A global dataset sounds like the obvious default, but it can easily be much larger than your product requires. If users only need a region - or if you only support certain zoom levels - extracting a smaller tileset can cut storage, reduce transfer size, and shorten build and upload time.

If you just want to test the delivery model, starting with a ready-made global PMTiles archive is convenient. Protomaps publishes daily builds you can download as a starting point. For a production setup, you should still check coverage, update cadence, licensing, and attribution requirements. A convenient download is not automatically safe for every commercial use or every product requirement.

Reduce the archive to the product's real scope

Protomaps' command-line tools can extract tiles for a bounding box and limit which zoom levels you include. Those choices have real consequences. Smaller geographic coverage shrinks the archive, and dropping zoom levels does too. But if a user navigates outside your coverage, you'll end up with a blank map or tiles that are missing detail.

Use your product's actual interaction model to set those boundaries. A local discovery app might need detailed streets in one metro area and only coarse context outside it. A travel product might want multiple regions at medium zoom, with detailed tiles only for a handful of cities. The "right" archive is the smallest one that still covers the paths users are likely to take - not just the smallest file you can generate.

Keep a repeatable record of how each archive was built: source dataset, extraction bounds, zoom range, build date, and tool version. That makes it much easier to reproduce a release and to debug why what's in production differs from a newer build.

Treat updates as deployments

A single-file archive is easy to deploy, but you still need a release plan. Build the new file separately, verify it, upload it under a new versioned filename, and then update your application configuration to point at the new archive. Keeping the previous archive available also gives you a straightforward rollback.

Also decide how often you truly need to update the tiles. A daily upstream build doesn't mean your product needs a daily deployment. If your map data changes slowly for your use case, updating less often can reduce operational work without hurting users. If the data is time-sensitive, you may need a different update strategy - rebuilding and replacing a large archive might not be acceptable.

How to deploy PMTiles to storage and a CDN

Deployment has two parts: an object storage origin that holds the archive, and a CDN that serves it. The exact setup varies by provider, but the requirements are consistent:

  • The origin must store the full file reliably.
  • The CDN delivery path must preserve and cache HTTP Range requests in a way the PMTiles client can use.

Bunny.net is one example because it offers storage zones, a CDN pull zone, and range-based delivery. Pricing and product settings can change, so check the current rates and documentation before you treat it as "the way to do it." This example is mainly a deployment pattern, not a claim that one provider is always the cheapest or best in every region.

Upload a large archive reliably

For larger files, plan for long uploads. In one practical setup, uploading via the provider's HTTP API timed out after 15 minutes. Creating a storage zone with S3-compatible access and then uploading with rclone worked more reliably.

If your local network is unstable, you'll also want something that helps keep the upload going - like a persistent terminal session (for example, tmux) or a temporary VM.

A typical workflow looks like this:

  1. Create a storage zone and enable its S3-compatible interface.
  2. Configure rclone with the zone name, storage key, and the correct regional endpoint.
  3. Use rclone's URL-copy operation to stream the build file into the storage zone.
  4. Confirm the uploaded object's size and availability before configuring the CDN.

Treat transfer credentials like secrets. Don't commit them to source control. If they're exposed, revoke or rotate them. For repeatable deployments, use a proper secrets manager instead of relying on "a command I copied into a shell once."

Configure the CDN for range requests

Create a pull zone using the storage zone as the origin. Then focus on the settings that affect access and caching, rather than assuming defaults will work.

In Bunny.net's interface, the source setup recommends enabling a large-object delivery optimization so Range requests can be cached. Confirm the current option name and behavior in the provider's docs, then test the deployed archive from the client.

Configure access controls intentionally. CORS affects whether browsers on your own site can make the required requests. Referrer controls can reduce casual hotlinking, but they're not a solid authentication mechanism - referrers can be missing or altered, and public map data is inherently accessible to clients. Use these settings to manage casual misuse, not to "secure" sensitive information.

Finally, test the full path. A file URL that opens in a browser isn't enough. A working PMTiles integration needs partial responses and correct cache behavior. Check response headers, load the map in a browser, pan and zoom, and inspect the network panel for Range requests and caching. If the CDN fetches the entire object for every tile request - or won't cache partial responses - the setup might still work, but you'll likely see worse latency and higher bandwidth than you expected.

How to add PMTiles to a web map

Once the archive is reachable through the CDN, connect it to your web mapping library. MapLibre GL is one option for rendering vector maps in the browser. The usual integration pattern is to:

  • install the PMTiles JavaScript package,
  • register its protocol with MapLibre, and
  • provide a map style that points to the PMTiles archive.

The style matters. The archive contains tile data; it doesn't automatically decide how roads, labels, land, and water look. Make sure your style's source configuration references the deployed archive, and that your layers actually map to data present in the tileset.

Test real user journeys

A map that displays correctly at its initial center isn't fully tested. You need to test the locations and zoom levels your product supports. Try:

  • a fresh browser session,
  • a reload,
  • a slow connection,
  • and a device with limited memory.

Watch for missing tiles, labels that become unreadable, and errors that show up only at certain zoom levels.

Also test caching behavior. The first request for a region might be a cache miss. A repeat visit might be served from a nearby CDN point of presence or the browser cache. Those scenarios can have very different latency and cost characteristics. Measure both, rather than relying on one successful local test.

Keep the map version explicit

If you overwrite an archive "in place," some users (and CDNs) may keep cached data from the older version. A safer approach is to publish a new archive filename and update the application to reference it. That makes releases easier to reason about and gives you a clear rollback path.

It also helps you separate tileset updates from application updates. You can deploy new tile data on your own schedule while still recording exactly which tileset version each app release used. It's a small process change, but it saves time when someone reports a "map discrepancy" and you need to figure out what they actually saw.

How to evaluate costs, limits and trade-offs

Your main cost categories are:

  • archive storage,
  • data transfer, and
  • any replication you choose.

There may also be costs for tooling, build infrastructure, monitoring, and the engineering time required to run the setup. Self-hosting can lower what you'd otherwise pay a provider, but it also increases internal ownership. A fair comparison includes both sides.

As an example, one setup referenced a 139 GB world map and estimated storage at roughly $5 per month with replication across several regions. That depends heavily on provider rates, region selection, and replication settings - so treat it as an example, not a current quote. A smaller regional archive typically stores for less and can reduce how much data users request.

Estimate transfer from observed behavior

Say a laptop session transfers about 5 MB while loading a European map and zooming into a city. If bandwidth is priced at $0.01 per GB, that's about $0.00005 per session using decimal units. Multiply that by 1,000 similar sessions and you get roughly $0.05 in bandwidth, before other charges. The math is straightforward - the assumption that every session transfers exactly 5 MB is the part that usually breaks.

Not every visitor behaves the same way. Some leave quickly. Others pan across many regions, request deeper zoom levels, or come back after the browser cache has expired. A CDN cache can reduce repeated transfers from your origin, but it doesn't mean every user request "costs nothing." Measure your traffic profile after launch and adjust your estimate using actual byte counts.

Commercial services may charge a fixed amount per map load. The example that compared one rate to a Mapbox price beyond a free allowance estimated that the illustrative bandwidth could be much lower - up to 100x in that particular scenario. That doesn't generalize automatically: pricing changes, what counts as a "load" varies, and usage patterns may not match. Always check current plans and compare to your expected workload, including any API features you'd otherwise need to replace.

Add safeguards without breaking normal use

Public archives can attract downloads that aren't the same as normal map browsing. You can use a CDN setting that slows a single request after a defined threshold of transferred data to discourage "download the whole file" attempts. In the Bunny.net example, the threshold was 10 MB followed by a very low transfer speed. Use that kind of setup to start testing, not as a universal configuration.

Be careful with request-rate limits. Even a legitimate map can generate a lot of requests while a user pans and zooms, especially when the browser fetches tiles in parallel. A monthly bandwidth cap can prevent runaway bills, but once you hit it, the map may become unavailable until the cap resets. Alerting and investigation are often safer first controls than a hard cap that surprises users.

Key decision: Self-host when your data fits a static archive model, your expected transfer costs are lower than the API alternative, and your team can own deployment and monitoring. Keep a managed API when it saves meaningful engineering time or provides capabilities your product depends on.

Key takeaways

  • PMTiles stores tiles in a single archive and uses HTTP Range requests to fetch only the parts you need.
  • A compatible storage origin plus a CDN can deliver the archive without a dedicated tile server.
  • Extracting only the regions and zoom levels you need can cut storage and transfer, but your boundaries must match real user journeys.
  • Confirm the CDN handles and caches Range requests correctly, and test through the real browser workflow.
  • Compare measured bandwidth and storage costs with current API pricing, and include engineering and operational work.
  • Use versioned archives, sensible monitoring, and tested limits so releases are reversible and costs are visible.

Conclusion

PMTiles makes self-hosted maps more practical by pairing a single archive with HTTP Range requests. With compatible storage and CDN delivery, you can avoid operating a traditional tile server and instead pay mainly for the data you store and the traffic you serve. It's especially compelling for static maps with unpredictable traffic.

Start with your actual geographic and zoom requirements, test with a smaller archive, and verify Range caching end-to-end in the browser. Then compare measured costs and operational effort against the managed API you'd otherwise use. If the data model fits and the numbers hold up, self-hosting can be a straightforward architecture choice - not a leap of faith.

Frequently Asked Questions

PMTiles is a format for storing map tiles in a single archive. A compatible client uses HTTP Range requests to retrieve the relevant portions of that file, rather than downloading the entire archive or asking a tile server for a separate file for every tile.
Not necessarily. If your storage provider and CDN correctly support HTTP Range requests and caching, they can serve the archive directly. You still need to build or obtain the tiles, configure delivery, and monitor the deployment; PMTiles removes a serving component, not every operational task.
No. The delivery path needs to handle partial byte-range requests correctly, and caching behavior matters. Test the provider with the client you intend to use, including cache misses and repeat requests. A CDN that only serves the complete file efficiently may not be a good fit for this pattern.
No. It depends on traffic, data size, cache behavior, current provider pricing and the features included in the API. Self-hosting can be cost-effective for static tiles and variable usage, but engineering time, updates and monitoring count too. Compare actual data transfer with the API’s current billing model.

Related articles