7 min read· by Awab Tech Lover

Self Host Map Tiles with Protomaps to Slash Costs

Want to slash your Mapbox bill? Learn how to self host map tiles with Protomaps using PMTiles and static object storage to cut mapping costs by up to 90%.

Self Host Map Tiles with Protomaps to Slash Costs

Self Host Map Tiles with Protomaps to Cut Costs by 90%

Building location-aware web applications usually starts with an off-the-shelf provider like Mapbox or Google Maps. In the beginning, the developer experience is frictionless, the base maps look stunning, and the free tier covers early development. But as monthly active users climb and page views scale, mapping bills can balloon unexpectedly. If you want to retain full control over your geospatial infrastructure while dramatically reducing your cloud spend, learning how to self host map tiles with Protomaps is one of the most effective engineering decisions you can make.

Protomaps introduces a paradigm shift in how we serve spatial data. By moving away from complex, database-heavy tile servers and replacing them with static, cloud-native file formats, you can serve interactive vector maps straight from cheap cloud object storage.

Here is a comprehensive, production-ready guide to breaking free from usage-based map pricing using Protomaps and PMTiles.


Why Hosted Map APIs Become Prohibitively Expensive

Commercial map platforms charge primarily by usage—either per map load or per thousand tile requests:

  • Mapbox GL JS: After the initial free tier (50,000 map loads), charges start at $5.00 per 1,000 loads, stepping down gradually at higher volumes.
  • Google Maps Platform: Charges $7.00 per 1,000 dynamic map loads.

If your web application receives 500,000 monthly map views, your baseline bill with Mapbox sits around $2,250 every single month just for rendering the base map canvas. This pricing model penalizes high-traffic applications, dashboards with frequent refreshes, and embedding maps on public-facing content sites.

Historically, the alternative was self-hosting a traditional tile stack: PostgreSQL/PostGIS, Osm2pgsql, Mapnik, and a caching server like TileServer GL or TileStache. While this avoided per-request fees, it introduced heavy server maintenance, high memory overhead, and continuous operational friction.

Protomaps completely eliminates that operational burden.


The Protomaps Revolution: What is PMTiles?

At the core of Protomaps is PMTiles, an open, single-file archive format for pyramid tile datasets (vector or raster).

Traditionally, a map tileset consists of millions of individual .pbf or .png files organized into a deep directory tree (/{z}/{x}/{y}.vector.pbf). Syncing millions of tiny files to Amazon S3 or Google Cloud Storage takes hours, costs significant PUT request fees, and strains filesystem caches.

PMTiles solves this problem by packaging the entire planetary or regional tileset into a single archive file. It leverages HTTP Range Requests to fetch only the specific bytes required to display the user's viewport.

Browser Viewport 
      │
      ▼
MapLibre GL JS (Client)
      │
      ▼  (HTTP Range Request: bytes=2048-4096)
Cloudflare / CDN Edge
      │
      ▼
Object Storage (S3 / R2 / B2 hosting single world.pmtiles)

Because PMTiles files are read-only and static, you do not need an active application server running Node.js, Go, or Python. You only need a static file bucket and a lightweight edge cache.


Comparing Architectures: Mapbox vs. Traditional vs. Protomaps

Feature Commercial APIs (Mapbox) Traditional Self-Hosted (PostGIS) Protomaps (PMTiles)
Cost at 1M Views ~$4,750 / month $100–$300 / month (VM costs) $5–$25 / month (Storage + Egress)
Server Maintenance Zero High (DB tuning, OS patches) Zero (Static hosting)
Infrastructure Proprietary Cloud Dedicated VPS / Kubernetes S3, Cloudflare R2, or MinIO
Setup Complexity Low Very High Low to Medium
Data Source Proprietary + OpenStreetMap OpenStreetMap / Custom OpenStreetMap
Offline Support Limited / Enterprise Complex Native (Single-file download)

Step-by-Step: How to Self-Host Vector Tiles

Deploying your own vector tile stack with Protomaps requires four distinct steps: obtaining the data, storing it, serving it via CDN, and rendering it in the browser.

Step 1: Download or Generate a PMTiles Archive

You do not need to process raw OpenStreetMap (OSM) data yourself unless you need hyper-custom layers.

  1. Pre-built planet and regional extracts: Protomaps publishes regularly updated OSM daily/weekly builds. You can download pre-rendered regional extracts (e.g., North America, individual countries, or cities) directly from the official Protomaps distribution site or download the entire 120GB+ planet file.
  2. Custom builds with Planetiler: If you require custom vector data attributes, you can use Planetiler, a fast Java-based tool that processes the entire global OSM dataset into a PMTiles archive on a typical desktop computer in under an hour.

For testing, download a small city extract:

wget https://build.protomaps.com/20240101.pmtiles -O my_city.pmtiles

Step 2: Upload to Egress-Free Cloud Storage

While you can store your .pmtiles archive in Amazon S3, S3 charges data transfer fees ($0.09 per GB) when data leaves the region.

To maximize your 90% savings, use an object store with zero egress fees:

  • Cloudflare R2: $0.015/GB-month storage, $0.00/GB egress.
  • Backblaze B2: $0.006/GB-month storage, zero egress when paired with Cloudflare CDN.

Upload your archive to your bucket using the AWS CLI or Cloudflare dashboard:

aws s3 cp my_city.pmtiles s3://my-map-bucket/tiles/world.pmtiles \
  --endpoint-url https://<account_id>.r2.cloudflarestorage.com

