Decoupling Web GIS: Architecting Serverless Vector Map Pipelines with PMTiles and HTTP Range Requests
Traditional web mapping stacks require brittle tile servers, complex caching layers, and high operational costs. Learn how the PMTiles format leverages single-file spatial archives and HTTP Range Requests to deliver serverless, ultra-low-latency vector maps directly from object storage.
The Crippling Overhead of Legacy Tile Server Architectures
For over a decade, deploying scalable, custom web maps has forced engineering teams into an architectural compromise. The classic slippy map architecture relies on a deterministic grid system: a planetary dataset is divided into square tiles organized across zoom levels ($z$) and cartesian coordinates ($x, y$). Traditionally, serving these tiles—whether as raster PNGs or Mapbox Vector Tiles (MVT/PBF format)—demanded one of two burdensome infrastructure patterns:
- The Million-File Object Storage Anti-Pattern: Generating static tiles upfront and syncing them to cloud storage (e.g., AWS S3). A zoom-level 0 to 14 planetary extract yields over 350 million distinct
.pbffiles. File system metadata operations grind to a halt, uploading takes days due to S3 API rate limits (PUTtransactions), and storage costs balloon from raw object overhead and listing overhead. - The Stateful Tile Server Anti-Pattern: Hosting dynamic tile servers such as Tegola, Martin, or TileServer GL backed by PostGIS or SQLite-based
.mbtilesarchives. While this avoids millions of loose files, it introduces stateful compute clusters. Spikes in traffic require horizontal autoscaling, complex database connection pooling, persistent disk attachment (EBS/Ceph) for SQLite reads, and persistent memory pressure under concurrent rasterization or vector serialization.
For engineering teams building data-dense geospatial visualizations, internal operational dashboards, or privacy-conscious applications, both paradigms introduce unnecessary friction, egress bandwidth costs, and single points of failure. The modern solution lies in eliminating the middleman server entirely by redesigning the container format around web standards.
Anatomy of PMTiles: Single-Archive Spatial Data Structures
Created by Brandon Liu as part of the open-source Protomaps ecosystem, PMTiles is an open specification for pyramid vector and raster tile archives stored in a single file. Rather than relying on a relational database or a directory tree, PMTiles relies on clever spatial indexing, deterministic compression, and strict byte alignment.
Spatial Indexing via the Hilbert Curve
To store millions of tile payloads sequentially within a single binary blob while maintaining fast lookup times, PMTiles maps two-dimensional tile coordinates $(x, y)$ at each zoom level $(z)$ to a one-dimensional integer sequence using a Hilbert space-filling curve.
The Hilbert curve preserves spatial locality far better than naive Z-order (Morton) indexing or row-major raster scans. Adjacent tiles on a display surface are clustered closely together within the physical byte layout of the PMTiles archive. This property is crucial for minimizing disk seek times and maximizing read-ahead efficiency over network streams.
Clustered and Sparse Directories
A PMTiles v3 archive is segmented into deterministic sections:
- Header (127 bytes): Fixed-length metadata containing the magic bytes
PMTiles, version indicators, byte offsets, lengths for directories, tile data bounds, minimum/maximum zoom levels, and compression algorithms (Gzip, Zstandard, or Brotli). - Root Directory: A compact binary table mapping Hilbert-indexed tile ID ranges to absolute byte offsets and lengths within the tile data section.
- Leaf Directories: For global planetary datasets with hundreds of millions of tiles, nesting a monolithic directory into the header is impossible. PMTiles uses a two-level tree: the root directory points to intermediate leaf directories, which resolve individual tile offsets on demand.
- Tile Data: The raw binary payloads (MVT protobufs, WebP, or AVIF), deduplicated and tightly packed.
Because identical water or landcover tiles can repeat thousands of times across the globe, PMTiles deduplicates payloads automatically: multiple directory entries can point to the exact same byte offset and run length, drastically cutting total storage footprints.
Exploiting HTTP Range Requests (RFC 7233) for Spatial Lookups
The fundamental innovation enabling PMTiles to run without an application server is RFC 7233 HTTP Range Requests. Standard cloud object storage—such as Amazon S3, Google Cloud Storage, Cloudflare R2, or MinIO—natively supports fetching arbitrary byte slices using the Range: bytes=start-end request header.
When a client-side map renderer (such as MapLibre GL JS) requests a tile at coordinate z/x/y:
- Hilbert Coordinate Conversion: The client library converts
(z, x, y)into an integer Tile ID. - Root Directory Lookup: The client checks its in-memory cache for the root directory. If uncached, it issues an HTTP Range request for the first few kilobytes of the
.pmtilesarchive to parse the header and root table. - Leaf Directory Resolution (If Necessary): If the target Tile ID resides within a leaf directory, the client issues a secondary Range request targeting that specific leaf slice (typically 1 to 4 KB).
- Tile Extraction: With the absolute byte offset and length resolved, the client requests the exact byte slice containing the vector tile payload.
- Client-Side Protobuf Parsing: The client decodes the compressed MVT payload in a Web Worker and passes the geometry directly to WebGL/WebGPU render passes.
Under warm cache conditions, resolving any tile on Earth requires exactly one single HTTP request directly to cloud storage, bypassing API gateways, application runtimes, and databases completely.
+-------------------------------------------------------------------------+
| Client (MapLibre GL JS + pmtiles.js) |
+-------------------------------------------------------------------------+
| |
| 1. Range: bytes=0-16383 | 2. Range: bytes=842390-854720
| (Header & Root Directory) | (Specific Tile Payload)
v v
+-------------------------------------------------------------------------+
| Edge CDN / Object Storage (Cloudflare R2 / AWS S3) |
| |
| [Header] [Root Dir] [Leaf Dirs...] [--------- Tile Data Stream --------]|
+-------------------------------------------------------------------------+
Building the Pipeline: From Planet PBF to Global Edge CDN
To build a completely self-hosted, self-managed vector map pipeline, you can process raw OpenStreetMap (OSM) data and publish it to zero-egress object storage in an afternoon.
Step 1: Tile Extraction with Planetiler
Generating vector tiles from planet-wide OSM data historically required days of compute using tools like Tilemaker or Mapnik. Planetiler, a Java-based tile engine, rewrites this process using memory-mapped I/O and low-level primitive parallelism, compiling the entire planet into an archive in under an hour on commodity multi-core hardware.
Execute Planetiler using the Protomaps profile directly from Docker:
docker run -e JAVA_TOOL_OPTIONS="-Xmx28g" \
-v "$(pwd)/data":/data \
ghcr.io/onthegomap/planetiler:latest \
--osm-path=/data/planet-latest.osm.pbf \
--output=/data/planet.pmtiles \
--profile=protomaps
This single pass yields a self-contained planet.pmtiles file (approx. 80GB to 110GB depending on feature filtering and maximum zoom).
Step 2: Zero-Egress Cloud Storage Deployment
Upload the generated archive to an S3-compatible bucket. Deploying to Cloudflare R2 is ideal because R2 does not charge egress bandwidth fees for public reads—a critical cost consideration when streaming millions of spatial chunks globally:
# Uploading using the AWS CLI configured with Cloudflare R2 endpoints
aws s3 cp data/planet.pmtiles s3://vector-maps-archive/planet.pmtiles \
--endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com \
--content-type "application/vnd.pmtiles"
Ensure your bucket is exposed publicly or routed behind a CDN zone with appropriate CORS configurations:
[
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET", "HEAD"],
"AllowedHeaders": ["Range", "If-Match", "If-Unmodified-Since"],
"ExposeHeaders": ["Content-Range", "Content-Length", "ETag"],
"MaxAgeSeconds": 86400
}
]
Client-Side Integration with MapLibre GL JS
Consuming PMTiles in modern web frontends is trivial using the pmtiles JavaScript protocol extension for MapLibre GL JS.
import maplibregl from 'maplibre-gl';
import * as pmtiles from 'pmtiles';
import 'maplibre-gl/dist/maplibre-gl.css';
// 1. Instantiate the PMTiles Protocol Cache
const protocol = new pmtiles.Protocol();
maplibregl.addProtocol('pmtiles', protocol.tile);
// 2. Define the remote PMTiles archive URL
const PMTILES_URL = 'https://maps.yourdomain.com/planet.pmtiles';
// 3. Initialize the Map Instance
const map = new maplibregl.Map({
container: 'map',
style: {
version: 8,
glyphs: 'https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf',
sources: {
'protomaps-source': {
type: 'vector',
url: `pmtiles://${PMTILES_URL}`,
attribution: '© <a href="https://openstreetmap.org">OpenStreetMap</a>'
}
},
layers: [
{
id: 'water',
type: 'fill',
source: 'protomaps-source',
'source-layer': 'water',
paint: {
'fill-color': '#a0cfdf'
}
},
{
id: 'roads-base',
type: 'line',
source: 'protomaps-source',
'source-layer': 'roads',
paint: {
'line-color': '#cfcfcf',
'line-width': 1.5
}
}
]
},
center: [-74.006, 40.7128],
zoom: 12
});
Behind the scenes, pmtiles.Protocol intercepts tile requests formulated as pmtiles://https://.../{z}/{x}/{y}.mvt, calculates the offset via the local directory cache, issues the HTTP Range request via fetch(), and returns the raw array buffer directly to MapLibre's rendering worker pipeline.
Benchmarking Architecture: PMTiles vs. TileServer GL on Kubernetes
To evaluate the real-world operational difference between a containerized tile server stack and a serverless PMTiles architecture, consider the following metrics observed across a high-traffic production application handling 10,000,000 tile requests per day:
| Operational Dimension | TileServer GL (EKS / EC2) | PMTiles on Cloudflare R2 | Delta |
| :--- | :--- | :--- | :--- |
| Monthly Compute Cost | ~$480 (3x c6i.xlarge nodes) | $0.00 (No servers) | -100% |
| Bandwidth/Egress Cost | ~$450 (AWS Data Transfer Out) | $0.00 (R2 Zero-Egress) | -100% |
| Storage Cost (100GB) | $10.00 (EBS gp3) | $1.50 (Standard Storage) | -85% |
| P95 Latency (Cached) | 42 ms | 18 ms (Edge Cloudflare CDN) | -57% |
| P95 Latency (Uncached) | 180 ms | 65 ms (Direct S3 Range) | -63% |
| Maintenance Overhead | Kernel upgrades, scaling rules, OOM crash handling | None (Static file asset) | Near Zero |
By leveraging byte-range requests, compute is pushed entirely to the client device, while edge distribution is handled by commodity CDN infrastructure designed specifically for streaming file segments.
Moving Beyond Hosted Mapping Lock-In
Adopting serverless spatial data architectures eliminates proprietary map platform vendor lock-in. Traditional commercial mapping providers monetize by charging per-map-load or per-tile-request. This pricing model penalizes user engagement: applications with high session lengths or data-dense geospatial tracking face exponentially growing bills.
By packaging spatial data into PMTiles archives and distributing them over open web protocols, development teams regain complete architectural sovereignty over their geospatial stack. Whether deploying offline-first applications on Android and iOS using embedded HTTP engines, conducting client-side spatial joins via DuckDB-WASM directly against remote archives, or simply rendering global maps for pennies a month, the combination of modern spatial index design and HTTP byte-range routing shifts web GIS from complex distributed computing to static file delivery.