Ensure your storage bucket allows GET and HEAD requests, along with the Range request header.

Step 3: Configure Edge Caching and CORS

To allow web browsers to query your bucket using HTTP range requests, set your CORS policy on the bucket:

[
  {
    "AllowedHeaders": ["Range", "Content-Type"],
    "AllowedMethods": ["GET", "HEAD"],
    "AllowedOrigins": ["*"],
    "ExposeHeaders": ["Content-Range", "Content-Length", "ETag"],
    "MaxAgeSeconds": 3600
  }
]

For optimal performance, place a CDN (like Cloudflare or Fastly) in front of your storage bucket. When a user zooms into Paris, the CDN caches the specific byte chunks representing those tile indices at edge locations worldwide, making subsequent loads near-instant.

Step 4: Render the Map with MapLibre GL JS

On the client side, combine MapLibre GL JS (the open-source fork of Mapbox GL) with the official Protomaps client library (pmtiles).

Install the packages:

npm install maplibre-gl pmtiles protomaps-themes-base

Implement the map inside your frontend application:

import maplibregl from 'maplibre-gl';
import * as pmtiles from 'pmtiles';
import layers from 'protomaps-themes-base';
import 'maplibre-gl/dist/maplibre-gl.css';

// 1. Initialize the PMTiles protocol engine
const protocol = new pmtiles.Protocol();
maplibregl.addProtocol('pmtiles', protocol.tile);

// 2. Define the remote PMTiles URL
const PMTILES_URL = 'https://cdn.yourdomain.com/tiles/world.pmtiles';

// 3. Initialize the MapLibre canvas
const map = new maplibregl.Map({
  container: 'map',
  zoom: 12,
  center: [-73.985, 40.748], // New York City
  style: {
    version: 8,
    glyphs: 'https://protomaps.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf',
    sources: {
      protomaps: {
        type: 'vector',
        url: `pmtiles://${PMTILES_URL}`,
        attribution: '© <a href="https://openstreetmap.org">OpenStreetMap</a>'
      }
    },
    // Use the official Protomaps style presets (light, dark, white, grayscale)
    layers: layers('protomaps', 'light')
  }
});

The Realistic Math: What Do You Actually Save?

Let's model the operational costs for a web application serving 1,000,000 dynamic map views per month.

With Mapbox:

  • First 50,000 loads: $0 (Free tier)
  • Next 950,000 loads: $5.00 per 1,000 loads = $4,750.00 / month

With Protomaps on Cloudflare R2:

  • Storage: A complete worldwide planet extract with street-level detail down to zoom level 15 is roughly 120 GB.
    • 120 GB × $0.015/GB = $1.80 / month
  • Class B Operations (Reads / HTTP Range Requests):
    • Average map session performs ~15-25 byte-range requests.
    • 20 requests × 1,000,000 = 20,000,000 requests.
    • Cloudflare R2 charges $0.36 per million Class B operations = $7.20 / month
  • Bandwidth / Egress: $0.00 (R2 features zero egress fees).
  • Total Estimated Cost: $9.00 / month

You slash your monthly expenditure from $4,750 to under $10—representing a cost reduction of over 99% without managing a single Linux server.


When You Should NOT Switch

While Protomaps offers massive cost savings for tile rendering, commercial providers still excel in specialized use cases:

  1. Turn-by-Turn Navigation & Routing: PMTiles provides visual vector geometry, not a routable graph. If you need real-time traffic-aware navigation APIs, you still need services like Mapbox Directions or self-hosted Valhalla/OSRM.
  2. Address Geocoding & Autocomplete: Forward and reverse geocoding requires a dedicated search engine (like Pelias or Mapbox Search).
  3. High-Resolution Satellite Imagery: OpenStreetMap data is vector-only. Global high-resolution satellite imagery remains expensive to acquire and host independently.

If your core requirement is rendering fast, responsive, custom-styled vector basemaps for users to explore, Protomaps gives you enterprise-grade infrastructure at near-zero recurring cost.


FAQ

What are the bandwidth requirements for serving PMTiles?

Because PMTiles stores data as compressed vector tiles (typically Protocol Buffers), each individual tile range request transfers between 5 KB and 40 KB. In total, a user browsing an area consumes only a fraction of a megabyte. Pairing your storage with a CDN ensures that these requests are served rapidly from edge memory caches.

Can I customize the map colors and typography?

Yes. Protomaps vector tiles follow an open schema compatible with standard MapLibre styles. You can use the official protomaps-themes-base styling presets, customize individual layers (roads, water, buildings, labels) using standard JSON style specifications, or design styles visually in tools like Maputnik.

How often is the underlying OpenStreetMap data updated?

The Protomaps project provides public builds updated on a regular schedule. If you host your own pipeline, you can use Planetiler or Tilemaker alongside an OSM diff updater to rebuild your regional .pmtiles archives daily or weekly via automated GitHub Actions or cron jobs.

Do I need to run a serverless proxy like Cloudflare Workers?

Not necessarily. If your object storage bucket supports native HTTP range requests, correct CORS headers, and public access, you can read the .pmtiles file directly in the browser via pmtiles.Protocol. However, placing a lightweight edge function (like the official Protomaps Edge Worker) in front of the bucket allows you to serve standard Z/X/Y endpoints to legacy GIS clients that do not support PMTiles natively.